Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1cb45d

Browse files
committedSep 24, 2024··
m
1 parent b2bce62 commit f1cb45d

File tree

4 files changed

+23
-51
lines changed

4 files changed

+23
-51
lines changed
 

‎DynamoDbEncryption/runtimes/rust/Cargo.toml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
name = "aws-db-esdk"
33
version = "0.1.0"
44
edition = "2021"
5+
rust-version = "1.80.0"
6+
keywords = ["crypto", "cryptography", "security", "dynamodb", "ddb", "encryption", "client-side", "clientside"]
7+
license = "ISC AND (Apache-2.0 OR ISC)"
8+
description = "aws-db-esdk is a library for implementing client side encryption with DynamoDB."
9+
homepage = "https://github.com/aws/aws-database-encryption-sdk-dynamodb/tree/main/releases/rust/db_esdk"
10+
repository = "https://github.com/aws/aws-database-encryption-sdk-dynamodb/tree/main/releases/rust/db_esdk"
11+
authors = ["AWS-CryptoTools"]
12+
documentation = "https://docs.rs/crate/aws-db-esdk"
513

614
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
715

816
[dependencies]
917
aws-config = "1.5.6"
1018
aws-lc-rs = "1.9.0"
11-
aws-lc-sys = "0.21.1"
12-
aws-sdk-dynamodb = "1.45.0"
13-
aws-sdk-kms = "1.43.0"
14-
aws-smithy-runtime = {version = "1.7.1", features = ["client"] }
19+
aws-lc-sys = "0.21.2"
20+
aws-sdk-dynamodb = "1.47.0"
21+
aws-sdk-kms = "1.44.0"
1522
aws-smithy-runtime-api = {version = "1.7.2", features = ["client"] }
1623
aws-smithy-types = "1.2.6"
17-
aws-types = "1.3.3"
1824
chrono = "0.4.38"
1925
dafny_runtime = { path = "dafny_runtime_rust"}
2026
dashmap = "6.1.0"
@@ -24,6 +30,3 @@ uuid = { version = "1.10.0", features = ["v4"] }
2430

2531
[lib]
2632
path = "src/implementation_from_dafny.rs"
27-
28-
[dev-dependencies]
29-
aws-sdk-sts = "1.43.0"

‎DynamoDbEncryption/runtimes/rust/dafny_runtime_rust/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ edition = "2021"
55

66
[dependencies]
77
once_cell = "1.18.0"
8-
paste = "1.0"
98
num = "0.4"
109
itertools = "0.11.0"
11-
as-any = "0.3.1"

‎DynamoDbEncryption/runtimes/rust/examples/clientsupplier/client_supplier_example.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn put_item_get_item() -> Result<(), crate::BoxError> {
5555
// Note: RegionalRoleClientSupplier will internally use the key_arn's region
5656
// to retrieve the correct IAM role.
5757
let supplier_ref = ClientSupplierRef {
58-
inner: std::rc::Rc::new(std::cell::RefCell::new(RegionalRoleClientSupplier::new())),
58+
inner: std::rc::Rc::new(std::cell::RefCell::new(RegionalRoleClientSupplier {})),
5959
};
6060

6161
let mrk_keyring_with_client_supplier = mpl

‎DynamoDbEncryption/runtimes/rust/examples/clientsupplier/regional_role_client_supplier.rs

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,40 @@ use aws_db_esdk::aws_cryptography_materialProviders::types::ClientSupplier;
33
use aws_db_esdk::deps::aws_cryptography_materialProviders::operation::get_client::GetClientInput;
44
use aws_db_esdk::deps::aws_cryptography_materialProviders::types::error::Error;
55
use aws_db_esdk::deps::com_amazonaws_kms::client::Client as kms_client;
6-
use aws_sdk_sts::Client as sts_client;
76

87
/*
98
Example class demonstrating an implementation of a custom client supplier.
109
This particular implementation will create KMS clients with different IAM roles,
1110
depending on the region passed.
1211
*/
1312

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 {}
3014

3115
impl ClientSupplier for RegionalRoleClientSupplier {
3216
fn get_client(&mut self, input: GetClientInput) -> Result<kms_client, Error> {
3317
let region = input.region.unwrap();
3418
let arn =
3519
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(|| {
3724
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()
4429
.await
4530
})
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+
});
6132

6233
let sdk_config = tokio::task::block_in_place(|| {
6334
tokio::runtime::Handle::current().block_on(async {
6435
aws_config::load_defaults(aws_config::BehaviorVersion::v2024_03_28()).await
6536
})
6637
});
6738
let kms_config = aws_sdk_kms::config::Builder::from(&sdk_config)
68-
.credentials_provider(cred_prov)
39+
.credentials_provider(provider)
6940
.region(Region::new(region))
7041
.build();
7142

0 commit comments

Comments
 (0)
Please sign in to comment.