Skip to content

Commit ce4f1e9

Browse files
author
Lucas McDonald
committed
m
1 parent 683a9dc commit ce4f1e9

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Initialization code for AWS DBESDK for DynamoDB."""
44

5-
# Initialize generated Dafny, then initialize externs
6-
# Disable sorting imports; this order initializes code in the required order
7-
# (generated Dafny, then externs)
5+
# Disable sorting imports; this order initializes code in the required order: generated Dafny, then externs.
86
# ruff: noqa: I001, F401
97
from .internaldafny.generated import module_
108
from .internaldafny import extern
@@ -15,9 +13,10 @@
1513
boto3 deserializes strings to Decimals according to its DYNAMODB_CONTEXT:
1614
https://github.com/boto/boto3/blob/develop/boto3/dynamodb/types.py#L37-L42
1715
18-
boto3 is configured to raise an exception if the deserialization is "Rounded": (`traps: [.. Rounded]`)
19-
https://docs.python.org/3/library/decimal.html#decimal.Rounded
20-
"Rounded" means some digits were discarded.
16+
From the link above, boto3 is configured to raise an exception
17+
if the deserialization is "Rounded": (`traps: [.. Rounded]`).
18+
Documentation: https://docs.python.org/3/library/decimal.html#decimal.Rounded
19+
From the link above, "Rounded" means some digits were discarded.
2120
However, those digits may have been 0, and no information is lost.
2221
2322
boto3 is also configured to raise an exception if the deserialization is "Inexact":
@@ -36,7 +35,11 @@
3635
import boto3.dynamodb.types
3736

3837
old_context = boto3.dynamodb.types.DYNAMODB_CONTEXT
39-
old_traps = old_context.__getattribute__("traps")
38+
try:
39+
old_traps = old_context.__getattribute__("traps")
40+
except AttributeError:
41+
raise AttributeError("boto3.dynamodb.types.DYNAMODB_CONTEXT must have a 'traps' attribute to use DBESDK for DynamoDB.")
42+
4043
# traps structure: {k (trap class) : v (True if trap should raise Exception; False otherwise)}
4144
old_traps[Rounded] = False
4245
boto3.dynamodb.types.DYNAMODB_CONTEXT.__setattr__("traps", old_traps)

Examples/runtimes/python/DynamoDBEncryption/src/searchable_encryption/complex_example/client/query_requests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ def run_query_3(ddb_client, table_name):
142142
# Check known values in the response
143143
found_known_value_item = False
144144
for item in response["Items"]:
145-
if item["partition_key"] == "reservation1":
146-
found_known_value_item = True
147145
if item["partition_key"]["S"] == "reservation1":
146+
found_known_value_item = True
148147
assert item["Subject"]["S"] == "Scan beacons"
149148
assert item["Location"]["M"]["Building"]["S"] == "SEA33"
150149
assert {"S": "[email protected]"} in item["Attendees"]["L"]

TestVectors/runtimes/python/src/aws_dbesdk_dynamodb_test_vectors/internaldafny/extern/CreateInterceptedDDBResource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def CreateInterceptedDDBClient(dafny_encryption_config):
151151
table_config_names = list(native_encryption_config.table_encryption_configs.keys())
152152
if len(table_config_names) > 1:
153153
raise ValueError("TODO more than 1 table; need EncryptedTablesManager")
154-
# table = boto3.resource('dynamodb').Table(table_config_names[0])
154+
# For TestVectors, use local DynamoDB endpoint
155155
resource = boto3.resource('dynamodb', endpoint_url="http://localhost:8000")
156156
encrypted_resource = EncryptedResource(resource = resource, encryption_config = native_encryption_config)
157157
wrapped_encrypted_resource = DynamoDBClientWrapperForDynamoDBResource(resource = encrypted_resource, client = boto3_client)

TestVectors/runtimes/python/src/aws_dbesdk_dynamodb_test_vectors/internaldafny/extern/CreateInterceptedDDBTable.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ def CreateInterceptedDDBClient(dafny_encryption_config):
200200
boto3_client = WaitingLocalDynamoClient()
201201
table_config_names = list(native_encryption_config.table_encryption_configs.keys())
202202
if len(table_config_names) > 1:
203-
# If needed, this could be supported by setting up an EncryptedTablesManager
203+
# If needed, >1 table could be supported by setting up an EncryptedTablesManager
204204
raise ValueError(">1 table not supported")
205+
# For TestVectors, use local DynamoDB endpoint
205206
table = boto3.resource('dynamodb', endpoint_url="http://localhost:8000").Table(table_config_names[0])
206207
encrypted_table = EncryptedTable(table = table, encryption_config = native_encryption_config)
207208
wrapped_encrypted_table = DynamoDBClientWrapperForDynamoDBTable(table = encrypted_table, client = boto3_client)

0 commit comments

Comments
 (0)