Class: Miasma::Contrib::OpenStackApiCore::Authenticate::Version2
- Inherits:
-
Miasma::Contrib::OpenStackApiCore::Authenticate
- Object
- Miasma::Contrib::OpenStackApiCore::Authenticate
- Miasma::Contrib::OpenStackApiCore::Authenticate::Version2
- Defined in:
- lib/miasma/contrib/open_stack.rb
Overview
Authentication implementation compatible for v2
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Miasma::Contrib::OpenStackApiCore::Authenticate
Instance Method Summary collapse
-
#authentication_request ⇒ Smash
Authentication request body.
-
#identify_and_load ⇒ TrueClass
Identify with authentication service and load token information and service catalog.
Methods inherited from Miasma::Contrib::OpenStackApiCore::Authenticate
#api_token, #identity_and_load, #initialize, #service_catalog, #user
Constructor Details
This class inherits a constructor from Miasma::Contrib::OpenStackApiCore::Authenticate
Instance Method Details
#authentication_request ⇒ Smash
Returns authentication request body.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/miasma/contrib/open_stack.rb', line 70 def authentication_request if(credentials[:open_stack_token]) auth = Smash.new( :token => Smash.new( :id => credentials[:open_stack_token] ) ) else auth = Smash.new( 'passwordCredentials' => Smash.new( 'username' => credentials[:open_stack_username], 'password' => credentials[:open_stack_password] ) ) end if(credentials[:open_stack_tenant_name]) auth['tenantName'] = credentials[:open_stack_tenant_name] end auth end |
#identify_and_load ⇒ TrueClass
Identify with authentication service and load token information and service catalog
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/miasma/contrib/open_stack.rb', line 95 def identify_and_load result = HTTP.post( File.join( credentials[:open_stack_identity_url], 'tokens' ), :json => Smash.new( :auth => authentication_request ) ) unless(result.status == 200) raise Error::ApiError::AuthenticationError.new('Failed to authenticate', :response => result) end info = MultiJson.load(result.body.to_s).to_smash info = info[:access] @user = info[:user] @service_catalog = info[:serviceCatalog] @token = info[:token] token[:expires] = Time.parse(token[:expires]) true end |