Class: Misty::AuthV2
- Inherits:
-
Auth
- Object
- Auth
- Misty::AuthV2
show all
- Defined in:
- lib/misty/auth/auth_v2.rb
Instance Attribute Summary
Attributes inherited from Auth
#catalog, #token
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Auth
#authenticate, #expired?, factory, #find_url, #get_service, #get_token, #get_url, #initialize
http_request
Constructor Details
This class inherits a constructor from Misty::Auth
Class Method Details
.get_url(endpoint, region_id, interface) ⇒ Object
9
10
11
|
# File 'lib/misty/auth/auth_v2.rb', line 9
def self.get_url(endpoint, region_id, interface)
return endpoint["#{interface}URL"] if endpoint['region'] == region_id && endpoint["#{interface}URL"]
end
|
.path ⇒ Object
5
6
7
|
# File 'lib/misty/auth/auth_v2.rb', line 5
def self.path
'/v2.0/tokens'
end
|
Instance Method Details
#credentials ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/misty/auth/auth_v2.rb', line 13
def credentials
if @token
identity = { 'token': { 'id': @token } }
else
raise Misty::Auth::CredentialsError, "#{self.class}: User name is required" if @user.name.nil?
raise Misty::Auth::CredentialsError, "#{self.class}: User password is required" if @user.password.nil?
identity = { 'passwordCredentials': user_credentials }
end
if @tenant.id
identity.merge!('tenantId': @tenant.id)
elsif @tenant.name
identity.merge!('tenantName': @tenant.name)
else
raise Misty::Auth::CredentialsError, "#{self.class}: No tenant available"
end
{ 'auth': identity }
end
|
#set(response) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/misty/auth/auth_v2.rb', line 40
def set(response)
payload = JSON.load(response.body)
token = payload['access']['token']['id']
catalog = payload['access']['serviceCatalog']
expires = payload['access']['token']['expires']
[token, catalog, expires]
end
|
#set_credentials(auth) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/misty/auth/auth_v2.rb', line 48
def set_credentials(auth)
if auth[:token]
@token = auth[:token]
else
@user = Misty::Auth::User.new(auth[:user_id], auth[:user])
@user.password = auth[:password]
end
@tenant = Misty::Auth::Name.new(auth[:tenant_id], auth[:tenant])
credentials
end
|
#user_credentials ⇒ Object
33
34
35
36
37
38
|
# File 'lib/misty/auth/auth_v2.rb', line 33
def user_credentials
{
'username': @user.name,
'password': @user.password
}
end
|