@@ -32,7 +32,7 @@ use std::collections::HashMap;
32
32
- Partition key is named "partition_key" with type (S)
33
33
- Sort key is named "sort_key" with type (S)
34
34
*/
35
- pub async fn put_item_get_item ( ) {
35
+ pub async fn put_item_get_item ( ) -> Result < ( ) , crate :: BoxError > {
36
36
let ddb_table_name = test_utils:: TEST_DDB_TABLE_NAME ;
37
37
// Note that we pass in an MRK in us-east-1...
38
38
let key_arn = test_utils:: TEST_MRK_REPLICA_KEY_ID_US_EAST_1 . to_string ( ) ;
@@ -47,24 +47,23 @@ pub async fn put_item_get_item() {
47
47
// 2) the key must be an MRK with a replica defined
48
48
// in a region in the regions list, and the client
49
49
// must have the correct permissions to access the replica.
50
- let mpl_config = MaterialProvidersConfig :: builder ( ) . build ( ) . unwrap ( ) ;
51
- let mpl = mpl_client:: Client :: from_conf ( mpl_config) . unwrap ( ) ;
50
+ let mpl_config = MaterialProvidersConfig :: builder ( ) . build ( ) ? ;
51
+ let mpl = mpl_client:: Client :: from_conf ( mpl_config) ? ;
52
52
53
53
// Create the multi-keyring using our custom client supplier
54
54
// defined in the RegionalRoleClientSupplier class in this directory.
55
55
// Note: RegionalRoleClientSupplier will internally use the key_arn's region
56
56
// to retrieve the correct IAM role.
57
57
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 { } ) ) ,
59
59
} ;
60
60
61
61
let mrk_keyring_with_client_supplier = mpl
62
62
. create_aws_kms_mrk_multi_keyring ( )
63
63
. client_supplier ( supplier_ref. clone ( ) )
64
64
. generator ( key_arn)
65
65
. send ( )
66
- . await
67
- . unwrap ( ) ;
66
+ . await ?;
68
67
69
68
// 2. Configure which attributes are encrypted and/or signed when writing new items.
70
69
// For each attribute that may exist on the items we plan to write to our DynamoDbTable,
@@ -116,13 +115,11 @@ pub async fn put_item_get_item() {
116
115
. attribute_actions_on_encrypt ( attribute_actions_on_encrypt. clone ( ) )
117
116
. keyring ( mrk_keyring_with_client_supplier)
118
117
. allowed_unsigned_attribute_prefix ( UNSIGNED_ATTR_PREFIX )
119
- . build ( )
120
- . unwrap ( ) ;
118
+ . build ( ) ?;
121
119
122
120
let table_configs = DynamoDbTablesEncryptionConfig :: builder ( )
123
121
. table_encryption_configs ( HashMap :: from ( [ ( ddb_table_name. to_string ( ) , table_config) ] ) )
124
- . build ( )
125
- . unwrap ( ) ;
122
+ . build ( ) ?;
126
123
127
124
// 5. Create a new AWS SDK DynamoDb client using the DynamoDb Config above
128
125
let sdk_config = aws_config:: load_defaults ( aws_config:: BehaviorVersion :: latest ( ) ) . await ;
@@ -149,13 +146,11 @@ pub async fn put_item_get_item() {
149
146
) ,
150
147
] ) ;
151
148
152
- let _resp = ddb
153
- . put_item ( )
149
+ ddb. put_item ( )
154
150
. table_name ( ddb_table_name)
155
151
. set_item ( Some ( item. clone ( ) ) )
156
152
. send ( )
157
- . await
158
- . unwrap ( ) ;
153
+ . await ?;
159
154
160
155
// 7. Get the item back from our table using the same keyring.
161
156
// The client will decrypt the item client-side using the MRK
@@ -174,8 +169,7 @@ pub async fn put_item_get_item() {
174
169
. set_key ( Some ( key_to_get. clone ( ) ) )
175
170
. consistent_read ( true )
176
171
. send ( )
177
- . await
178
- . unwrap ( ) ;
172
+ . await ?;
179
173
180
174
assert_eq ! (
181
175
resp. item. unwrap( ) [ "sensitive_data" ] ,
@@ -193,17 +187,15 @@ pub async fn put_item_get_item() {
193
187
let discovery_filter = DiscoveryFilter :: builder ( )
194
188
. partition ( "aws" )
195
189
. account_ids ( account_ids)
196
- . build ( )
197
- . unwrap ( ) ;
190
+ . build ( ) ?;
198
191
199
192
let mrk_discovery_client_supplier_keyring = mpl
200
193
. create_aws_kms_mrk_discovery_multi_keyring ( )
201
194
. client_supplier ( supplier_ref. clone ( ) )
202
195
. discovery_filter ( discovery_filter)
203
196
. regions ( regions)
204
197
. send ( )
205
- . await
206
- . unwrap ( ) ;
198
+ . await ?;
207
199
208
200
// 9. Create a new config and client using the discovery keyring.
209
201
// This is the same setup as above, except we provide the discovery keyring to the config.
@@ -214,16 +206,14 @@ pub async fn put_item_get_item() {
214
206
. attribute_actions_on_encrypt ( attribute_actions_on_encrypt)
215
207
. keyring ( mrk_discovery_client_supplier_keyring)
216
208
. allowed_unsigned_attribute_prefix ( UNSIGNED_ATTR_PREFIX )
217
- . build ( )
218
- . unwrap ( ) ;
209
+ . build ( ) ?;
219
210
220
211
let only_replica_table_configs = DynamoDbTablesEncryptionConfig :: builder ( )
221
212
. table_encryption_configs ( HashMap :: from ( [ (
222
213
ddb_table_name. to_string ( ) ,
223
214
only_replica_table_config,
224
215
) ] ) )
225
- . build ( )
226
- . unwrap ( ) ;
216
+ . build ( ) ?;
227
217
228
218
let only_replica_dynamo_config = aws_sdk_dynamodb:: config:: Builder :: from ( & sdk_config)
229
219
. interceptor ( DbEsdkInterceptor :: new ( only_replica_table_configs) )
@@ -245,13 +235,13 @@ pub async fn put_item_get_item() {
245
235
. set_key ( Some ( key_to_get) )
246
236
. consistent_read ( true )
247
237
. send ( )
248
- . await
249
- . unwrap ( ) ;
238
+ . await ?;
250
239
251
240
assert_eq ! (
252
241
resp. item. unwrap( ) [ "sensitive_data" ] ,
253
242
AttributeValue :: S ( "encrypt and sign me!" . to_string( ) )
254
243
) ;
255
244
256
245
println ! ( "client_supplier_example successful." ) ;
246
+ Ok ( ( ) )
257
247
}
0 commit comments