Class: Enviroblyd::IMDS
- Inherits:
-
Object
- Object
- Enviroblyd::IMDS
- 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
- #get(key) ⇒ Object
-
#initialize ⇒ IMDS
constructor
A new instance of IMDS.
- #private_ipv4 ⇒ Object
Constructor Details
#initialize ⇒ IMDS
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_ipv4 ⇒ Object
20 21 22 |
# File 'lib/enviroblyd/imds.rb', line 20 def private_ipv4 get "local-ipv4" end |