Class: Legion::API::Middleware::Tenant
- Inherits:
-
Object
- Object
- Legion::API::Middleware::Tenant
- Defined in:
- lib/legion/api/middleware/tenant.rb
Constant Summary collapse
- SKIP_PATHS =
%w[/api/health /api/ready /api/openapi.json /metrics].freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ Tenant
constructor
A new instance of Tenant.
Constructor Details
#initialize(app, opts = {}) ⇒ Tenant
Returns a new instance of Tenant.
9 10 11 12 |
# File 'lib/legion/api/middleware/tenant.rb', line 9 def initialize(app, opts = {}) @app = app @opts = opts end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/api/middleware/tenant.rb', line 14 def call(env) return @app.call(env) if skip_path?(env['PATH_INFO']) tenant_id = extract_tenant(env) if tenant_id Legion::Logging.debug "API tenant: resolved tenant_id=#{tenant_id} for #{env['REQUEST_METHOD']} #{env['PATH_INFO']}" if defined?(Legion::Logging) Legion::TenantContext.set(tenant_id) end @app.call(env) ensure Legion::TenantContext.clear end |