-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
- Loading branch information
Showing
6 changed files
with
86 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" | ||
"fmt" | ||
|
||
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" | ||
) | ||
|
||
// 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{}, fmt.Errorf("unable to load AWS SDK config, %v", err) | ||
} | ||
|
||
creds, err := cfg.Credentials.Retrieve(context.TODO()) | ||
if err != nil { | ||
return credentials.Value{}, fmt.Errorf("unable to retrieve AWS SDK credentials, %v", err) | ||
} | ||
|
||
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() | ||
} |