class Miasma::Contrib::OpenStackApiCore::Authenticate::Version3
Authentication implementation compatible for v2
Public Instance Methods
authentication_request()
click to toggle source
@return [Smash] authentication request body
# 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()
click to toggle source
Identify with authentication service and load token information and service catalog
@return [TrueClass]
# 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