-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport cortexproject/cortex#4897 to fix IDMSv1 (#2760)
* Backport cortexproject/cortex#4897 to fix IDMSv1 Signed-off-by: Jakub Coufal <[email protected]> * Update CHANGELOG.md Signed-off-by: Jakub Coufal <[email protected]> --------- Signed-off-by: Jakub Coufal <[email protected]>
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package s3 | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/defaults" | ||
mcreds "github.com/minio/minio-go/v7/pkg/credentials" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func NewAWSSDKAuth(region string) *AWSSDKAuth { | ||
dc := defaults.Config().WithRegion(region) | ||
creds := defaults.CredChain(dc, defaults.Handlers()) | ||
return &AWSSDKAuth{ | ||
creds: creds, | ||
} | ||
} | ||
|
||
// AWSSDKAuth retrieves credentials from the aws-sdk-go. | ||
type AWSSDKAuth struct { | ||
creds *credentials.Credentials | ||
} | ||
|
||
// Retrieve retrieves the keys from the environment. | ||
func (a *AWSSDKAuth) Retrieve() (mcreds.Value, error) { | ||
val, err := a.creds.Get() | ||
if err != nil { | ||
return mcreds.Value{}, errors.Wrap(err, "retrieve AWS SDK credentials") | ||
} | ||
return mcreds.Value{ | ||
AccessKeyID: val.AccessKeyID, | ||
SecretAccessKey: val.SecretAccessKey, | ||
SessionToken: val.SessionToken, | ||
SignerType: mcreds.SignatureV4, | ||
}, nil | ||
} | ||
|
||
// IsExpired returns if the credentials have been retrieved. | ||
func (a *AWSSDKAuth) IsExpired() bool { | ||
return a.creds.IsExpired() | ||
} |
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