@@ -3,69 +3,40 @@ use aws_db_esdk::aws_cryptography_materialProviders::types::ClientSupplier;
3
3
use aws_db_esdk:: deps:: aws_cryptography_materialProviders:: operation:: get_client:: GetClientInput ;
4
4
use aws_db_esdk:: deps:: aws_cryptography_materialProviders:: types:: error:: Error ;
5
5
use aws_db_esdk:: deps:: com_amazonaws_kms:: client:: Client as kms_client;
6
- use aws_sdk_sts:: Client as sts_client;
7
6
8
7
/*
9
8
Example class demonstrating an implementation of a custom client supplier.
10
9
This particular implementation will create KMS clients with different IAM roles,
11
10
depending on the region passed.
12
11
*/
13
12
14
- pub struct RegionalRoleClientSupplier {
15
- sts_client : sts_client , // private readonly AmazonSecurityTokenServiceClient _stsClient = new AmazonSecurityTokenServiceClient();
16
- }
17
-
18
- impl RegionalRoleClientSupplier {
19
- pub fn new ( ) -> Self {
20
- let sdk_config = tokio:: task:: block_in_place ( || {
21
- tokio:: runtime:: Handle :: current ( ) . block_on ( async {
22
- aws_config:: load_defaults ( aws_config:: BehaviorVersion :: v2024_03_28 ( ) ) . await
23
- } )
24
- } ) ;
25
- Self {
26
- sts_client : sts_client:: new ( & sdk_config) ,
27
- }
28
- }
29
- }
13
+ pub struct RegionalRoleClientSupplier { }
30
14
31
15
impl ClientSupplier for RegionalRoleClientSupplier {
32
16
fn get_client ( & mut self , input : GetClientInput ) -> Result < kms_client , Error > {
33
17
let region = input. region . unwrap ( ) ;
34
18
let arn =
35
19
super :: regional_role_client_supplier_config:: region_iam_role_map ( ) [ & region] . clone ( ) ;
36
- let creds = tokio:: task:: block_in_place ( || {
20
+
21
+ use aws_config:: sts:: AssumeRoleProvider ;
22
+
23
+ let provider = tokio:: task:: block_in_place ( || {
37
24
tokio:: runtime:: Handle :: current ( ) . block_on ( async {
38
- self . sts_client
39
- . assume_role ( )
40
- . role_arn ( arn)
41
- . duration_seconds ( 900 )
42
- . role_session_name ( "Rust-Client-Supplier-Example-Session" )
43
- . send ( )
25
+ AssumeRoleProvider :: builder ( arn)
26
+ . region ( Region :: new ( region. clone ( ) ) )
27
+ . session_name ( "Rust-Client-Supplier-Example-Session" )
28
+ . build ( )
44
29
. await
45
30
} )
46
- } )
47
- . unwrap ( ) ;
48
-
49
- let types_cred = creds. credentials . unwrap ( ) ;
50
- let config_creds = aws_sdk_sts:: config:: Credentials :: new (
51
- types_cred. access_key_id ( ) ,
52
- types_cred. secret_access_key ( ) ,
53
- Some ( types_cred. session_token ( ) . to_string ( ) ) ,
54
- Some (
55
- std:: time:: SystemTime :: UNIX_EPOCH
56
- + std:: time:: Duration :: from_secs ( types_cred. expiration ( ) . secs ( ) as u64 ) ,
57
- ) ,
58
- "SomeProvider" ,
59
- ) ;
60
- let cred_prov = aws_sdk_kms:: config:: SharedCredentialsProvider :: new ( config_creds) ;
31
+ } ) ;
61
32
62
33
let sdk_config = tokio:: task:: block_in_place ( || {
63
34
tokio:: runtime:: Handle :: current ( ) . block_on ( async {
64
35
aws_config:: load_defaults ( aws_config:: BehaviorVersion :: v2024_03_28 ( ) ) . await
65
36
} )
66
37
} ) ;
67
38
let kms_config = aws_sdk_kms:: config:: Builder :: from ( & sdk_config)
68
- . credentials_provider ( cred_prov )
39
+ . credentials_provider ( provider )
69
40
. region ( Region :: new ( region) )
70
41
. build ( ) ;
71
42
0 commit comments