Skip to content

Commit 408ca2f

Browse files
committed
Change return type of get_aws_credentials from AwsCredential to aws_credential_types::Credential
1 parent f365624 commit 408ca2f

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/client/auth/aws.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use aws_config::BehaviorVersion;
33

44
#[cfg(feature = "aws-auth")]
5-
use aws_credential_types::provider::ProvideCredentials;
5+
use aws_credential_types::{provider::ProvideCredentials, Credentials};
66

77
// Note from RUST-1529: commented Duration import since original implementation is commented out
88
// use std::time::Duration;
@@ -99,7 +99,13 @@ async fn authenticate_stream_inner(
9999
let server_first = ServerFirst::parse(server_first_response.auth_response_body(MECH_NAME)?)?;
100100
server_first.validate(&nonce)?;
101101

102-
let aws_credential = get_aws_credentials(credential).await?;
102+
let creds = get_aws_credentials(credential).await?;
103+
let aws_credential = AwsCredential::from_sdk_creds(
104+
creds.access_key_id().to_string(),
105+
creds.secret_access_key().to_string(),
106+
creds.session_token().map(|s| s.to_string()),
107+
None,
108+
);
103109

104110
// Find credentials using original implementation without AWS SDK
105111
// let aws_credential = {
@@ -166,10 +172,10 @@ async fn authenticate_stream_inner(
166172
}
167173

168174
// Find credentials using MongoDB URI or AWS SDK
169-
pub async fn get_aws_credentials(credential: &Credential) -> Result<AwsCredential> {
175+
pub async fn get_aws_credentials(credential: &Credential) -> Result<Credentials> {
170176
if let (Some(access_key), Some(secret_key)) = (&credential.username, &credential.password) {
171177
// Look for credentials in the MongoDB URI
172-
Ok(AwsCredential::from_sdk_creds(
178+
Ok(Credentials::new(
173179
access_key.clone(),
174180
secret_key.clone(),
175181
credential
@@ -178,6 +184,7 @@ pub async fn get_aws_credentials(credential: &Credential) -> Result<AwsCredentia
178184
.and_then(|mp| mp.get_str("AWS_SESSION_TOKEN").ok())
179185
.map(str::to_owned),
180186
None,
187+
"MongoDB URI",
181188
))
182189
} else {
183190
// If credentials are not provided in the URI, use the AWS SDK to load
@@ -195,13 +202,7 @@ pub async fn get_aws_credentials(credential: &Credential) -> Result<AwsCredentia
195202
.map_err(|e| {
196203
Error::authentication_error(MECH_NAME, &format!("failed to get creds: {e}"))
197204
})?;
198-
199-
Ok(AwsCredential::from_sdk_creds(
200-
creds.access_key_id().to_string(),
201-
creds.secret_access_key().to_string(),
202-
creds.session_token().map(|s| s.to_string()),
203-
None,
204-
))
205+
Ok(creds)
205206
}
206207
}
207208

src/client/csfle/state_machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ impl CryptExecutor {
260260
get_aws_credentials(&Credential::default()).await?;
261261

262262
let mut creds = rawdoc! {
263-
"accessKeyId": aws_creds.access_key(),
264-
"secretAccessKey": aws_creds.secret_key(),
263+
"accessKeyId": aws_creds.access_key_id().to_string(),
264+
"secretAccessKey": aws_creds.secret_access_key().to_string(),
265265
};
266266
if let Some(token) = aws_creds.session_token() {
267267
creds.append(cstr!("sessionToken"), token);

0 commit comments

Comments
 (0)