Skip to content

Commit

Permalink
Merge pull request #614 from achanda/handle_status
Browse files Browse the repository at this point in the history
Handle non 200 codes while getting env metadata
  • Loading branch information
dadgar committed Dec 22, 2015
2 parents bcb2ef0 + 13aac9e commit 50e2fbd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions client/fingerprint/env_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (f *EnvAWSFingerprint) Fingerprint(cfg *config.Config, node *structs.Node)
}
for _, k := range keys {
res, err := client.Get(metadataURL + k)
if res.StatusCode != http.StatusOK {
f.logger.Printf("[WARN]: fingerprint.env_aws: Could not read value for attribute %q", k)
continue
}
if err != nil {
// if it's a URL error, assume we're not in an AWS environment
// TODO: better way to detect AWS? Check xen virtualization?
Expand Down
3 changes: 2 additions & 1 deletion client/fingerprint/env_gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (f *EnvGCEFingerprint) Get(attribute string, recursive bool) (string, error
}

res, err := f.client.Do(req)
if err != nil {
if err != nil || res.StatusCode != http.StatusOK {
f.logger.Printf("[WARN]: fingerprint.env_gce: Could not read value for attribute %q", attribute)
return "", err
}

Expand Down

0 comments on commit 50e2fbd

Please sign in to comment.