Class: Ros::TenantMiddleware
- Inherits:
-
Apartment::Elevators::Generic
- Object
- Apartment::Elevators::Generic
- Ros::TenantMiddleware
- Defined in:
- lib/ros/tenant_middleware.rb
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#auth_string ⇒ Object
Returns the value of attribute auth_string.
-
#auth_type ⇒ Object
Returns the value of attribute auth_type.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #credential ⇒ Object
-
#parse_tenant_name(request) ⇒ Object
Returns the schema_name for Apartment to switch to for this request.
- #tenant_name_from_basic ⇒ Object
- #tenant_name_from_bearer ⇒ Object
- #urn ⇒ Object
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
7 8 9 |
# File 'lib/ros/tenant_middleware.rb', line 7 def access_key_id @access_key_id end |
#auth_string ⇒ Object
Returns the value of attribute auth_string.
7 8 9 |
# File 'lib/ros/tenant_middleware.rb', line 7 def auth_string @auth_string end |
#auth_type ⇒ Object
Returns the value of attribute auth_type.
7 8 9 |
# File 'lib/ros/tenant_middleware.rb', line 7 def auth_type @auth_type end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/ros/tenant_middleware.rb', line 7 def token @token end |
Instance Method Details
#credential ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/ros/tenant_middleware.rb', line 27 def credential # TODO: Credential.authorization must be an instance variable Ros::Sdk::Credential. = auth_string Ros::IAM::Credential.where(access_key_id: access_key_id).first # rescue JsonApiClient::Errors::ServerError => e # NOTE: Swallow the auth error and return nil which causes tenant to be 'public' rescue JsonApiClient::Errors::NotAuthorized => e end |
#parse_tenant_name(request) ⇒ Object
Returns the schema_name for Apartment to switch to for this request
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ros/tenant_middleware.rb', line 10 def parse_tenant_name(request) @auth_string = request.env['HTTP_AUTHORIZATION'] return 'public' unless auth_string.present? @auth_type, @token = auth_string.split(' ') @auth_type.downcase! Rails.logger.info("Invalid auth type #{auth_type}") and return 'public' unless auth_type.in? %w(basic bearer) Rails.logger.info('Invalid token') and return 'public' if token.nil? schema_name = send("tenant_name_from_#{auth_type}") Rails.logger.info('Invalid credentials') if schema_name.eql?('public') schema_name end |
#tenant_name_from_basic ⇒ Object
22 23 24 25 |
# File 'lib/ros/tenant_middleware.rb', line 22 def tenant_name_from_basic return 'public' unless @access_key_id = token.split(':').first credential.try(:schema_name) || 'public' end |
#tenant_name_from_bearer ⇒ Object
36 37 38 39 |
# File 'lib/ros/tenant_middleware.rb', line 36 def tenant_name_from_bearer return 'public' unless account_id = urn.try(:account_id) Tenant.account_id_to_schema(account_id) end |