class Ros::TenantMiddleware
Attributes
access_key_id[RW]
auth_string[RW]
auth_type[RW]
token[RW]
Public Instance Methods
credential()
click to toggle source
# File lib/ros/tenant_middleware.rb, line 27 def credential # TODO: Credential.authorization must be an instance variable Ros::Sdk::Credential.authorization = 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)
click to toggle source
Returns the schema_name for Apartment to switch to for this request
# 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()
click to toggle source
# 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()
click to toggle source
# 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
urn()
click to toggle source
# File lib/ros/tenant_middleware.rb, line 41 def urn; Urn.from_jwt(token) end