Skip to content

Commit

Permalink
Merge pull request #5131 from RanVaknin/add-logLevel-check-to-suprass…
Browse files Browse the repository at this point in the history
…-warning

Add log level check to gate IMDSv1 fallback warning
  • Loading branch information
RanVaknin committed Jan 5, 2024
2 parents f41238a + efcc00b commit c40776d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
### SDK Enhancements

### SDK Bugs
* The logging behavior in `aws/ec2metadata/token_provider.go` was updated: warnings about falling back to IMDSv1 are now logged only when LogLevel is set to `LogDebugWithDeprecated`.
* This change prevents unnecessary warnings when LogLevel is set to suppress messages.
5 changes: 4 additions & 1 deletion aws/ec2metadata/token_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ec2metadata

import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"net/http"
"sync/atomic"
"time"
Expand Down Expand Up @@ -65,7 +66,9 @@ func (t *tokenProvider) fetchTokenHandler(r *request.Request) {
switch requestFailureError.StatusCode() {
case http.StatusForbidden, http.StatusNotFound, http.StatusMethodNotAllowed:
atomic.StoreUint32(&t.disabled, 1)
t.client.Config.Logger.Log(fmt.Sprintf("WARN: failed to get session token, falling back to IMDSv1: %v", requestFailureError))
if t.client.Config.LogLevel.Matches(aws.LogDebugWithDeprecated) {
t.client.Config.Logger.Log(fmt.Sprintf("WARN: failed to get session token, falling back to IMDSv1: %v", requestFailureError))
}
case http.StatusBadRequest:
r.Error = requestFailureError
}
Expand Down

0 comments on commit c40776d

Please sign in to comment.