Module: Facter::Util::Resolvers::AwsToken

Defined in:
lib/facter/util/resolvers/aws_token.rb

Constant Summary collapse

AWS_API_TOKEN_URL =
'http://169.254.169.254/latest/api/token'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#tokenObject (readonly)



7
8
9
# File 'lib/facter/util/resolvers/aws_token.rb', line 7

def token
  @token
end

Class Method Details

.get(lifetime = 100) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/facter/util/resolvers/aws_token.rb', line 14

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

.resetObject



29
30
31
32
# File 'lib/facter/util/resolvers/aws_token.rb', line 29

def reset
  @expiry = nil
  @token = nil
end