Class: Rackconnect::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/rackconnect/lib/auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Auth

Returns a new instance of Auth.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rackconnect/lib/auth.rb', line 3

def initialize(options={})
  api_key  = options[:api_key]
  username = options[:username]

  params = {
    :auth => {
      "RAX-KSKEY:apiKeyCredentials" => {
        "apiKey" => api_key,
        "username" => username
      }
    }
  }.to_json

  resp = RestClient.post Rackconnect::IDENTITY_URL, params, content_type: :json, accept: :json
  body = JSON.parse(resp)

  Rackconnect.token     = body["access"]["token"]["id"]
  Rackconnect.tenant_id = body["access"]["token"]["tenant"]["id"]
end

Instance Method Details

#to_sObject



23
24
25
# File 'lib/rackconnect/lib/auth.rb', line 23

def to_s
  {auth_token: Rackconnect.token, tenant_id: Rackconnect.tenant_id}
end