verikloak-bff 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91439a22efdb87206de07fbff74c284cba33a05cb1c7392070c0b9f7c837734f
4
- data.tar.gz: be08bb99047e72502cad67dbea7c41b916aef6d49fb103e3dbf53ab79082f6db
3
+ metadata.gz: 255d2d606e30f92f8c562d91d975be06975a7ba373bd607aa5057e5abcc279a6
4
+ data.tar.gz: 6f81b6407f5a1a6e5d307cb65981f48e12c5356ec411ba05d21829681bedb084
5
5
  SHA512:
6
- metadata.gz: 135054bc3b1556597924c843a834d87c46c291da4d880ed63ef611cafb9705984694062f64d25a08f8d3f932f304cfb7277c4d25f25dfb3f35ad3d83f0768e47
7
- data.tar.gz: 3358b1f9f3114e9a00a7d4edd283e5b2c81dd6166ec1a5718a581f5f83a7c1cf75d27f300da01d5dc25763f4569a50be2393203130c5a67adb00ffb1a42fc1d9
6
+ metadata.gz: 995250cf2096de074988c0a00d4c2de0ff4b03c798089acfd0f0e0e5e3c0cdc3717da82f4f85be74db68fe40ced3cda5c27ae9f14ae41385a38a24e2eb9c4814
7
+ data.tar.gz: 157ddfbc41d48b9903b59f732ef8128a4d27127fee098d4a6e2388ca713ce15a749acad287b4995f87515d70233f74d4f44f7ac9d289de34d548d26bef3e9d17
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ---
9
9
 
10
+ ## [0.2.1] - 2025-09-23
11
+
12
+ ### Fixed
13
+ - Skip inserting `Verikloak::BFF::HeaderGuard` in Rails when `Verikloak::Middleware` is absent (e.g., discovery not configured)
14
+ so that generators and boot sequences no longer fail.
15
+
10
16
  ## [0.2.0] - 2025-09-22
11
17
 
12
18
  ### Added
data/README.md CHANGED
@@ -23,8 +23,22 @@ bundle add verikloak-bff
23
23
 
24
24
  ## Usage
25
25
 
26
- - Rack-only apps: `use Verikloak::BFF::HeaderGuard` before your core Verikloak middleware.
27
- - Rails apps: see the full guide in [docs/rails.md](docs/rails.md) (Gemfile, middleware order、initializer、proxy examples)。
26
+ ### Rack Applications
27
+ Add to your `config.ru`:
28
+ ```ruby
29
+ use Verikloak::BFF::HeaderGuard, trusted_proxies: ['127.0.0.1', '10.0.0.0/8']
30
+ # Place before your core Verikloak middleware
31
+ ```
32
+
33
+ ### Rails Applications
34
+ Simply add to your Gemfile and the middleware will be automatically integrated:
35
+ ```ruby
36
+ gem 'verikloak-bff'
37
+ ```
38
+
39
+ The gem automatically inserts `Verikloak::BFF::HeaderGuard` into the Rails middleware stack after the core `Verikloak::Middleware`. If the core middleware is not present (e.g., discovery not configured), it gracefully skips insertion with a warning, allowing Rails to boot normally.
40
+
41
+ For detailed configuration, proxy setup examples, and troubleshooting, see [docs/rails.md](docs/rails.md).
28
42
 
29
43
  ## Consistency mapping
