aws-db-esdk 1.2.4

aws-db-esdk is a library for implementing client side encryption with DynamoDB.
Documentation
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use aws_sdk_dynamodb::types::AttributeValue;
use std::collections::HashMap;

/*
 * This file is used in an example to demonstrate complex queries
 * you can perform using beacons.
 * The example data used is for demonstrative purposes only,
 * and might not meet the distribution and correlation uniqueness
 * recommendations for beacons.
 * See our documentation for whether beacons are
 * right for your particular data set:
 * https://docs.aws.amazon.com/database-encryption-sdk/latest/devguide/searchable-encryption.html#are-beacons-right-for-me
 *
 * This class implements PutItemAsync calls to populate a DDB table with items from our workshop.
 * By providing a DynamoDbClient that is configured to use searchable encryption,
 *   this class will encrypt the data client side and add beacon attributes to the items.
 * This only implements a single item of each of the 6 record types from Demo.md. Adding the remaining
 *   items would extend the test and example coverage.
 */

pub async fn put_all_items_to_table(
    ddb_table_name: &str,
    ddb: &mut aws_sdk_dynamodb::Client,
) -> Result<(), crate::BoxError> {
    put_all_meeting_items(ddb_table_name, ddb).await?;
    put_all_employee_items(ddb_table_name, ddb).await?;
    put_all_project_items(ddb_table_name, ddb).await?;
    put_all_reservation_items(ddb_table_name, ddb).await?;
    put_all_ticket_items(ddb_table_name, ddb).await?;
    put_all_timecard_items(ddb_table_name, ddb).await?;
    Ok(())
}

fn ss(s: &str) -> AttributeValue {
    AttributeValue::S(s.to_string())
}
fn entry(name: &str, value: &str) -> (String, AttributeValue) {
    (name.to_string(), ss(value))
}

async fn put_item(
    ddb_table_name: &str,
    ddb: &mut aws_sdk_dynamodb::Client,
    item: HashMap<String, AttributeValue>,
) -> Result<(), crate::BoxError> {
    ddb.put_item()
        .table_name(ddb_table_name)
        .set_item(Some(item))
        .send()
        .await?;
    Ok(())
}

