Class: Misty::Auth::Token::V2

Inherits:
Object
  • Object
show all
Includes:
Misty::Auth::Token
Defined in:
lib/misty/auth/token/v2.rb

Constant Summary

Constants included from Misty::Auth::Token

DOMAIN_ID

Instance Attribute Summary

Attributes included from Misty::Auth::Token

#catalog, #token

Instance Method Summary collapse

Methods included from Misty::Auth::Token

build, #get, #initialize

Methods included from HTTP::NetHTTP

http_request

Instance Method Details

#credentialsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/misty/auth/token/v2.rb', line 10

def credentials
  if @token
    identity = { 'token': { 'id': @token } }
  else
    raise CredentialsError, "#{self.class}: User name is required" if @user.name.nil?
    raise CredentialsError, "#{self.class}: User password is required" if @user.password.nil?
    identity = { 'passwordCredentials': user_credentials }
  end

  if @tenant.id
    identity.merge!('tenantId': @tenant.id)
  elsif @tenant.name
    identity.merge!('tenantName': @tenant.name)
  else
    raise CredentialsError, "#{self.class}: No tenant available"
  end

  { 'auth': identity }
end

#pathObject



30
31
32
# File 'lib/misty/auth/token/v2.rb', line 30

def path
  '/v2.0/tokens'
end

#set(response) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/misty/auth/token/v2.rb', line 41

def set(response)
  payload = JSON.load(response.body)
  @token   = payload['access']['token']['id']
  @expires = payload['access']['token']['expires']
  catalog = payload['access']['serviceCatalog']
  @catalog = Misty::Auth::Catalog::V2.new(catalog)
end

#set_credentials(auth) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/misty/auth/token/v2.rb', line 49

def set_credentials(auth)
  if auth[:token]
    @token = auth[:token]
  else
    @user = Misty::Auth::User.new(auth[:user_id], auth[:user])
    @user.password = auth[:password]
  end

  @tenant = Misty::Auth::Name.new(auth[:tenant_id], auth[:tenant])
  credentials
end

#user_credentialsObject



34
35
36
37
38
39
# File 'lib/misty/auth/token/v2.rb', line 34

def user_credentials
  {
    'username': @user.name,
    'password': @user.password
  }
end