Class: Misty::AuthV3
- Inherits:
-
Auth
- Object
- Auth
- Misty::AuthV3
show all
- Defined in:
- lib/misty/auth/auth_v3.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_v3.rb', line 9
def self.get_url(endpoint, region_id, interface)
return endpoint['url'] if endpoint['region_id'] == region_id && endpoint['interface'] == interface
end
|
.path ⇒ Object
5
6
7
|
# File 'lib/misty/auth/auth_v3.rb', line 5
def self.path
'/v3/auth/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_v3.rb', line 13
def credentials
if @token
identity = {
'methods': ['token'],
'token': { 'id': @token }
}
else
identity = {
'methods': ['password'],
'password': @user.identity
}
end
{
'auth': {
'identity': identity,
'scope': scope
}
}
end
|
#scope ⇒ Object
33
34
35
36
37
|
# File 'lib/misty/auth/auth_v3.rb', line 33
def scope
return @project.identity if @project
return @domain.identity if @domain
raise Misty::Auth::CredentialsError, "#{self.class}: No scope available"
end
|
#set(response) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/misty/auth/auth_v3.rb', line 39
def set(response)
payload = JSON.load(response.body)
token = response['x-subject-token']
catalog = payload['token']['catalog']
expires = payload['token']['expires_at']
[token, catalog, expires]
end
|
#set_credentials(auth) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/misty/auth/auth_v3.rb', line 47
def set_credentials(auth)
if auth[:project_id] || auth[:project]
project_domain_id = auth[:project_domain_id]
if project_domain_id.nil? && auth[:project_domain].nil?
project_domain_id = Misty::DOMAIN_ID
end
@project = Misty::Auth::ProjectScope.new(auth[:project_id], auth[:project])
@project.domain = Misty::Auth::Name.new(project_domain_id, auth[:project_domain])
else
if auth[:domain_id] || auth[:domain]
@domain = Misty::Auth::DomainScope.new(auth[:domain_id], auth[:domain])
else
@domain = Misty::Auth::DomainScope.new(Misty::DOMAIN_ID, nil)
end
end
if auth[:token]
@token = auth[:token]
else
user_domain_id = auth[:user_domain_id] ? auth[:user_domain_id] : Misty::DOMAIN_ID
@user = Misty::Auth::User.new(auth[:user_id], auth[:user])
@user.password = auth[:password]
@user.domain = Misty::Auth::Name.new(user_domain_id, auth[:user_domain])
end
credentials
end
|