class Armrest::Api::Auth::Metadata

Public Class Methods

new(options={}) click to toggle source
# File lib/armrest/api/auth/metadata.rb, line 4
def initialize(options={})
  @options = options
end

Public Instance Methods

api_version() click to toggle source
# File lib/armrest/api/auth/metadata.rb, line 47
def api_version
  "2021-10-01"
end
available?() click to toggle source
# 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(0.5) do
    resp = get(url)
  end
  @@available = resp.code == "200"
rescue Net::OpenTimeout => e
  logger.debug "#{e.class}: #{e.message}"
  false
end
creds() click to toggle source
# 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
endpoint() click to toggle source

interface method

# File lib/armrest/api/auth/metadata.rb, line 38
def endpoint
  "http://169.254.169.254"
end
headers() click to toggle source

interface method

# File lib/armrest/api/auth/metadata.rb, line 43
def headers
  { Metadata: true }
end
query_params() click to toggle source
# 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