Skip to content

Commit d78e700

Browse files
liangxiao1TurboTurtle
authored andcommitted
[plugin_aws]fix unable to get metadata in aws.py
- exec_cmd() cmd type is a str, cannot execute when it is a list - removed spaces after X-aws-ec2-metadata-token and X-aws-ec2-metadata-token-ttl-seconds Signed-off-by: Frank Liang <[email protected]>
1 parent 586fb45 commit d78e700

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

sos/report/plugins/aws.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,19 @@ def setup(self):
4141

4242
# Try to get an IMDSv2 token
4343
token_url = 'http://169.254.169.254/latest/api/token'
44-
token_cmd = [
45-
'curl', '-sS', '-X', 'PUT', '-H',
46-
'X-aws-ec2-metadata-token-ttl-seconds: 21600',
47-
token_url]
44+
token_cmd = f'curl -sS -X PUT -H \
45+
X-aws-ec2-metadata-token-ttl-seconds:21600 {token_url}'
4846

4947
try:
50-
token = self.exec_cmd(token_cmd, timeout=1)
48+
token = self.exec_cmd(token_cmd, timeout=1)['output']
5149
except Exception:
5250
token = ''
5351

5452
# Add header only if token retrieval succeeded
55-
token_header = []
53+
token_header = ''
5654

5755
if token:
58-
token_header = ['-H', f'X-aws-ec2-metadata-token: {token}']
56+
token_header = f'-H X-aws-ec2-metadata-token:{token}'
5957

6058
# List of metadata paths we want to get
6159
metadata_paths = [
@@ -73,7 +71,7 @@ def setup(self):
7371
meta_url = base_url + path
7472
safe_name = path.replace('/', '_')
7573
self.add_cmd_output(
76-
['curl', '-sS'] + token_header + [meta_url],
74+
f'curl -sS {token_header} {meta_url}',
7775
suggest_filename=f'aws_metadata_{safe_name}.txt'
7876
)
7977

0 commit comments

Comments
 (0)