-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathregional_role_client_supplier.rs
51 lines (43 loc) · 1.88 KB
/
regional_role_client_supplier.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
use aws_config::Region;
use aws_db_esdk::com_amazonaws_kms::client::Client as kms_client;
use aws_db_esdk::material_providers::operation::get_client::GetClientInput;
use aws_db_esdk::material_providers::types::error::Error;
use aws_db_esdk::material_providers::types::ClientSupplier;
/*
Example class demonstrating an implementation of a custom client supplier.
This particular implementation will create KMS clients with different IAM roles,
depending on the region passed.
*/
pub struct RegionalRoleClientSupplier {}
impl ClientSupplier for RegionalRoleClientSupplier {
fn get_client(&self, input: GetClientInput) -> Result<kms_client, Error> {
let region = input.region.unwrap();
let arn =
super::regional_role_client_supplier_config::region_iam_role_map()[®ion].clone();
use aws_config::sts::AssumeRoleProvider;
let provider = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
AssumeRoleProvider::builder(arn)
.region(Region::new(region.clone()))
.session_name("Rust-Client-Supplier-Example-Session")
.build()
.await
})
});
let sdk_config = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(async {
aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await
})
});
let kms_config = aws_sdk_kms::config::Builder::from(&sdk_config)
.credentials_provider(provider)
.region(Region::new(region))
.build();
let inner_client = aws_sdk_kms::Client::from_conf(kms_config);
Ok(kms_client {
inner: inner_client,
})
}
}