Class: Miasma::Contrib::OpenStackApiCore::Authenticate::Version2

Inherits:
Miasma::Contrib::OpenStackApiCore::Authenticate show all
Defined in:
lib/miasma/contrib/open_stack.rb

Overview

Authentication implementation compatible for v2

Instance Attribute Summary

Attributes inherited from Miasma::Contrib::OpenStackApiCore::Authenticate

#credentials, #token

Instance Method Summary collapse

Methods inherited from Miasma::Contrib::OpenStackApiCore::Authenticate

#api_token, #identity_and_load, #initialize, #service_catalog, #user

Constructor Details

This class inherits a constructor from Miasma::Contrib::OpenStackApiCore::Authenticate

Instance Method Details

#authentication_requestSmash

Returns authentication request body.

Returns:

  • (Smash)

    authentication request body



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/miasma/contrib/open_stack.rb', line 70

def authentication_request
  if(credentials[:open_stack_token])
    auth = Smash.new(
      :token => Smash.new(
        :id => credentials[:open_stack_token]
      )
    )
  else
    auth = Smash.new(
      'passwordCredentials' => Smash.new(
        'username' => credentials[:open_stack_username],
        'password' => credentials[:open_stack_password]
      )
    )
  end
  if(credentials[:open_stack_tenant_name])
    auth['tenantName'] = credentials[:open_stack_tenant_name]
  end
  auth
end

#identify_and_loadTrueClass

Identify with authentication service and load token information and service catalog

Returns:

  • (TrueClass)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/miasma/contrib/open_stack.rb', line 95

def identify_and_load
  result = HTTP.post(
    File.join(
      credentials[:open_stack_identity_url],
      'tokens'
    ),
    :json => Smash.new(
      :auth => authentication_request
    )
  )
  unless(result.status == 200)
    raise Error::ApiError::AuthenticationError.new('Failed to authenticate', :response => result)
  end
  info = MultiJson.load(result.body.to_s).to_smash
  info = info[:access]
  @user = info[:user]
  @service_catalog = info[:serviceCatalog]
  @token = info[:token]
  token[:expires] = Time.parse(token[:expires])
  true
end