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
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Auth
#authenticate, #expired?, factory, #get_endpoint, #get_token, #initialize
net_http
Constructor Details
This class inherits a constructor from Misty::Auth
Class Method Details
.path ⇒ Object
5
6
7
|
# File 'lib/misty/auth/auth_v3.rb', line 5
def self.path
"/v3/auth/tokens"
end
|
Instance Method Details
#catalog_endpoints(endpoints, region, interface) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/misty/auth/auth_v3.rb', line 9
def catalog_endpoints(endpoints, region, interface)
endpoints.each do |endpoint|
if endpoint["region_id"] == region && endpoint["interface"] == interface
return endpoint["url"]
end
end
end
|
#credentials ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/misty/auth/auth_v3.rb', line 17
def credentials
if @token
identity = {
"methods": ["token"],
"token": { "id": @token }
}
else
identity = {
"methods": ["password"],
"password": @user.identity
}
end
{
"auth": {
"identity": identity,
"scope": scope
}
}
end
|
#get_endpoint_url(endpoints, region, interface) ⇒ Object
37
38
39
40
41
|
# File 'lib/misty/auth/auth_v3.rb', line 37
def get_endpoint_url(endpoints, region, interface)
endpoint = endpoints.select { |ep| ep["region_id"] == region && ep["interface"] == interface }
raise CatalogError, "No endpoint available for region '#{region}' and interface '#{interface}'" unless endpoint
endpoint[0]["url"]
end
|
#scope ⇒ Object
43
44
45
46
47
|
# File 'lib/misty/auth/auth_v3.rb', line 43
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
49
50
51
52
53
54
55
|
# File 'lib/misty/auth/auth_v3.rb', line 49
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/misty/auth/auth_v3.rb', line 57
def set_credentials(auth)
if auth[:project_id] || auth[:project]
project_domain_id = auth[:project_domain_id] ? auth[:project_domain_id] : Misty::DOMAIN_ID
@project = Misty::Auth::ProjectScope.new(auth[:project_id], auth[:project])
@project.domain = Misty::Auth::Name.new(project_domain_id, auth[:user_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
|