Class: Misty::AuthV2

Inherits:
Auth
  • Object
show all
Defined in:
lib/misty/auth/auth_v2.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

Constructor Details

This class inherits a constructor from Misty::Auth

Class Method Details

.pathObject



5
6
7
# File 'lib/misty/auth/auth_v2.rb', line 5

def self.path
  "/v2.0/tokens"
end

Instance Method Details

#catalog_endpoints(endpoints, region, interface) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/misty/auth/auth_v2.rb', line 9

def catalog_endpoints(endpoints, region, interface)
  endpoints.each do |endpoint|
    if endpoint["region"] == region && endpoint["#{interface}URL"]
      return endpoint["#{interface}URL"]
    end
  end
end

#credentials_valid?(creds) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/misty/auth/auth_v2.rb', line 17

def credentials_valid?(creds)
  true if creds[:user] && creds[:password] && creds[:tenant]
end

#get_endpoint_url(endpoints, region, interface) ⇒ Object

Raises:



21
22
23
24
25
# File 'lib/misty/auth/auth_v2.rb', line 21

def get_endpoint_url(endpoints, region, interface)
  endpoint = endpoints.select { |ep| !ep[interface].empty? }
  raise CatalogError, "No endpoint available for region '#{region}' and interface '#{interface}'" unless endpoint
  endpoint[0][interface]
end

#scoped_credentials(creds) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/misty/auth/auth_v2.rb', line 34

def scoped_credentials(creds)
  {
    "auth": {
      "passwordCredentials": {
        "username": creds[:user],
        "password": creds[:password]
      },
      "tenantName": creds[:tenant]
    }
  }
end

#setup(response) ⇒ Object



27
28
29
30
31
32
# File 'lib/misty/auth/auth_v2.rb', line 27

def setup(response)
  payload = JSON.load(response.body)
  @token   = payload["access"]["token"]["id"]
  @catalog = payload["access"]["serviceCatalog"]
  @expires = payload["access"]["token"]["expires"]
end