// emeeting.json
async fn put_all_meeting_items(
    ddb_table_name: &str,
    ddb: &mut aws_sdk_dynamodb::Client,
) -> Result<(), crate::BoxError> {
    let meeting1_attendee_list = vec![ss("able@gmail.com"), ss("zorro@gmail.com")];
    let meeting1_location = HashMap::from([entry("Floor", "12"), entry("Room", "403")]);
    let meeting1 = HashMap::from([
        entry("partition_key", "meeting1-rust"),
        entry("EmployeeID", "emp_001"),
        entry("EmployeeEmail", "able@gmail.com"),
        entry("MeetingStart", "2022-07-04T13:00"),
        entry("Duration", "30"),
        entry("Subject", "Scan Beacons"),
        ("Location".to_string(), AttributeValue::M(meeting1_location)),
        (
            "Attendees".to_string(),
            AttributeValue::L(meeting1_attendee_list),
        ),
    ]);
    put_item(ddb_table_name, ddb, meeting1).await?;

    let meeting2_attendee_list = vec![ss("barney@gmail.com"), ss("zorro@gmail.com")];
    let meeting2_location = HashMap::from([entry("Floor", "12"), entry("Room", "403")]);
    let meeting2 = HashMap::from([
        entry("partition_key", "meeting2-rust"),
        entry("EmployeeID", "emp_002"),
        entry("EmployeeEmail", "barney@gmail.com"),
        entry("MeetingStart", "2022-07-04T13:00"),
        entry("Duration", "30"),
        entry("Subject", "Scan Beacons"),
        ("Location".to_string(), AttributeValue::M(meeting2_location)),
        (
            "Attendees".to_string(),
            AttributeValue::L(meeting2_attendee_list),
        ),
    ]);
    put_item(ddb_table_name, ddb, meeting2).await?;

    let meeting3_attendee_list = vec![ss("charlie@gmail.com"), ss("zorro@gmail.com")];
    let meeting3_location = HashMap::from([entry("Floor", "12"), entry("Room", "403")]);
    let meeting3 = HashMap::from([
        entry("partition_key", "meeting3-rust"),
        entry("EmployeeID", "emp_003"),
        entry("EmployeeEmail", "charlie@gmail.com"),
        entry("MeetingStart", "2022-07-04T13:00"),
        entry("Duration", "30"),
        entry("Subject", "Scan Beacons"),
        ("Location".to_string(), AttributeValue::M(meeting3_location)),
        (
            "Attendees".to_string(),
            AttributeValue::L(meeting3_attendee_list),
        ),
    ]);
    put_item(ddb_table_name, ddb, meeting3).await?;

    let meeting4_attendee_list = vec![ss("david@gmail.com"), ss("zorro@gmail.com")];
    let meeting4_location = HashMap::from([entry("Floor", "12"), entry("Room", "403")]);
    let meeting4 = HashMap::from([
        entry("partition_key", "meeting4-rust"),
        entry("EmployeeID", "emp_004"),
        entry("EmployeeEmail", "david@gmail.com"),
        entry("MeetingStart", "2022-07-04T13:00"),
        entry("Duration", "30"),
        entry("Subject", "Scan Beacons"),
        ("Location".to_string(), AttributeValue::M(meeting4_location)),
        (
            "Attendees".to_string(),
            AttributeValue::L(meeting4_attendee_list),
        ),
    ]);
    put_item(ddb_table_name, ddb, meeting4).await?;

    let meeting5_attendee_list = vec![ss("barney@gmail.com"), ss("zorro@gmail.com")];
    let meeting5_location = HashMap::from([entry("Floor", "12"), entry("Room", "407")]);
    let meeting5 = HashMap::from([
        entry("partition_key", "meeting5-rust"),
        entry("EmployeeID", "emp_002"),
        entry("EmployeeEmail", "barney@gmail.com"),
        entry("MeetingStart", "2022-07-04T14:00"),
        entry("Duration", "30"),
        entry("Subject", "DB ESDK"),
        ("Location".to_string(), AttributeValue::M(meeting5_location)),
        (
            "Attendees".to_string(),
            AttributeValue::L(meeting5_attendee_list),
        ),
    ]);
    put_item(ddb_table_name, ddb, meeting5).await?;

    let meeting6_attendee_list = vec![ss("charlie@gmail.com"), ss("zorro@gmail.com")];
    let meeting6_location = HashMap::from([entry("Floor", "12"), entry("Room", "407")]);
    let meeting6 = HashMap::from([
        entry("partition_key", "meeting6-rust"),
        entry("EmployeeID", "emp_003"),
        entry("EmployeeEmail", "charlie@gmail.com"),
        entry("MeetingStart", "2022-07-04T14:00"),
        entry("Duration", "30"),
        entry("Subject", "DB ESDK"),
        ("Location".to_string(), AttributeValue::M(meeting6_location)),
        (
            "Attendees".to_string(),
            AttributeValue::L(meeting6_attendee_list),
        ),
    ]);
    put_item(ddb_table_name, ddb, meeting6).await?;
    Ok(())
}

// employee.json
async fn put_all_employee_items(
    ddb_table_name: &str,
    ddb: &mut aws_sdk_dynamodb::Client,
) -> Result<(), crate::BoxError> {
    let employee1_location = HashMap::from([
        entry("Building", "44"),
        entry("Floor", "12"),
        entry("Desk", "3"),
        entry("City", "Seattle"),
    ]);
    let employee1 = HashMap::from([
        entry("partition_key", "employee1-rust"),
        entry("EmployeeID", "emp_001"),
        entry("EmployeeEmail", "able@gmail.com"),
        entry("ManagerEmail", "zorro@gmail.com"),
        entry("EmployeeName", "Able Jones"),
        entry("EmployeeTitle", "SDE9"),
        (
            "Location".to_string(),
            AttributeValue::M(employee1_location),
        ),
    ]);
    put_item(ddb_table_name, ddb, employee1).await?;

    let employee2_location = HashMap::from([
        entry("Building", "44"),
        entry("Floor", "12"),
        entry("Desk", "4"),
        entry("City", "Seattle"),
    ]);
    let employee2 = HashMap::from([
        entry("partition_key", "employee2-rust"),
        entry("EmployeeID", "emp_002"),
        entry("EmployeeEmail", "barney@gmail.com"),
        entry("ManagerEmail", "zorro@gmail.com"),
        entry("EmployeeName", "Barney Jones"),
        entry("EmployeeTitle", "SDE8"),
        (
            "Location".to_string(),
            AttributeValue::M(employee2_location),
        ),
    ]);
    put_item(ddb_table_name, ddb, employee2).await?;

    let employee3_location = HashMap::from([
        entry("Building", "44"),
        entry("Floor", "4"),
        entry("Desk", "5"),
        entry("City", "Seattle"),
    ]);
    let employee3 = HashMap::from([
        entry("partition_key", "employee3-rust"),
        entry("EmployeeID", "emp_003"),
        entry("EmployeeEmail", "charlie@gmail.com"),
        entry("ManagerEmail", "zorro@gmail.com"),
        entry("EmployeeName", "Charlie Jones"),
        entry("EmployeeTitle", "SDE7"),
        (
            "Location".to_string(),
            AttributeValue::M(employee3_location),
        ),
    ]);
    put_item(ddb_table_name, ddb, employee3).await?;

    let employee4_location = HashMap::from([
        entry("Building", "22"),
        entry("Floor", "1"),
        entry("Desk", "3"),
        entry("City", "NYC"),
    ]);
    let employee4 = HashMap::from([
        entry("partition_key", "employee4-rust"),
        entry("EmployeeID", "emp_004"),
        entry("EmployeeEmail", "david@gmail.com"),
        entry("ManagerEmail", "zorro@gmail.com"),
        entry("EmployeeName", "David Jones"),
        entry("EmployeeTitle", "SDE6"),
        (
            "Location".to_string(),
            AttributeValue::M(employee4_location),
        ),
    ]);
    put_item(ddb_table_name, ddb, employee4).await?;
    Ok(())
}

