16
16
// under the License.
17
17
18
18
use crate :: aws:: STRICT_ENCODE_SET ;
19
- use crate :: client:: retry:: RetryExt ;
19
+ use crate :: client:: retry:: { ClientConfig , RetryExt } ;
20
20
use crate :: client:: token:: { TemporaryToken , TokenCache } ;
21
21
use crate :: util:: hmac_sha256;
22
- use crate :: { Result , RetryConfig } ;
22
+ use crate :: Result ;
23
23
use bytes:: Buf ;
24
24
use chrono:: { DateTime , Utc } ;
25
25
use futures:: future:: BoxFuture ;
@@ -328,7 +328,7 @@ impl CredentialProvider for StaticCredentialProvider {
328
328
pub struct InstanceCredentialProvider {
329
329
pub cache : TokenCache < Arc < AwsCredential > > ,
330
330
pub client : Client ,
331
- pub retry_config : RetryConfig ,
331
+ pub client_config : ClientConfig ,
332
332
pub imdsv1_fallback : bool ,
333
333
pub metadata_endpoint : String ,
334
334
}
@@ -338,7 +338,7 @@ impl CredentialProvider for InstanceCredentialProvider {
338
338
Box :: pin ( self . cache . get_or_insert_with ( || {
339
339
instance_creds (
340
340
& self . client ,
341
- & self . retry_config ,
341
+ & self . client_config ,
342
342
& self . metadata_endpoint ,
343
343
self . imdsv1_fallback ,
344
344
)
@@ -361,15 +361,15 @@ pub struct WebIdentityProvider {
361
361
pub session_name : String ,
362
362
pub endpoint : String ,
363
363
pub client : Client ,
364
- pub retry_config : RetryConfig ,
364
+ pub client_config : ClientConfig ,
365
365
}
366
366
367
367
impl CredentialProvider for WebIdentityProvider {
368
368
fn get_credential ( & self ) -> BoxFuture < ' _ , Result < Arc < AwsCredential > > > {
369
369
Box :: pin ( self . cache . get_or_insert_with ( || {
370
370
web_identity (
371
371
& self . client ,
372
- & self . retry_config ,
372
+ & self . client_config ,
373
373
& self . token_path ,
374
374
& self . role_arn ,
375
375
& self . session_name ,
@@ -405,7 +405,7 @@ impl From<InstanceCredentials> for AwsCredential {
405
405
/// <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#instance-metadata-security-credentials>
406
406
async fn instance_creds (
407
407
client : & Client ,
408
- retry_config : & RetryConfig ,
408
+ config : & ClientConfig ,
409
409
endpoint : & str ,
410
410
imdsv1_fallback : bool ,
411
411
) -> Result < TemporaryToken < Arc < AwsCredential > > , StdError > {
@@ -417,7 +417,7 @@ async fn instance_creds(
417
417
let token_result = client
418
418
. request ( Method :: PUT , token_url)
419
419
. header ( "X-aws-ec2-metadata-token-ttl-seconds" , "600" ) // 10 minute TTL
420
- . send_retry ( retry_config )
420
+ . send_retry ( config )
421
421
. await ;
422
422
423
423
let token = match token_result {
@@ -438,7 +438,7 @@ async fn instance_creds(
438
438
role_request = role_request. header ( AWS_EC2_METADATA_TOKEN_HEADER , token) ;
439
439
}
440
440
441
- let role = role_request. send_retry ( retry_config ) . await ?. text ( ) . await ?;
441
+ let role = role_request. send_retry ( config ) . await ?. text ( ) . await ?;
442
442
443
443
let creds_url = format ! ( "{endpoint}/{CREDENTIALS_PATH}/{role}" ) ;
444
444
let mut creds_request = client. request ( Method :: GET , creds_url) ;
@@ -447,7 +447,7 @@ async fn instance_creds(
447
447
}
448
448
449
449
let creds: InstanceCredentials =
450
- creds_request. send_retry ( retry_config ) . await ?. json ( ) . await ?;
450
+ creds_request. send_retry ( config ) . await ?. json ( ) . await ?;
451
451
452
452
let now = Utc :: now ( ) ;
453
453
let ttl = ( creds. expiration - now) . to_std ( ) . unwrap_or_default ( ) ;
@@ -491,7 +491,7 @@ impl From<AssumeRoleCredentials> for AwsCredential {
491
491
/// <https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts-technical-overview.html>
492
492
async fn web_identity (
493
493
client : & Client ,
494
- retry_config : & RetryConfig ,
494
+ config : & ClientConfig ,
495
495
token_path : & str ,
496
496
role_arn : & str ,
497
497
session_name : & str ,
@@ -510,7 +510,7 @@ async fn web_identity(
510
510
( "Version" , "2011-06-15" ) ,
511
511
( "WebIdentityToken" , & token) ,
512
512
] )
513
- . send_retry ( retry_config )
513
+ . send_retry ( config )
514
514
. await ?
515
515
. bytes ( )
516
516
. await ?;
@@ -722,7 +722,7 @@ mod tests {
722
722
// For example https://github.com/aws/amazon-ec2-metadata-mock
723
723
let endpoint = env:: var ( "EC2_METADATA_ENDPOINT" ) . unwrap ( ) ;
724
724
let client = Client :: new ( ) ;
725
- let retry_config = RetryConfig :: default ( ) ;
725
+ let config = ClientConfig :: default ( ) ;
726
726
727
727
// Verify only allows IMDSv2
728
728
let resp = client
@@ -737,7 +737,7 @@ mod tests {
737
737
"Ensure metadata endpoint is set to only allow IMDSv2"
738
738
) ;
739
739
740
- let creds = instance_creds ( & client, & retry_config , & endpoint, false )
740
+ let creds = instance_creds ( & client, & config , & endpoint, false )
741
741
. await
742
742
. unwrap ( ) ;
743
743
@@ -762,7 +762,7 @@ mod tests {
762
762
763
763
let endpoint = server. url ( ) ;
764
764
let client = Client :: new ( ) ;
765
- let retry_config = RetryConfig :: default ( ) ;
765
+ let config = ClientConfig :: default ( ) ;
766
766
767
767
// Test IMDSv2
768
768
server. push_fn ( |req| {
@@ -788,7 +788,7 @@ mod tests {
788
788
Response :: new ( Body :: from ( r#"{"AccessKeyId":"KEYID","Code":"Success","Expiration":"2022-08-30T10:51:04Z","LastUpdated":"2022-08-30T10:21:04Z","SecretAccessKey":"SECRET","Token":"TOKEN","Type":"AWS-HMAC"}"# ) )
789
789
} ) ;
790
790
791
- let creds = instance_creds ( & client, & retry_config , endpoint, true )
791
+ let creds = instance_creds ( & client, & config , endpoint, true )
792
792
. await
793
793
. unwrap ( ) ;
794
794
@@ -821,7 +821,7 @@ mod tests {
821
821
Response :: new ( Body :: from ( r#"{"AccessKeyId":"KEYID","Code":"Success","Expiration":"2022-08-30T10:51:04Z","LastUpdated":"2022-08-30T10:21:04Z","SecretAccessKey":"SECRET","Token":"TOKEN","Type":"AWS-HMAC"}"# ) )
822
822
} ) ;
823
823
824
- let creds = instance_creds ( & client, & retry_config , endpoint, true )
824
+ let creds = instance_creds ( & client, & config , endpoint, true )
825
825
. await
826
826
. unwrap ( ) ;
827
827
@@ -838,7 +838,7 @@ mod tests {
838
838
) ;
839
839
840
840
// Should fail
841
- instance_creds ( & client, & retry_config , endpoint, false )
841
+ instance_creds ( & client, & config , endpoint, false )
842
842
. await
843
843
. unwrap_err ( ) ;
844
844
}
0 commit comments