30
44
 
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Verikloak
4
+ module BFF
5
+ # Rails-specific functionality for Verikloak BFF
6
+ module Rails
7
+ # Middleware management utilities for Rails applications
8
+ #
9
+ # This module provides functionality to insert Verikloak BFF middleware
10
+ # into Rails middleware stack, with proper error handling for cases where
11
+ # the core Verikloak middleware is not present.
12
+ module Middleware
13
+ module_function
14
+
15
+ # Inserts Verikloak::BFF::HeaderGuard middleware after Verikloak::Middleware
16
+ #
17
+ # Attempts to insert the HeaderGuard middleware into the Rails middleware stack
18
+ # after the core Verikloak::Middleware. If the core middleware is not present,
19
+ # logs a warning and gracefully skips the insertion.
20
+ #
21
+ # @param stack [ActionDispatch::MiddlewareStack] Rails middleware stack
22
+ # @param logger [Logger, nil] Optional logger for warning messages
23
+ # @return [Boolean] true if insertion succeeded, false if skipped due to missing core
24
+ # @raise [RuntimeError] Re-raises non-middleware-related runtime errors
25
+ #
26
+ # @example Inserting middleware in Rails configuration
27
+ # Verikloak::BFF::Rails::Middleware.insert_after_core(
28
+ # Rails.application.config.middleware,
29
+ # logger: Rails.logger
30
+ # )
31
+ def insert_after_core(stack, logger: nil)
32
+ stack.insert_after(::Verikloak::Middleware, ::Verikloak::BFF::HeaderGuard)
33
+ true
34
+ rescue RuntimeError => e
35
+ raise unless missing_core?(e)
36
+
37
+ log_skip(logger)
38
+ false
39
+ end
40
+
41
+ # Checks if the error indicates missing core Verikloak middleware
42
+ #
43
+ # Examines a RuntimeError to determine if it was caused by attempting
44
+ # to insert middleware after a non-existent Verikloak::Middleware.
45
+ #
46
+ # @param error [RuntimeError] The error to examine
47
+ # @return [Boolean] true if error indicates missing Verikloak::Middleware
48
+ #
49
+ # @example Checking for missing middleware error
50
+ # begin
51
+ # stack.insert_after(::Verikloak::Middleware, SomeMiddleware)
52
+ # rescue RuntimeError => e
53
+ # puts "Missing core!" if missing_core?(e)
54
+ # end
55
+ def missing_core?(error)
56
+ error.message.include?('No such middleware') &&
57
+ error.message.include?('Verikloak::Middleware')
58
+ end
59
+
60
+ # Logs a warning message about skipping middleware insertion
61
+ #
62
+ # Outputs a descriptive warning message explaining why the HeaderGuard
63
+ # middleware insertion was skipped and provides guidance for resolution.
64
+ # Uses the provided logger if available, otherwise falls back to warn().
65
+ #
66
+ # @param logger [Logger, nil] Optional logger instance for structured logging
67
+ #
68
+ # @example Logging with Rails logger
69
+ # log_skip(Rails.logger)
70
+ #
71
+ # @example Logging without logger (uses warn)
72
+ # log_skip(nil)
73
+ def log_skip(logger)
74
+ message = <<~MSG.chomp
75
+ [verikloak-bff] Skipping Verikloak::BFF::HeaderGuard insertion because Verikloak::Middleware is not present. Configure verikloak-rails discovery settings and restart once core verification is enabled.
76
+ MSG
77
+
78
+ if logger
79
+ logger.warn(message)
80
+ else
81
+ warn(message)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'rails'
4
+
5
+ module Verikloak
6
+ # Module providing Verikloak BFF (Backend for Frontend) functionality
7
+ module BFF
8
+ # Railtie class for integrating Verikloak BFF middleware into Rails applications
9
+ #
10
+ # This class automatically inserts Verikloak::BFF::Rails::Middleware into the
11
+ # Rails initialization process. The middleware is inserted after the
12
+ # 'verikloak.middleware' initializer and configured with an appropriate logger.
13
+ #
14
+ # @example Automatic initialization in Rails applications
15
+ # # Simply adding verikloak-bff to Gemfile automatically enables it
16
+ # gem 'verikloak-bff'
17
+ #
18
+ # @see Verikloak::BFF::Rails::Middleware
19
+ class Railtie < ::Rails::Railtie
20
+ # Initializer that inserts Verikloak BFF middleware into Rails application
21
+ #
22
+ # This initializer runs after 'verikloak.middleware' and inserts
23
+ # Verikloak::BFF::Rails::Middleware at the appropriate position.
24
+ # Uses Rails.logger as the logger if available.
25
+ #
26
+ # @param app [Rails::Application] Rails application instance
27
+ initializer 'verikloak.bff.insert_middleware', after: 'verikloak.middleware' do |app|
28
+ logger = ::Rails.logger if defined?(::Rails.logger)
29
+
30
+ Verikloak::BFF::Rails::Middleware.insert_after_core(app.config.middleware, logger: logger)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -5,6 +5,6 @@
5
5
  # @return [String]
6
6
  module Verikloak
7
7
  module BFF
8
- VERSION = '0.2.0'
8
+ VERSION = '0.2.1'
9
9
  end
10
10
  end
data/lib/verikloak-bff.rb CHANGED
@@ -18,3 +18,6 @@ require 'verikloak/bff/proxy_trust'
18
18
  require 'verikloak/bff/forwarded_token'
19
19
  require 'verikloak/bff/consistency_checks'
20
20
  require 'verikloak/bff/header_guard'
21
+ require 'verikloak/bff/rails'
22
+
23
+ require 'verikloak/bff/railtie' if defined?(Rails::Railtie)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verikloak-bff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - taiyaky
@@ -55,7 +55,7 @@ dependencies:
55
55
  requirements:
56
56
  - - ">="
57
57
  - !ruby/object:Gem::Version
58
- version: 0.1.5
58
+ version: 0.2.0
59
59
  - - "<"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.0.0
@@ -65,7 +65,7 @@ dependencies:
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.5
68
+ version: 0.2.0
69
69
  - - "<"
70
70
  - !ruby/object:Gem::Version
71
71
  version: 1.0.0
@@ -87,6 +87,8 @@ files:
87
87
  - lib/verikloak/bff/forwarded_token.rb
88
88
  - lib/verikloak/bff/header_guard.rb
89
89
  - lib/verikloak/bff/proxy_trust.rb
90
+ - lib/verikloak/bff/rails.rb
91
+ - lib/verikloak/bff/railtie.rb
90
92
  - lib/verikloak/bff/version.rb
91
93
  - lib/verikloak/header_sources.rb
92
94
  homepage: https://github.com/taiyaky/verikloak-bff
@@ -96,7 +98,7 @@ metadata:
96
98
  source_code_uri: https://github.com/taiyaky/verikloak-bff
97
99
  changelog_uri: https://github.com/taiyaky/verikloak-bff/blob/main/CHANGELOG.md
98
100
  bug_tracker_uri: https://github.com/taiyaky/verikloak-bff/issues
99
- documentation_uri: https://rubydoc.info/gems/verikloak-bff/0.2.0
101
+ documentation_uri: https://rubydoc.info/gems/verikloak-bff/0.2.1
100
102
  rubygems_mfa_required: 'true'
101
103
  rdoc_options: []
102
104
  require_paths: