Class: Stitches::CallingServiceMiddleware
- Inherits:
-
Object
- Object
- Stitches::CallingServiceMiddleware
- Defined in:
- lib/stitches/calling_service_middleware.rb
Overview
Rack middleware that populates the caller identity env var from the calling service header when no other auth middleware has already set it. This allows existing code that reads the caller identity object to work transparently after API keys are disabled.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ CallingServiceMiddleware
constructor
A new instance of CallingServiceMiddleware.
Constructor Details
#initialize(app) ⇒ CallingServiceMiddleware
Returns a new instance of CallingServiceMiddleware.
9 10 11 |
# File 'lib/stitches/calling_service_middleware.rb', line 9 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/stitches/calling_service_middleware.rb', line 13 def call(env) client_key = Stitches.configuration.env_var_to_hold_api_client unless env[client_key] header_name = Stitches.configuration.calling_service_header rack_key = "HTTP_#{header_name.upcase.tr('-', '_')}" if (name = env[rack_key]).present? env[client_key] = CallingServiceClient.new(name) end end @app.call(env) end |