Skip to content

Commit 3d78f80

Browse files
committed
Get auth credentials through env variables using AWS SDK
1 parent bb11533 commit 3d78f80

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ aws-auth = ["dep:reqwest"]
4646

4747
# Enable support AWS SDK for authentication.
4848
# This can only be used with the tokio-runtime and aws-auth feature flags.
49-
aws-sdk-auth = ["dep:reqwest"]
49+
aws-sdk-auth = ["dep:reqwest", "aws-config"]
5050

5151
# Enable support for on-demand Azure KMS credentials.
5252
# This can only be used with the tokio-runtime feature flag.
@@ -124,10 +124,20 @@ webpki-roots = "0.26"
124124
zstd = { version = "0.11.2", optional = true }
125125
macro_magic = "0.5.1"
126126
rustversion = "1.0.20"
127-
aws-config = { version = "1.1.7", features = ["behavior-version-latest"] }
128127
aws-credential-types = "1.2.4"
129128
aws-types = "1.3.7"
130129

130+
[dependencies.aws-config]
131+
version = "1.8.2"
132+
optional = true
133+
default-features = false
134+
features = [
135+
"behavior-version-latest",
136+
"sso",
137+
"default-https-client",
138+
"rt-tokio"
139+
]
140+
131141
[dependencies.bson2]
132142
git = "https://github.com/mongodb/bson-rust"
133143
branch = "2.15.x"

src/client/auth/aws.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::{fs::File, io::Read, time::Duration};
22

33
// Note: Uncomment the following lines for AWS SDK for authentication
4-
// use aws_config::BehaviorVersion;
5-
// use aws_credential_types::provider::ProvideCredentials;
6-
// use aws_types::sdk_config::SharedCredentialsProvider;
4+
use aws_config::BehaviorVersion;
5+
use aws_credential_types::provider::ProvideCredentials;
6+
use aws_types::sdk_config::SharedCredentialsProvider;
77
use chrono::{offset::Utc, DateTime};
88
use hmac::Hmac;
99
use once_cell::sync::Lazy;
@@ -111,29 +111,21 @@ async fn authenticate_stream_inner(
111111
)
112112
} else {
113113
// If credentials are not provided in the URI, use the AWS SDK to load
114-
// Note: Untested but compiles
115-
// let creds = aws_config::load_defaults(BehaviorVersion::latest())
116-
// .await
117-
// .credentials_provider()
118-
// .expect("no credential provider configured")
119-
// .provide_credentials()
120-
// .await
121-
// .map_err(|e| {
122-
// Error::authentication_error(MECH_NAME, &format!("failed to get creds: {e}"))
123-
// })?;
124-
// AwsCredential::from_sdk_creds(
125-
// creds.access_key_id().to_string(),
126-
// creds.secret_access_key().to_string(),
127-
// creds.session_token().map(|s| s.to_string()),
128-
// None,
129-
// )
130-
131-
// For now, throw an error
132-
return Err(Error::authentication_error(
133-
MECH_NAME,
134-
"Credentials must be provided in the MongoDB URI - methods supported by the AWS SDK \
135-
are not yet tested",
136-
));
114+
let creds = aws_config::load_defaults(BehaviorVersion::latest())
115+
.await
116+
.credentials_provider()
117+
.expect("no credential provider configured")
118+
.provide_credentials()
119+
.await
120+
.map_err(|e| {
121+
Error::authentication_error(MECH_NAME, &format!("failed to get creds: {e}"))
122+
})?;
123+
AwsCredential::from_sdk_creds(
124+
creds.access_key_id().to_string(),
125+
creds.secret_access_key().to_string(),
126+
creds.session_token().map(|s| s.to_string()),
127+
None,
128+
)
137129
};
138130
#[cfg(not(feature = "aws-sdk-auth"))]
139131
let aws_credential = {

0 commit comments

Comments
 (0)