forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pure aws-sdk-go auth (thanos-io#4667)
* Add a pure aws-sdk-go auth Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr> * Upgrade github.com/aws/aws-sdk-go-v2 Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr> * Update CHANGELOG.md Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com> * Move s3 conf test in validate() Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr> Co-authored-by: Giedrius Statkevičius <giedriuswork@gmail.com> Signed-off-by: Nicholaswang <wzhever@gmail.com>
- Loading branch information
1 parent
e67e995
commit cf92655
Showing
6 changed files
with
102 additions
and
1 deletion.
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
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,54 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package s3 | ||
|
||
import ( | ||
"context" | ||
|
||
aws "github.com/aws/aws-sdk-go-v2/aws" | ||
awsconfig "github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/minio/minio-go/v7/pkg/credentials" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// AWSSDKAuth retrieves credentials from the aws-sdk-go. | ||
type AWSSDKAuth struct { | ||
Region string | ||
creds aws.Credentials | ||
} | ||
|
||
// NewAWSSDKAuth returns a pointer to a new Credentials object | ||
// wrapping the environment variable provider. | ||
func NewAWSSDKAuth(region string) *credentials.Credentials { | ||
return credentials.New(&AWSSDKAuth{ | ||
Region: region, | ||
}) | ||
} | ||
|
||
// Retrieve retrieves the keys from the environment. | ||
func (a *AWSSDKAuth) Retrieve() (credentials.Value, error) { | ||
cfg, err := awsconfig.LoadDefaultConfig(context.TODO(), awsconfig.WithRegion(a.Region)) | ||
if err != nil { | ||
return credentials.Value{}, errors.Wrap(err, "load AWS SDK config") | ||
} | ||
|
||
creds, err := cfg.Credentials.Retrieve(context.TODO()) | ||
if err != nil { | ||
return credentials.Value{}, errors.Wrap(err, "retrieve AWS SDK credentials") | ||
} | ||
|
||
a.creds = creds | ||
|
||
return credentials.Value{ | ||
AccessKeyID: creds.AccessKeyID, | ||
SecretAccessKey: creds.SecretAccessKey, | ||
SessionToken: creds.SessionToken, | ||
SignerType: credentials.SignatureV4, | ||
}, nil | ||
} | ||
|
||
// IsExpired returns if the credentials have been retrieved. | ||
func (a *AWSSDKAuth) IsExpired() bool { | ||
return a.creds.Expired() | ||
} |