class Miasma::Contrib::OpenStackApiCore::Authenticate::Version2

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 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() 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 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