plugins/rest/aws: debug log metadata error (#4061)

A user on Slack is getting 500 responses from the AWS metadata API
using a configuration like the below:

```yaml
 services:
  - name: svc-bundle
    url: https://opa-policies-dev.s3.amazonaws.com
    credentials:
      s3_signing:
        metadata_credentials:
          aws_region: us-east-1
          iam_role: arn:aws:iam::1234:role/opa-bundles
```
It's really hard to know why this might be given how we currently
only log the HTTP status code under this error condition.

This tries to print the response body on debug level (if set).

Signed-off-by: Anders Eknert <anders@eknert.com>
This commit is contained in:
Anders Eknert
2021-11-29 13:18:46 +01:00
committed by GitHub
parent 1cb83490cd
commit c30494e7a0
+6
View File
@@ -378,6 +378,12 @@ func doMetaDataRequestWithClient(req *http.Request, client *http.Client, desc st
}).Debug("Received response from " + desc + " service.")
if resp.StatusCode != 200 {
if logger.GetLevel() == logging.Debug {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Debug("Error response with response body: %v", body)
}
}
// could be 404 for role that's not available, but cover all the bases
return nil, errors.New(desc + " HTTP request returned unexpected status: " + resp.Status)
}