Class: Misty::Auth
Defined Under Namespace
Modules: Domain
Classes: AuthenticationError, CatalogError, CredentialsError, DomainScope, ExpiryError, InitError, Name, ProjectScope, TokenError, URLError, User
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
net_http
Constructor Details
#initialize(auth, http) ⇒ Auth
Returns a new instance of Auth.
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/misty/auth.rb', line 33
def initialize(auth, http)
if auth[:context]
@token = auth[:context][:token]
@catalog = auth[:context][:catalog]
@expires = auth[:context][:expires]
else
@http = http
@credentials = set_credentials(auth)
@token, @catalog, @expires = set(authenticate)
end
end
|
Instance Attribute Details
#catalog ⇒ Object
Returns the value of attribute catalog.
17
18
19
|
# File 'lib/misty/auth.rb', line 17
def catalog
@catalog
end
|
#token ⇒ Object
Returns the value of attribute token.
17
18
19
|
# File 'lib/misty/auth.rb', line 17
def token
@token
end
|
Class Method Details
.factory(auth, config) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/misty/auth.rb', line 19
def self.factory(auth, config)
http = nil
unless auth[:context]
raise URLError, "No URL provided" unless auth[:url] && !auth[:url].empty?
http = Misty::HTTP::NetHTTP.net_http(URI.parse(auth[:url]), config.ssl_verify_mode, config.log)
end
if auth[:tenant_id] || auth[:tenant]
return Misty::AuthV2.new(auth, http)
else
return Misty::AuthV3.new(auth, http)
end
end
|
Instance Method Details
#authenticate ⇒ Object
47
48
49
50
51
|
# File 'lib/misty/auth.rb', line 47
def authenticate
response = @http.post(self.class.path, @credentials.to_json, Misty::HEADER_JSON)
raise AuthenticationError, "Response code=#{response.code}, Msg=#{response.msg}" unless response.code =~ /200|201/
response
end
|
#expired? ⇒ Boolean
53
54
55
56
|
# File 'lib/misty/auth.rb', line 53
def expired?
raise ExpiryError, "Missing token expiration data" if @expires.nil? || @expires.empty?
Time.parse(@expires) < Time.now.utc
end
|
#get_endpoint(service_names, region, interface) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/misty/auth.rb', line 58
def get_endpoint(service_names, region, interface)
@catalog.each do |catalog|
if service_names.include? catalog["type"]
return catalog_endpoints(catalog["endpoints"], region, interface)
end
end
raise CatalogError, "No service found with either #{service_names} name, region #{region}, interface #{interface}"
end
|
#get_token ⇒ Object
67
68
69
70
|
# File 'lib/misty/auth.rb', line 67
def get_token
@token, @catalog, @expires = set(authenticate) if expired?
@token
end
|