Class: Armrest::Api::Auth::Metadata

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

Constant Summary collapse

@@available =
nil

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, #request, #send_request, #set_headers!, #standarize_path, #url, #with_open_timeout

Methods included from Settings

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

Methods included from HandleResponse

#load_json, #ok?

Methods included from Logging

#default_logger, #logger, #logger=

Constructor Details

#initialize(options = {}) ⇒ Metadata

Returns a new instance of Metadata.



4
5
6
# File 'lib/armrest/api/auth/metadata.rb', line 4

def initialize(options={})
  @options = options
end

Instance Method Details

#api_versionObject



47
48
49
# File 'lib/armrest/api/auth/metadata.rb', line 47

def api_version
  "2021-10-01"
end

#available?Boolean

Returns:

  • (Boolean)


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

def available?
  return false if ENV['ARMREST_DISABLE_MSI']
  return @@available unless @@available.nil?
  url = "metadata/instance"
  resp = nil
  with_open_timeout(1.5) do
    resp = get(url)
  end
  @@available = resp.code == "200"
rescue Net::OpenTimeout => e
  logger.debug "#{e.class}: #{e.message}"
  false
end

#credsObject



8
9
10
11
12
# File 'lib/armrest/api/auth/metadata.rb', line 8

def creds
  url = "metadata/identity/oauth2/token?" + Rack::Utils.build_query(query_params)
  resp = get(url)
  load_json(resp)
end

#endpointObject

interface method



38
39
40
# File 'lib/armrest/api/auth/metadata.rb', line 38

def endpoint
  "http://169.254.169.254"
end

#headersObject

interface method



43
44
45
# File 'lib/armrest/api/auth/metadata.rb', line 43

def headers
  { Metadata: true }
end

#query_paramsObject



29
30
31
32
33
34
35
# File 'lib/armrest/api/auth/metadata.rb', line 29

def query_params
  params = { resource: resource }
  params[:client_id] = client_id if client_id
  params[:object_id] = object_id if @options[:object_id]
  params[:msi_res_id] = msi_res_id if @options[:msi_res_id]
  params
end