File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -5,10 +5,13 @@ def initialize(host_inventory)
5
5
@host_inventory = host_inventory
6
6
7
7
@base_uri = 'http://169.254.169.254/latest/meta-data/'
8
+ @token_uri = 'http://169.254.169.254/latest/api/token'
9
+ @token = ''
8
10
@metadata = { }
9
11
end
10
12
11
13
def get
14
+ @token = get_token
12
15
@metadata = get_metadata
13
16
self
14
17
end
@@ -64,7 +67,7 @@ def inspect
64
67
def get_metadata ( path = '' )
65
68
metadata = { }
66
69
67
- keys = @host_inventory . backend . run_command ( "curl -s #{ @base_uri } #{ path } " ) . stdout . split ( "\n " )
70
+ keys = @host_inventory . backend . run_command ( "curl -H \" X-aws-ec2-metadata-token: #{ @token } \" - s #{ @base_uri } #{ path } " ) . stdout . split ( "\n " )
68
71
69
72
keys . each do |key |
70
73
if key =~ %r{/$}
@@ -84,7 +87,16 @@ def get_metadata(path='')
84
87
end
85
88
86
89
def get_endpoint ( path )
87
- ret = @host_inventory . backend . run_command ( "curl -s #{ @base_uri } #{ path } " )
90
+ ret = @host_inventory . backend . run_command ( "curl -H \" X-aws-ec2-metadata-token: #{ @token } \" -s #{ @base_uri } #{ path } " )
91
+ if ret . success?
92
+ ret . stdout
93
+ else
94
+ nil
95
+ end
96
+ end
97
+
98
+ def get_token
99
+ ret = @host_inventory . backend . run_command ( "curl -X PUT -H \" X-aws-ec2-metadata-token-ttl-seconds: 21600\" -s #{ @token_uri } " )
88
100
if ret . success?
89
101
ret . stdout
90
102
else
You can’t perform that action at this time.
0 commit comments