-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update filecache to use AWS SDK Go V2 with wrappers
This changes updates filecache's internal types to use the AWS SDK Go v2's types, while preserving the external interface used by /pkg/token. This will simplify the future project-wide change for AWS SDK Go v2. Signed-off-by: Micah Hausler <[email protected]>
- Loading branch information
1 parent
8464316
commit f4ca661
Showing
8 changed files
with
246 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package filecache | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
) | ||
|
||
type v2 struct { | ||
creds *credentials.Credentials | ||
} | ||
|
||
var _ aws.CredentialsProvider = &v2{} | ||
|
||
func (p *v2) Retrieve(ctx context.Context) (aws.Credentials, error) { | ||
val, err := p.creds.GetWithContext(ctx) | ||
if err != nil { | ||
return aws.Credentials{}, err | ||
} | ||
resp := aws.Credentials{ | ||
AccessKeyID: val.AccessKeyID, | ||
SecretAccessKey: val.SecretAccessKey, | ||
SessionToken: val.SessionToken, | ||
Source: val.ProviderName, | ||
CanExpire: false, | ||
// Don't have account ID | ||
} | ||
|
||
if expiration, err := p.creds.ExpiresAt(); err != nil { | ||
resp.CanExpire = true | ||
resp.Expires = expiration | ||
} | ||
return resp, nil | ||
} | ||
|
||
// V1ProviderToV2Provider converts a v1 credentials.Provider to a v2 aws.CredentialsProvider | ||
func V1ProviderToV2Provider(p credentials.Provider) aws.CredentialsProvider { | ||
return V1CredentialToV2Provider(credentials.NewCredentials(p)) | ||
} | ||
|
||
// V1CredentialToV2Provider converts a v1 credentials.Credential to a v2 aws.CredentialProvider | ||
func V1CredentialToV2Provider(c *credentials.Credentials) aws.CredentialsProvider { | ||
return &v2{creds: c} | ||
} | ||
|
||
// V2CredentialToV1Value converts a v2 aws.Credentials to a v1 credentials.Value | ||
func V2CredentialToV1Value(cred aws.Credentials) credentials.Value { | ||
return credentials.Value{ | ||
AccessKeyID: cred.AccessKeyID, | ||
SecretAccessKey: cred.SecretAccessKey, | ||
SessionToken: cred.SessionToken, | ||
ProviderName: cred.Source, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.