2
2
use aws_config:: BehaviorVersion ;
3
3
4
4
#[ cfg( feature = "aws-auth" ) ]
5
- use aws_credential_types:: provider:: ProvideCredentials ;
5
+ use aws_credential_types:: { provider:: ProvideCredentials , Credentials } ;
6
6
7
7
// Note from RUST-1529: commented Duration import since original implementation is commented out
8
8
// use std::time::Duration;
@@ -99,7 +99,13 @@ async fn authenticate_stream_inner(
99
99
let server_first = ServerFirst :: parse ( server_first_response. auth_response_body ( MECH_NAME ) ?) ?;
100
100
server_first. validate ( & nonce) ?;
101
101
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
+ ) ;
103
109
104
110
// Find credentials using original implementation without AWS SDK
105
111
// let aws_credential = {
@@ -166,10 +172,10 @@ async fn authenticate_stream_inner(
166
172
}
167
173
168
174
// 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 > {
170
176
if let ( Some ( access_key) , Some ( secret_key) ) = ( & credential. username , & credential. password ) {
171
177
// Look for credentials in the MongoDB URI
172
- Ok ( AwsCredential :: from_sdk_creds (
178
+ Ok ( Credentials :: new (
173
179
access_key. clone ( ) ,
174
180
secret_key. clone ( ) ,
175
181
credential
@@ -178,6 +184,7 @@ pub async fn get_aws_credentials(credential: &Credential) -> Result<AwsCredentia
178
184
. and_then ( |mp| mp. get_str ( "AWS_SESSION_TOKEN" ) . ok ( ) )
179
185
. map ( str:: to_owned) ,
180
186
None ,
187
+ "MongoDB URI" ,
181
188
) )
182
189
} else {
183
190
// 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
195
202
. map_err ( |e| {
196
203
Error :: authentication_error ( MECH_NAME , & format ! ( "failed to get creds: {e}" ) )
197
204
} ) ?;
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)
205
206
}
206
207
}
207
208
0 commit comments