Skip to content

Commit

Permalink
Merge pull request #1750 from DataDog/olivielpeau/ec2-metadata-traili…
Browse files Browse the repository at this point in the history
…ng-slash

[ec2] Add trailing slash to metadata lists endpoints
  • Loading branch information
remh committed Jul 17, 2015
2 parents 7579d0d + ed3a3ea commit 28333fa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ def get_tags(agentConfig):
pass

try:
iam_role = urllib2.urlopen(EC2.METADATA_URL_BASE + "/iam/security-credentials").read().strip()
iam_params = json.loads(urllib2.urlopen(EC2.METADATA_URL_BASE + "/iam/security-credentials" + "/" + unicode(iam_role)).read().strip())
iam_role = urllib2.urlopen(EC2.METADATA_URL_BASE + "/iam/security-credentials/").read().strip()
iam_params = json.loads(urllib2.urlopen(EC2.METADATA_URL_BASE + "/iam/security-credentials/" + unicode(iam_role)).read().strip())
instance_identity = json.loads(urllib2.urlopen(EC2.INSTANCE_IDENTITY_URL).read().strip())
region = instance_identity['region']

Expand Down Expand Up @@ -384,11 +384,11 @@ def get_metadata(agentConfig):
except Exception:
pass

for k in ('instance-id', 'hostname', 'local-hostname', 'public-hostname', 'ami-id', 'local-ipv4', 'public-keys', 'public-ipv4', 'reservation-id', 'security-groups'):
for k in ('instance-id', 'hostname', 'local-hostname', 'public-hostname', 'ami-id', 'local-ipv4', 'public-keys/', 'public-ipv4', 'reservation-id', 'security-groups'):
try:
v = urllib2.urlopen(EC2.METADATA_URL_BASE + "/" + unicode(k)).read().strip()
assert type(v) in (types.StringType, types.UnicodeType) and len(v) > 0, "%s is not a string" % v
EC2.metadata[k] = v
EC2.metadata[k.rstrip('/')] = v
except Exception:
pass

Expand Down

0 comments on commit 28333fa

Please sign in to comment.