Class: Enviroblyd::IMDS

Inherits:
Object
  • Object
show all
Defined in:
lib/enviroblyd/imds.rb

Constant Summary collapse

TOKEN_TTL_SECONDS =
30
IMDS_HOST =
ENV.fetch("ENVIROBLYD_IMDS_HOST", "169.254.169.254")

Instance Method Summary collapse

Constructor Details

#initializeIMDS

Returns a new instance of IMDS.



7
8
9
10
11
12
# File 'lib/enviroblyd/imds.rb', line 7

def initialize
  @token = Enviroblyd::Web.http("http://#{IMDS_HOST}/latest/api/token",
    type: Net::HTTP::Put,
    headers: { "X-aws-ec2-metadata-token-ttl-seconds" => TOKEN_TTL_SECONDS.to_s }).
    body.strip
end

Instance Method Details

#get(key) ⇒ Object



14
15
16
17
18
# File 'lib/enviroblyd/imds.rb', line 14

def get(key)
  Enviroblyd::Web.http("http://#{IMDS_HOST}/latest/meta-data/#{key}",
    headers: { "X-aws-ec2-metadata-token" => @token }).
    body.strip
end

#private_ipv4Object



20
21
22
# File 'lib/enviroblyd/imds.rb', line 20

def private_ipv4
  get "local-ipv4"
end