Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update credentials.go #1841

Merged
merged 3 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelog/363e17c617154bf4b6f4f27355dce260.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "363e17c6-1715-4bf4-b6f4-f27355dce260",
"type": "bugfix",
"description": "Fixes an issues where an error from an underlying SigV4 credential provider would not be surfaced from the SigV4a credential provider. Contribution by [sakthipriyan-aqfer](https://github.com/sakthipriyan-aqfer).",
"modules": [
"internal/v4a"
]
}
2 changes: 1 addition & 1 deletion internal/v4a/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type SymmetricCredentialAdaptor struct {
func (s *SymmetricCredentialAdaptor) Retrieve(ctx context.Context) (aws.Credentials, error) {
symCreds, err := s.retrieveFromSymmetricProvider(ctx)
if err != nil {
return aws.Credentials{}, nil
return aws.Credentials{}, err
}

if asymCreds := s.getCreds(); asymCreds == nil {
Expand Down
17 changes: 16 additions & 1 deletion internal/v4a/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import (

type rotatingCredsProvider struct {
count int
fail chan struct{}
}

func (r *rotatingCredsProvider) Retrieve(ctx context.Context) (aws.Credentials, error) {
select {
case <-r.fail:
return aws.Credentials{}, fmt.Errorf("rotatingCredsProvider error")
default:
}
credentials := aws.Credentials{
AccessKeyID: fmt.Sprintf("ACCESS_KEY_ID_%d", r.count),
SecretAccessKey: fmt.Sprintf("SECRET_ACCESS_KEY_%d", r.count),
Expand All @@ -21,7 +27,10 @@ func (r *rotatingCredsProvider) Retrieve(ctx context.Context) (aws.Credentials,
}

func TestSymmetricCredentialAdaptor(t *testing.T) {
provider := &rotatingCredsProvider{}
provider := &rotatingCredsProvider{
count: 0,
fail: make(chan struct{}),
}

adaptor := &SymmetricCredentialAdaptor{SymmetricProvider: provider}

Expand Down Expand Up @@ -58,4 +67,10 @@ func TestSymmetricCredentialAdaptor(t *testing.T) {
if load := adaptor.asymmetric.Load(); load.(*Credentials) != nil {
t.Errorf("expect asymmetric credentials to be nil")
}

close(provider.fail) // All requests to the original provider will now fail from this point-on.
_, err := adaptor.Retrieve(context.Background())
if err == nil {
t.Error("expect error, got nil")
}
}