// project.json
async fn put_all_project_items(
    ddb_table_name: &str,
    ddb: &mut aws_sdk_dynamodb::Client,
) -> Result<(), crate::BoxError> {
    let project1 = HashMap::from([
        entry("partition_key", "project1-rust"),
        entry("ProjectName", "project_001"),
        entry("ProjectStatus", "Pending"),
        entry("ProjectStart", "2022-11-01"),
        entry("Description", "Turbo Crypto"),
        entry("ProjectTarget", "2024-01-01"),
    ]);
    put_item(ddb_table_name, ddb, project1).await?;

    let project2 = HashMap::from([
        entry("partition_key", "project2-rust"),
        entry("ProjectName", "project_002"),
        entry("ProjectStatus", "Active"),
        entry("ProjectStart", "2022-07-04"),
        entry("Description", "Scan Beacons"),
        entry("ProjectTarget", "2024-01-01"),
    ]);
    put_item(ddb_table_name, ddb, project2).await?;

    let project3 = HashMap::from([
        entry("partition_key", "project3-rust"),
        entry("ProjectName", "project_003"),
        entry("ProjectStatus", "Active"),
        entry("ProjectStart", "2022-08-05"),
        entry("Description", "DB ESDK"),
        entry("ProjectTarget", "2023-02-27"),
    ]);
    put_item(ddb_table_name, ddb, project3).await?;

    let project4 = HashMap::from([
        entry("partition_key", "project4-rust"),
        entry("ProjectName", "project_004"),
        entry("ProjectStatus", "Done"),
        entry("ProjectStart", "2020-03-03"),
        entry("Description", "S3EC"),
        entry("ProjectTarget", "2021-09-05"),
    ]);
    put_item(ddb_table_name, ddb, project4).await?;
    Ok(())
}

// reservation.json
async fn put_all_reservation_items(
    ddb_table_name: &str,
    ddb: &mut aws_sdk_dynamodb::Client,
) -> Result<(), crate::BoxError> {
    let reservation1_attendee_list = vec![ss("able@gmail.com"), ss("barney@gmail.com")];
    let reservation1_location = HashMap::from([
        entry("Building", "SEA33"),
        entry("Floor", "12"),
        entry("Room", "403"),
    ]);
    let reservation1 = HashMap::from([
        entry("partition_key", "reservation1-rust"),
        entry("MeetingStart", "2022-07-04T13:00"),
        entry("OrganizerEmail", "able@gmail.com"),
        entry("Duration", "30"),
        entry("Subject", "Scan beacons"),
        (
            "Location".to_string(),
            AttributeValue::M(reservation1_location),
        ),
        (
            "Attendees".to_string(),
            AttributeValue::L(reservation1_attendee_list),
        ),
    ]);
    put_item(ddb_table_name, ddb, reservation1).await?;

    let reservation2_attendee_list = vec![ss("able@gmail.com"), ss("barney@gmail.com")];
    let reservation2_location = HashMap::from([
        entry("Building", "SEA33"),
        entry("Floor", "12"),
        entry("Room", "407"),
    ]);
    let reservation2 = HashMap::from([
        entry("partition_key", "reservation2-rust"),
        entry("MeetingStart", "2022-07-04T14:00"),
        entry("OrganizerEmail", "barney@gmail.com"),
        entry("Duration", "30"),
        entry("Subject", "DB ESDK"),
        (
            "Location".to_string(),
            AttributeValue::M(reservation2_location),
        ),
        (
            "Attendees".to_string(),
            AttributeValue::L(reservation2_attendee_list),
        ),
    ]);
    put_item(ddb_table_name, ddb, reservation2).await?;
    Ok(())
}

