Sha256: 72c4a9de140638a6de9a094d3202d4e051d8edd4ec58a43760f3570c25b8f15d

Contents?: true

Size: 798 Bytes

Versions: 39

Compression:

Stored size: 798 Bytes

Contents

# frozen_string_literal: true

module Facter
  module Util
    module Resolvers
      module AwsToken
        attr_reader :token

        @log = Facter::Log.new(self)

        class << self
          AWS_API_TOKEN_URL = 'http://169.254.169.254/latest/api/token'

          def get(lifetime = 100)
            @expiry ||= Time.now

            return @token if @token && @expiry > Time.now

            @token = nil
            @expiry = Time.now + lifetime

            headers = {
              'X-aws-ec2-metadata-token-ttl-seconds' => lifetime.to_s
            }

            @token = Facter::Util::Resolvers::Http.put_request(AWS_API_TOKEN_URL, headers)
          end

          def reset
            @expiry = nil
            @token = nil
          end
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/util/resolvers/aws_token.rb
facter-4.9.0 lib/facter/util/resolvers/aws_token.rb
facter-4.8.0 lib/facter/util/resolvers/aws_token.rb
facter-4.7.1 lib/facter/util/resolvers/aws_token.rb
facter-4.7.0 lib/facter/util/resolvers/aws_token.rb
facter-4.6.1 lib/facter/util/resolvers/aws_token.rb
facter-4.6.0 lib/facter/util/resolvers/aws_token.rb
facter-4.5.2 lib/facter/util/resolvers/aws_token.rb
facter-4.5.1 lib/facter/util/resolvers/aws_token.rb
facter-4.5.0 lib/facter/util/resolvers/aws_token.rb
facter-4.4.3 lib/facter/util/resolvers/aws_token.rb
facter-4.4.2 lib/facter/util/resolvers/aws_token.rb
facter-4.4.1 lib/facter/util/resolvers/aws_token.rb
facter-4.4.0 lib/facter/util/resolvers/aws_token.rb
facter-4.3.1 lib/facter/util/resolvers/aws_token.rb
facter-4.3.0 lib/facter/util/resolvers/aws_token.rb
facter-4.2.14 lib/facter/util/resolvers/aws_token.rb
facter-4.2.13 lib/facter/util/resolvers/aws_token.rb
facter-4.2.12 lib/facter/util/resolvers/aws_token.rb
facter-4.2.11 lib/facter/util/resolvers/aws_token.rb