-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-3454 Support custom AWS credential provider. #2228
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||||||||||||||||
| // Copyright (C) MongoDB, Inc. 2025-present. | ||||||||||||||||||||
| // | ||||||||||||||||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); you may | ||||||||||||||||||||
| // not use this file except in compliance with the License. You may obtain | ||||||||||||||||||||
| // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| package credproviders | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import ( | ||||||||||||||||||||
| "context" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| "go.mongodb.org/mongo-driver/v2/internal/aws" | ||||||||||||||||||||
| "go.mongodb.org/mongo-driver/v2/internal/aws/credentials" | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const awsProviderName = "AwsProvider" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // AwsProvider retrieves credentials from the given AWS credentials provider. | ||||||||||||||||||||
| type AwsProvider struct { | ||||||||||||||||||||
| credentials *aws.Credentials | ||||||||||||||||||||
| Provider func(context.Context) (aws.Credentials, error) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Retrieve retrieves the keys from the given AWS credentials provider. | ||||||||||||||||||||
| func (a *AwsProvider) Retrieve(ctx context.Context) (credentials.Value, error) { | ||||||||||||||||||||
| var value credentials.Value | ||||||||||||||||||||
| if a.credentials == nil { | ||||||||||||||||||||
| creds, err := a.Provider(ctx) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| return value, err | ||||||||||||||||||||
| } | ||||||||||||||||||||
| a.credentials = &creds | ||||||||||||||||||||
| } | ||||||||||||||||||||
| value.AccessKeyID = a.credentials.AccessKeyID | ||||||||||||||||||||
| value.SecretAccessKey = a.credentials.SecretAccessKey | ||||||||||||||||||||
| value.SessionToken = a.credentials.SessionToken | ||||||||||||||||||||
| value.ProviderName = awsProviderName | ||||||||||||||||||||
| return value, nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // IsExpired returns true if the credentials have not been retrieved. | ||||||||||||||||||||
| func (a *AwsProvider) IsExpired() bool { | ||||||||||||||||||||
| if a.credentials == nil || a.credentials.ExpirationCallback == nil { | ||||||||||||||||||||
| return true | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
||||||||||||||||||||
| if a.credentials == nil || a.credentials.ExpirationCallback == nil { | |
| return true | |
| } | |
| if a.credentials == nil { | |
| return true | |
| } | |
| if a.credentials.ExpirationCallback == nil { | |
| return false | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename this to
AWSCredentialssince it seems to be specific to the MONGODB-AWS auth mechanism.