// ticket.json
async fn put_all_ticket_items(
    ddb_table_name: &str,
    ddb: &mut aws_sdk_dynamodb::Client,
) -> Result<(), crate::BoxError> {
    let ticket1 = HashMap::from([
        entry("partition_key", "ticket1-rust"),
        entry("TicketNumber", "ticket_001"),
        entry("TicketModTime", "2022-10-07T14:32:25"),
        entry("CreatorEmail", "zorro@gmail.com"),
        entry("AssigneeEmail", "able@gmail.com"),
        entry("Severity", "3"),
        entry("Subject", "Bad bug"),
        entry("Message", "This bug looks pretty bad"),
    ]);
    put_item(ddb_table_name, ddb, ticket1).await?;

    let ticket2 = HashMap::from([
        entry("partition_key", "ticket2-rust"),
        entry("TicketNumber", "ticket_001"),
        entry("TicketModTime", "2022-10-07T14:32:25"),
        entry("CreatorEmail", "able@gmail.com"),
        entry("AssigneeEmail", "charlie@gmail.com"),
        entry("Severity", "3"),
        entry("Subject", "Bad bug"),
        entry("Message", "Charlie should handle this"),
    ]);
    put_item(ddb_table_name, ddb, ticket2).await?;

    let ticket3 = HashMap::from([
        entry("partition_key", "ticket3-rust"),
        entry("TicketNumber", "ticket_002"),
        entry("TicketModTime", "2022-10-06T14:32:25"),
        entry("CreatorEmail", "zorro@gmail.com"),
        entry("AssigneeEmail", "charlie@gmail.com"),
        entry("Severity", "3"),
        entry("Subject", "Easy bug"),
        entry("Message", "This seems simple enough"),
    ]);
    put_item(ddb_table_name, ddb, ticket3).await?;

    let ticket4 = HashMap::from([
        entry("partition_key", "ticket4-rust"),
        entry("TicketNumber", "ticket_002"),
        entry("TicketModTime", "2022-10-08T14:32:25"),
        entry("CreatorEmail", "charlie@gmail.com"),
        entry("AssigneeEmail", "able@gmail.com"),
        entry("Severity", "3"),
        entry("Subject", "Easy bug"),
        entry("Message", "that's in able's code"),
    ]);
    put_item(ddb_table_name, ddb, ticket4).await?;
    Ok(())
}

// timecard.json
async fn put_all_timecard_items(
    ddb_table_name: &str,
    ddb: &mut aws_sdk_dynamodb::Client,
) -> Result<(), crate::BoxError> {
    let timecard1 = HashMap::from([
        entry("partition_key", "timecard1-rust"),
        entry("ProjectName", "project_002"),
        entry("TimeCardStart", "2022-09-12"),
        entry("EmployeeEmail", "able@gmail.com"),
        entry("Hours", "40"),
        entry("Role", "SDE3"),
    ]);
    put_item(ddb_table_name, ddb, timecard1).await?;

    let timecard2 = HashMap::from([
        entry("partition_key", "timecard2-rust"),
        entry("ProjectName", "project_002"),
        entry("TimeCardStart", "2022-09-12"),
        entry("EmployeeEmail", "barney@gmail.com"),
        entry("Hours", "20"),
        entry("Role", "PM"),
    ]);
    put_item(ddb_table_name, ddb, timecard2).await?;

    let timecard3 = HashMap::from([
        entry("partition_key", "timecard3-rust"),
        entry("ProjectName", "project_003"),
        entry("TimeCardStart", "2022-09-12"),
        entry("EmployeeEmail", "charlie@gmail.com"),
        entry("Hours", "40"),
        entry("Role", "SDE3"),
    ]);
    put_item(ddb_table_name, ddb, timecard3).await?;

    let timecard4 = HashMap::from([
        entry("partition_key", "timecard4-rust"),
        entry("ProjectName", "project_003"),
        entry("TimeCardStart", "2022-09-12"),
        entry("EmployeeEmail", "barney@gmail.com"),
        entry("Hours", "20"),
        entry("Role", "PM"),
    ]);
    put_item(ddb_table_name, ddb, timecard4).await?;
    Ok(())
}