class Misty::Auth::Token::V2

Attributes

tenant[R]

Public Instance Methods

credentials() click to toggle source
# File lib/misty/auth/token/v2.rb, line 11
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
path() click to toggle source
# File lib/misty/auth/token/v2.rb, line 31
def path
  '/v2.0/tokens'
end
set(response) click to toggle source
# File lib/misty/auth/token/v2.rb, line 42
def set(response)
  @data = JSON.load(response.body)
  @token   = @data['access']['token']['id']
  @expires = @data['access']['token']['expires']
  catalog = @data['access']['serviceCatalog']
  @catalog = Misty::Auth::Catalog::V2.new(catalog)
end
set_credentials(auth) click to toggle source
# File lib/misty/auth/token/v2.rb, line 50
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_credentials() click to toggle source
# File lib/misty/auth/token/v2.rb, line 35
def user_credentials
  {
    'username': @user.name,
    'password': @user.password
  }
end