Class: Armrest::Api::Main

Inherits:
Base
  • Object
show all
Defined in:
lib/armrest/api/main.rb

Constant Summary collapse

@@creds_cache =

cache key is the resource/audience. IE:

"https://management.azure.com" => {...,
"https://vault.azure.com" => ...,

}

{}

Constants inherited from Base

Base::HTTP_READ_METHODS, Base::HTTP_WRITE_METHODS, Base::MAX_RETRIES

Instance Method Summary collapse

Methods inherited from Base

#append_api_version, #build_request, #http, #initialize, #request, #send_request, #set_headers!, #standarize_path, #url, #with_open_timeout

Methods included from Settings

#client_id, #client_secret, #endpoint, #group, #location, #resource, #subscription_id, #tenant_id

Methods included from HandleResponse

#load_json, #ok?

Methods included from Logging

#default_logger, #logger, #logger=

Constructor Details

This class inherits a constructor from Armrest::Api::Base

Instance Method Details

#authorizationObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/armrest/api/main.rb', line 16

def authorization
  creds = @@creds_cache[resource]
  if creds && Time.now < Time.at(creds['expires_on'].to_i)
    return bearer_token(creds)
  end

  provider = Armrest::Auth.new(@options).provider
  if provider
    creds = provider.creds
    @@creds_cache[resource] = creds
    bearer_token(creds)
  end
end

#bearer_token(creds) ⇒ Object



30
31
32
# File 'lib/armrest/api/main.rb', line 30

def bearer_token(creds)
  "#{creds['token_type']} #{creds['access_token']}"
end

#headersObject



3
4
5
6
7
8
# File 'lib/armrest/api/main.rb', line 3

def headers
  {
    "Authorization" => authorization,
    "Content-Type" => "application/json",
  }
end