Sha256: d8e3bb1f989232bde447cf9ffb16faebf97c72a8de72175dae0ded0c99d0ccbb

Contents?: true

Size: 1.03 KB

Versions: 30

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class Az < BaseResolver
      init_resolver

      AZ_METADATA_URL = 'http://169.254.169.254/metadata/instance?api-version=2020-09-01'
      AZ_SESSION_TIMEOUT = 5

      class << self
        private

        def post_resolve(fact_name, _options)
          log.debug('Querying Az metadata')
          @fact_list.fetch(fact_name) { read_facts(fact_name) }
        end

        def read_facts(fact_name)
          @fact_list[:metadata] = {}
          data = get_data_from(AZ_METADATA_URL)
          @fact_list[:metadata] = JSON.parse(data) unless data.empty?

          @fact_list[fact_name]
        end

        def get_data_from(url)
          headers = { Metadata: 'true' }
          Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout })
        end

        def determine_session_timeout
          session_env = ENV['AZ_SESSION_TIMEOUT']
          session_env ? session_env.to_i : AZ_SESSION_TIMEOUT
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
facter-4.7.0 lib/facter/resolvers/az.rb
facter-4.6.1 lib/facter/resolvers/az.rb
facter-4.6.0 lib/facter/resolvers/az.rb
facter-4.5.2 lib/facter/resolvers/az.rb
facter-4.5.1 lib/facter/resolvers/az.rb
facter-4.5.0 lib/facter/resolvers/az.rb
facter-4.4.3 lib/facter/resolvers/az.rb
facter-4.4.2 lib/facter/resolvers/az.rb
facter-4.4.1 lib/facter/resolvers/az.rb
facter-4.4.0 lib/facter/resolvers/az.rb
facter-4.3.1 lib/facter/resolvers/az.rb
facter-4.3.0 lib/facter/resolvers/az.rb
facter-4.2.14 lib/facter/resolvers/az.rb
facter-4.2.13 lib/facter/resolvers/az.rb
facter-4.2.12 lib/facter/resolvers/az.rb
facter-4.2.11 lib/facter/resolvers/az.rb
facter-4.2.10 lib/facter/resolvers/az.rb
facter-4.2.9 lib/facter/resolvers/az.rb
facter-4.2.8 lib/facter/resolvers/az.rb
facter-4.2.7 lib/facter/resolvers/az.rb