Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use aws_db_esdk::DynamoDbTablesEncryptionConfig;
use aws_sdk_dynamodb::types::AttributeValue;
use std::collections::HashMap;

const INSPECTION_DATE: &str = "2023-06-13";

/*
This example demonstrates how to use Beacons Styles on Standard Beacons on encrypted attributes,
put an item with the beacon, and query against that beacon.
Expand Down Expand Up @@ -210,7 +212,7 @@ pub async fn put_and_query_with_beacon(branch_key_id: &str) -> Result<(), crate:
("work_id".to_string(), AttributeValue::S(work_id1.clone())),
(
"inspection_date".to_string(),
AttributeValue::S("2023-06-13".to_string()),
AttributeValue::S(INSPECTION_DATE.to_string()),
),
("dessert".to_string(), AttributeValue::S("cake".to_string())),
("fruit".to_string(), AttributeValue::S("banana".to_string())),
Expand Down Expand Up @@ -241,7 +243,7 @@ pub async fn put_and_query_with_beacon(branch_key_id: &str) -> Result<(), crate:
("work_id".to_string(), AttributeValue::S(work_id2.clone())),
(
"inspection_date".to_string(),
AttributeValue::S("2023-06-13".to_string()),
AttributeValue::S(INSPECTION_DATE.to_string()),
),
(
"dessert".to_string(),
Expand Down Expand Up @@ -298,14 +300,14 @@ pub async fn put_and_query_with_beacon(branch_key_id: &str) -> Result<(), crate:
.delete_item()
.table_name(ddb_table_name)
.key("work_id", AttributeValue::S(work_id1))
.key("inspection_date", AttributeValue::S("2023-06-13".to_string()))
.key("inspection_date", AttributeValue::S(INSPECTION_DATE.to_string()))
.send()
.await;
let _ = plain_ddb
.delete_item()
.table_name(ddb_table_name)
.key("work_id", AttributeValue::S(work_id2))
.key("inspection_date", AttributeValue::S("2023-06-13".to_string()))
.key("inspection_date", AttributeValue::S(INSPECTION_DATE.to_string()))
.send()
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.swing.text.html.Option;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
Expand Down Expand Up @@ -75,6 +74,8 @@

public class BeaconStylesSearchableEncryptionExample {

private static final String INSPECTION_DATE = "2023-06-13";

public static void PutItemQueryItemWithBeaconStyles(
String ddbTableName,
String branchKeyId,
Expand Down Expand Up @@ -285,7 +286,7 @@ public static void PutItemQueryItemWithBeaconStyles(
item1.put("work_id", AttributeValue.builder().s(workId1).build());
item1.put(
"inspection_date",
AttributeValue.builder().s("2023-06-13").build()
AttributeValue.builder().s(INSPECTION_DATE).build()
);
item1.put("dessert", AttributeValue.builder().s("cake").build());
item1.put("fruit", AttributeValue.builder().s("banana").build());
Expand All @@ -306,7 +307,7 @@ public static void PutItemQueryItemWithBeaconStyles(
item2.put("work_id", AttributeValue.builder().s(workId2).build());
item2.put(
"inspection_date",
AttributeValue.builder().s("2023-06-13").build()
AttributeValue.builder().s(INSPECTION_DATE).build()
);
item2.put("fruit", AttributeValue.builder().s("orange").build());
item2.put("dessert", AttributeValue.builder().s("orange").build());
Expand Down Expand Up @@ -480,25 +481,28 @@ public static void PutItemQueryItemWithBeaconStyles(
assert scanResponse.items().get(0).equals(item1);
} finally {
// Clean up: delete both items using a plain DDB client
final DynamoDbClient plainDdb = DynamoDbClient.create();
HashMap<String, AttributeValue> key1 = new HashMap<>();
key1.put("work_id", AttributeValue.builder().s(workId1).build());
key1.put(
"inspection_date",
AttributeValue.builder().s("2023-06-13").build()
);
plainDdb.deleteItem(
DeleteItemRequest.builder().tableName(ddbTableName).key(key1).build()
);
HashMap<String, AttributeValue> key2 = new HashMap<>();
key2.put("work_id", AttributeValue.builder().s(workId2).build());
key2.put(
"inspection_date",
AttributeValue.builder().s("2023-06-13").build()
);
plainDdb.deleteItem(
DeleteItemRequest.builder().tableName(ddbTableName).key(key2).build()
);
try (DynamoDbClient plainDdb = DynamoDbClient.create()) {
HashMap<String, AttributeValue> key1 = new HashMap<>();
key1.put("work_id", AttributeValue.builder().s(workId1).build());
key1.put(
"inspection_date",
AttributeValue.builder().s(INSPECTION_DATE).build()
);
plainDdb.deleteItem(
DeleteItemRequest.builder().tableName(ddbTableName).key(key1).build()
);
HashMap<String, AttributeValue> key2 = new HashMap<>();
key2.put("work_id", AttributeValue.builder().s(workId2).build());
key2.put(
"inspection_date",
AttributeValue.builder().s(INSPECTION_DATE).build()
);
plainDdb.deleteItem(
DeleteItemRequest.builder().tableName(ddbTableName).key(key2).build()
);
} catch (Exception e) {
System.err.println("Cleanup failed: " + e.getMessage());
}
}
}

Expand Down
Loading