Class: Keystone::V2_0::TokenManager

Inherits:
Openstack::Client::Manager show all
Defined in:
lib/keystone/v2_0/tokens.rb

Constant Summary collapse

RESOURCE_CLASS =
Keystone::V2_0::Token

Instance Attribute Summary

Attributes inherited from Openstack::Client::Manager

#api, #resource_class

Instance Method Summary collapse

Methods inherited from Openstack::Client::Manager

#_create, #_delete, #_get, #_list, #_update, #get_id, #url_with_params

Constructor Details

#initialize(api) ⇒ TokenManager

Returns a new instance of TokenManager.



17
18
19
# File 'lib/keystone/v2_0/tokens.rb', line 17

def initialize api
  super
end

Instance Method Details

#authenticate(options) ⇒ Object

Parameters:

  • options (Hash)

Options Hash (options):

  • :username (String)
  • :tenant_id (String)
  • :tenant_name (String)
  • :password (String)
  • :token (String)
  • :return_raw (String)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/keystone/v2_0/tokens.rb', line 28

def authenticate options
  if options[:token]
    params = { 'auth' => { 'token' => { 'id' => options[:token] } } }
  elsif options[:username] and options[:password]
    params = { 
      'auth' => { 
        'passwordCredentials' => {
          'username' => options[:username],
          'password' => options[:password]
    }}}
  else
    raise 'A username and password or token is required.'
  end

  if options[:tenant_id]
    params['auth']['tenantId'] = options[:tenant_id]
  elsif options[:tenant_name]
    params['auth']['tenantName'] = options[:tenant_name]
  end

  return self._create('/tokens', params, 'access', options[:return_raw])
end

#delete(token) ⇒ Object



51
52
53
# File 'lib/keystone/v2_0/tokens.rb', line 51

def delete token
  self._delete("/tokens/#{token.id}")
end

#endpoints(token) ⇒ Object



55
56
57
# File 'lib/keystone/v2_0/tokens.rb', line 55

def endpoints token
  self._get("/tokens/#{token.id}/endpoints", 'token')
end