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
#net_http
Constructor Details
#initialize(options, *args) ⇒ AuthV3
Returns a new instance of AuthV3.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/misty/auth/auth_v3.rb', line 5
def initialize(options, *args)
if options[:project_id] || options[:project]
project_domain_id = options[:project_domain_id] ? options[:project_domain_id] : Misty::DOMAIN_ID
@project = Misty::Auth::ProjectScope.new(options[:project_id], options[:project])
@project.domain = Misty::Auth::Name.new(project_domain_id, options[:user_domain])
else
domain_id = options[:domain_id] ? options[:domain_id] : Misty::DOMAIN_ID
@domain = Misty::Auth::DomainScope.new(domain_id, options[:domain]) if domain_id || options[:domain]
end
user_domain_id = options[:user_domain_id] ? options[:user_domain_id] : Misty::DOMAIN_ID
@user = Misty::Auth::User.new(options[:user_id], options[:user])
@user.password = options[:password]
@user.domain = Misty::Auth::Name.new(user_domain_id, options[:user_domain])
super(options, *args)
end
|
Class Method Details
.path ⇒ Object
25
26
27
|
# File 'lib/misty/auth/auth_v3.rb', line 25
def self.path
"/v3/auth/tokens"
end
|
Instance Method Details
#catalog_endpoints(endpoints, region, interface) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/misty/auth/auth_v3.rb', line 29
def catalog_endpoints(endpoints, region, interface)
endpoints.each do |endpoint|
if endpoint["region_id"] == region && endpoint["interface"] == interface
return endpoint["url"]
end
end
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
55
56
57
58
59
|
# File 'lib/misty/auth/auth_v3.rb', line 55
def scope
return @project.identity if @project
return @domain.identity if @domain
raise Misty::Auth::CredentialsError, "#{self.class}: No scope available"
end
|
#scoped_authentication ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/misty/auth/auth_v3.rb', line 43
def scoped_authentication
{
"auth": {
"identity": {
"methods": ["password"],
"password": @user.identity
},
"scope": scope
}
}
end
|
#setup(response) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/misty/auth/auth_v3.rb', line 61
def setup(response)
payload = JSON.load(response.body)
@token = response["x-subject-token"]
@catalog = payload["token"]["catalog"]
@expires = payload["token"]["expires_at"]
end
|