Module: Nucleus::Adapters::V1::CloudControl::Authentication

Included in:
Nucleus::Adapters::V1::CloudControl
Defined in:
lib/nucleus/adapters/v1/cloud_control/authentication.rb

Overview

Authentication functionality to support the cloudControl API

Instance Method Summary collapse

Instance Method Details

#auth_clientObject

See Also:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/nucleus/adapters/v1/cloud_control/authentication.rb', line 8

def auth_client
  Token.new @check_certificates do |_verify_ssl, username, password|
    auth_headers = { 'Authorization' => 'Basic ' + ["#{username}:#{password}"].pack('m*').gsub(/\n/, '') }
    begin
      # ssl verification is implemented by the HttpClient itself
      response = post('/token', headers: auth_headers)
      # parse to retrieve the token and expiration date
      expires = Time.parse(response.body[:expires])
      [response.body[:token], expires]
    rescue Errors::AdapterError
      # ignore the error, return nil for failed authentication
      nil
    end
  end
end