Class: Miasma::Contrib::OpenStackApiCore::Authenticate::Version3
- Inherits:
-
Miasma::Contrib::OpenStackApiCore::Authenticate
- Object
- Miasma::Contrib::OpenStackApiCore::Authenticate
- Miasma::Contrib::OpenStackApiCore::Authenticate::Version3
- Defined in:
- lib/miasma/contrib/open_stack.rb
Overview
Authentication implementation compatible for v2
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.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/miasma/contrib/open_stack.rb', line 123 def authentication_request ident = Smash.new(:methods => []) if(credentials[:open_stack_password]) ident[:methods] << 'password' ident[:password] = Smash.new( :user => Smash.new( :password => credentials[:open_stack_password] ) ) if(credentials[:open_stack_user_id]) ident[:password][:user][:id] = credentials[:open_stack_user_id] else ident[:password][:user][:name] = credentials[:open_stack_username] end if(credentials[:open_stack_domain]) ident[:password][:user][:domain] = Smash.new( :name => credentials[:open_stack_domain] ) end end if(credentials[:open_stack_token]) ident[:methods] << 'token' ident[:token] = Smash.new( :token => Smash.new( :id => credentials[:open_stack_token] ) ) end if(credentials[:open_stack_project_id]) scope = Smash.new( :project => Smash.new( :id => credentials[:open_stack_project_id] ) ) else if(credentials[:open_stack_domain]) scope = Smash.new( :domain => Smash.new( :name => credentials[:open_stack_domain] ) ) if(credentials[:open_stack_project]) scope[:project] = Smash.new( :name => credentials[:open_stack_project] ) end end end auth = Smash.new(:identity => ident) if(scope) auth[:scope] = scope end auth end |
#identify_and_load ⇒ TrueClass
Identify with authentication service and load token information and service catalog
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/miasma/contrib/open_stack.rb', line 182 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!', result) end info = MultiJson.load(result.body.to_s).to_smash[:token] @service_catalog = info.delete(:catalog) @token = Smash.new( :expires => Time.parse(info[:expires_at]), :id => result.headers['X-Subject-Token'] ) @user = info[:user][:name] true end |