Class: Fog::OpenStack::Auth::Token::V2
Instance Attribute Summary collapse
#catalog, #data, #expires, #token, #user
Instance Method Summary
collapse
build, #get, #initialize
Instance Attribute Details
#tenant ⇒ Object
Returns the value of attribute tenant.
12
13
14
|
# File 'lib/fog/openstack/auth/token/v2.rb', line 12
def tenant
@tenant
end
|
Instance Method Details
#build_credentials(auth) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/fog/openstack/auth/token/v2.rb', line 61
def build_credentials(auth)
if auth[:openstack_auth_token]
@token = auth[:openstack_auth_token]
else
@user = Fog::OpenStack::Auth::User.new(auth[:openstack_userid], auth[:openstack_username])
@user.password = auth[:openstack_api_key]
end
@tenant = Fog::OpenStack::Auth::Name.new(auth[:openstack_tenant_id], auth[:openstack_tenant])
credentials
end
|
#credentials ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/fog/openstack/auth/token/v2.rb', line 14
def credentials
if @token
identity = {'token' => {'id' => @token}}
else
raise CredentialsError, "#{self.class}: User name is required" if @user.name.nil?
raise CredentialsError, "#{self.class}: User password is required" if @user.password.nil?
identity = {'passwordCredentials' => user_credentials}
end
if @tenant.id
identity['tenantId'] = @tenant.id.to_s
elsif @tenant.name
identity['tenantName'] = @tenant.name.to_s
end
{'auth' => identity}
end
|
#path ⇒ Object
40
41
42
|
# File 'lib/fog/openstack/auth/token/v2.rb', line 40
def path
'/tokens'
end
|
#prefix_path(uri) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/fog/openstack/auth/token/v2.rb', line 32
def prefix_path(uri)
if uri.path =~ /\/v2(\.0)*(\/)*.*$/
''
else
'/v2.0'
end
end
|
#set(response) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/fog/openstack/auth/token/v2.rb', line 51
def set(response)
@data = Fog::JSON.decode(response.body)
@token = @data['access']['token']['id']
@expires = @data['access']['token']['expires']
@tenant = @data['access']['token']['tenant']
@user = @data['access']['user']
catalog = @data['access']['serviceCatalog']
@catalog = Fog::OpenStack::Auth::Catalog::V2.new(catalog) if catalog
end
|
#user_credentials ⇒ Object
44
45
46
47
48
49
|
# File 'lib/fog/openstack/auth/token/v2.rb', line 44
def user_credentials
{
'username' => @user.name.to_s,
'password' => @user.password
}
end
|