Skip to content

Commit 2b01af7

Browse files
author
Lucas McDonald
committed
m
1 parent 9ac89a1 commit 2b01af7

File tree

100 files changed

+1719
-4219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1719
-4219
lines changed

DynamoDbEncryption/runtimes/python/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ ignore=[
9090
# Ignore opinionated docstring linting errors for internal modules
9191
"D205", "D400", "D401", "D403", "D404", "D415",
9292
]
93+
"test/*" = [
94+
# Ignore all "public"- and docstring-related linting errors for test modules
95+
"D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107",
96+
# Ignore opinionated docstring linting errors for test modules
97+
"D205", "D400", "D401", "D403", "D404", "D415",
98+
]
9399

94100
[tool.black]
95101
# Don't bother linting Dafny-generated code; don't re-lint Smithy-generated code

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted/client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,36 +400,42 @@ def _client_operation_logic(
400400
dict: The transformed response from DynamoDB
401401
402402
"""
403-
# Transform input from Python dictionary JSON to DynamoDB JSON if required
403+
# If _expect_standard_dictionaries is true, input items are expected to be standard dictionaries,
404+
# and need to be converted to DDB-JSON before encryption.
404405
sdk_input = deepcopy(operation_input)
405406
if self._expect_standard_dictionaries:
406407
if "TableName" in sdk_input:
407408
self._resource_to_client_shape_converter.table_name = sdk_input["TableName"]
408409
sdk_input = input_item_to_ddb_transform_method(sdk_input)
409410

410-
# Apply encryption transformation to the user-supplied input
411+
# Apply DBESDK transformation to the input
411412
transformed_request = input_transform_method(input_transform_shape(sdk_input=sdk_input)).transformed_input
412413

414+
# If _expect_standard_dictionaries is true, the boto3 client expects items to be standard dictionaries,
415+
# and needs to convert the DDB-JSON to a standard dictionary before passing the request to the boto3 client.
413416
if self._expect_standard_dictionaries:
414417
transformed_request = input_item_to_dict_transform_method(transformed_request)
415418

416-
# Call boto3 client method with transformed input and receive raw boto3 output
417419
sdk_response = client_method(**transformed_request)
418420

421+
# If _expect_standard_dictionaries is true, the boto3 client returns items as standard dictionaries,
422+
# and needs to convert the standard dictionary to DDB-JSON before passing the response to the DBESDK.
419423
if self._expect_standard_dictionaries:
420424
sdk_response = output_item_to_ddb_transform_method(sdk_response)
421425

422-
# Apply encryption transformation to the boto3 output
426+
# Apply DBESDK transformation to the boto3 output
423427
dbesdk_response = output_transform_method(
424428
output_transform_shape(
425429
original_input=sdk_input,
426430
sdk_output=sdk_response,
427431
)
428432
).transformed_output
429433

430-
# Copy any missing fields from the SDK output to the response
434+
# Copy any missing fields from the SDK output to the response (e.g. ConsumedCapacity)
431435
dbesdk_response = self._copy_sdk_response_to_dbesdk_response(sdk_response, dbesdk_response)
432436

437+
# If _expect_standard_dictionaries is true, output items are expected to be standard dictionaries,
438+
# and need to be converted from DDB-JSON to a standard dictionary before returning the response.
433439
if self._expect_standard_dictionaries:
434440
dbesdk_response = output_item_to_dict_transform_method(dbesdk_response)
435441

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted/table.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,39 +256,40 @@ def _table_operation_logic(
256256
dict: The transformed response from DynamoDB
257257
258258
"""
259-
# Table inputs are formatted as Python dictionary JSON, but encryption transformers expect DynamoDB JSON.
260-
# `input_resource_to_client_shape_transform_method` formats the supplied Python dictionary as DynamoDB JSON.
259+
# EncryptedTable inputs are formatted as standard dictionaries, but DBESDK transformations expect DynamoDB JSON.
260+
# Convert from standard dictionaries to DynamoDB JSON.
261261
input_transform_input = input_resource_to_client_shape_transform_method(operation_input)
262262

263-
# Apply encryption transformation to the user-supplied input
263+
# Apply DBESDK transformation to the input
264264
input_transform_output = input_encryption_transform_method(
265265
input_encryption_transform_shape(sdk_input=input_transform_input)
266266
).transformed_input
267267

268268
# The encryption transformation result is formatted in DynamoDB JSON,
269-
# but the underlying boto3 table expects Python dictionary JSON.
270-
# `input_client_to_resource_shape_transform_method` formats the transformation as Python dictionary JSON.
269+
# but the underlying boto3 table expects standard dictionaries.
270+
# Convert from DynamoDB JSON to standard dictionaries.
271271
sdk_input = input_client_to_resource_shape_transform_method(input_transform_output)
272272

273-
# Call boto3 Table method with Python-dictionary-JSON-formatted, encryption-transformed input,
274-
# and receive Python-dictionary-JSON-formatted boto3 output.
275273
sdk_output = table_method(**sdk_input)
276274

277-
# Format Python dictionary JSON-formatted SDK output as DynamoDB JSON for encryption transformer
275+
# Table outputs are formatted as standard dictionaries, but DBESDK transformations expect DynamoDB JSON.
276+
# Convert from standard dictionaries to DynamoDB JSON.
278277
output_transform_input = output_resource_to_client_shape_transform_method(sdk_output)
279278

280-
# Apply encryption transformer to boto3 output
279+
# Apply DBESDK transformation to boto3 output
281280
output_transform_output = output_encryption_transform_method(
282281
output_encryption_transform_shape(
283282
original_input=input_transform_input,
284283
sdk_output=output_transform_input,
285284
)
286285
).transformed_output
287286

288-
# Format DynamoDB JSON-formatted encryption transformation result as Python dictionary JSON
287+
# EncryptedTable outputs are formatted as standard dictionaries,
288+
# but DBESDK transformations provide DynamoDB JSON.
289+
# Convert from DynamoDB JSON to standard dictionaries.
289290
dbesdk_response = output_client_to_resource_shape_transform_method(output_transform_output)
290-
# Copy any missing fields from the SDK output to the response
291-
# (e.g. `ConsumedCapacity`)
291+
292+
# Copy any missing fields from the SDK output to the response (e.g. `ConsumedCapacity`)
292293
dbesdk_response = self._copy_sdk_response_to_dbesdk_response(sdk_output, dbesdk_response)
293294

294295
return dbesdk_response

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/internaldafny/extern/InternalLegacyOverride.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,44 @@
1010
try:
1111
from dynamodb_encryption_sdk.encrypted.client import EncryptedClient
1212
from dynamodb_encryption_sdk.structures import EncryptionContext
13+
1314
_HAS_LEGACY_DDBEC = True
1415
except ImportError:
1516
_HAS_LEGACY_DDBEC = False
1617

18+
1719
class InternalLegacyOverride(aws_dbesdk_dynamodb.internaldafny.generated.InternalLegacyOverride.InternalLegacyOverride):
1820
@staticmethod
1921
def Build(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncryptorConfig):
2022
if config.legacyOverride.is_None:
2123
return InternalLegacyOverride.CreateBuildSuccess(InternalLegacyOverride.CreateInternalLegacyOverrideNone())
22-
24+
2325
legacy_override = config.legacyOverride.value
2426

25-
maybe_encryptor = aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb.dafny_to_smithy.aws_cryptography_dbencryptionsdk_dynamodb_LegacyDynamoDbEncryptorReference(legacy_override.encryptor)
27+
maybe_encryptor = aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb.dafny_to_smithy.aws_cryptography_dbencryptionsdk_dynamodb_LegacyDynamoDbEncryptorReference(
28+
legacy_override.encryptor
29+
)
2630

2731
# Precondition: The encryptor MUST be a DynamoDBEncryptor
2832
if not _HAS_LEGACY_DDBEC:
29-
return InternalLegacyOverride.CreateBuildFailure(InternalLegacyOverride.CreateError("Could not find aws-dynamodb-encryption-python installation"))
33+
return InternalLegacyOverride.CreateBuildFailure(
34+
InternalLegacyOverride.CreateError("Could not find aws-dynamodb-encryption-python installation")
35+
)
3036
if not isinstance(maybe_encryptor, EncryptedClient):
31-
return InternalLegacyOverride.CreateBuildFailure(InternalLegacyOverride.CreateError("Legacy encryptor is not supported"))
37+
return InternalLegacyOverride.CreateBuildFailure(
38+
InternalLegacyOverride.CreateError("Legacy encryptor is not supported")
39+
)
3240

3341
# Preconditions: MUST be able to create valid encryption context
3442
maybe_encryption_context = InternalLegacyOverride.legacyEncryptionContext(config)
3543
if maybe_encryption_context.is_Failure:
3644
return InternalLegacyOverride.CreateBuildFailure(maybe_encryption_context.error())
37-
45+
3846
# Precondition: All actions MUST be supported types
3947
maybe_actions = InternalLegacyOverride.legacyActions(legacy_override.attributeActionsOnEncrypt)
4048
if maybe_actions.is_Failure:
4149
return InternalLegacyOverride.CreateBuildFailure(maybe_actions.error())
42-
50+
4351
def legacyEncryptionContext(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncryptorConfig):
4452
try:
4553
encryption_context_kwargs = {
@@ -55,18 +63,15 @@ def legacyEncryptionContext(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncr
5563

5664
@staticmethod
5765
def EncryptItem(input):
58-
return Wrappers.Result_Failure(
59-
"TODO-legacy-Encryptitem"
60-
)
61-
66+
return Wrappers.Result_Failure("TODO-legacy-Encryptitem")
67+
6268
@staticmethod
6369
def DecryptItem(input):
64-
return Wrappers.Result_Failure(
65-
"TODO-legacy-Decryptitem"
66-
)
67-
70+
return Wrappers.Result_Failure("TODO-legacy-Decryptitem")
71+
6872
@staticmethod
6973
def IsLegacyinput(input):
7074
return False
71-
75+
76+
7277
aws_dbesdk_dynamodb.internaldafny.generated.InternalLegacyOverride.InternalLegacyOverride = InternalLegacyOverride
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from . import (
22
InternalLegacyOverride,
3-
)
3+
)

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/smithygenerated/aws_cryptography_dbencryptionsdk_dynamodb/aws_sdk_to_dafny.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def com_amazonaws_dynamodb_AttributeValue(native_input):
2525
"".join(
2626
[
2727
chr(int.from_bytes(pair, "big"))
28-
for pair in zip(
29-
*[iter(native_input["S"].encode("utf-16-be"))] * 2
30-
)
28+
for pair in zip(*[iter(native_input["S"].encode("utf-16-be"))] * 2)
3129
]
3230
)
3331
)
@@ -38,9 +36,7 @@ def com_amazonaws_dynamodb_AttributeValue(native_input):
3836
"".join(
3937
[
4038
chr(int.from_bytes(pair, "big"))
41-
for pair in zip(
42-
*[iter(native_input["N"].encode("utf-16-be"))] * 2
43-
)
39+
for pair in zip(*[iter(native_input["N"].encode("utf-16-be"))] * 2)
4440
]
4541
)
4642
)
@@ -55,9 +51,7 @@ def com_amazonaws_dynamodb_AttributeValue(native_input):
5551
"".join(
5652
[
5753
chr(int.from_bytes(pair, "big"))
58-
for pair in zip(
59-
*[iter(list_element.encode("utf-16-be"))] * 2
60-
)
54+
for pair in zip(*[iter(list_element.encode("utf-16-be"))] * 2)
6155
]
6256
)
6357
)
@@ -73,9 +67,7 @@ def com_amazonaws_dynamodb_AttributeValue(native_input):
7367
"".join(
7468
[
7569
chr(int.from_bytes(pair, "big"))
76-
for pair in zip(
77-
*[iter(list_element.encode("utf-16-be"))] * 2
78-
)
70+
for pair in zip(*[iter(list_element.encode("utf-16-be"))] * 2)
7971
]
8072
)
8173
)
@@ -84,19 +76,14 @@ def com_amazonaws_dynamodb_AttributeValue(native_input):
8476
)
8577
)
8678
elif "BS" in native_input.keys():
87-
AttributeValue_union_value = AttributeValue_BS(
88-
Seq([Seq(list_element) for list_element in native_input["BS"]])
89-
)
79+
AttributeValue_union_value = AttributeValue_BS(Seq([Seq(list_element) for list_element in native_input["BS"]]))
9080
elif "M" in native_input.keys():
9181
AttributeValue_union_value = AttributeValue_M(
9282
Map(
9383
{
9484
Seq(
9585
"".join(
96-
[
97-
chr(int.from_bytes(pair, "big"))
98-
for pair in zip(*[iter(key.encode("utf-16-be"))] * 2)
99-
]
86+
[chr(int.from_bytes(pair, "big")) for pair in zip(*[iter(key.encode("utf-16-be"))] * 2)]
10087
)
10188
): aws_cryptography_internal_dynamodb.smithygenerated.com_amazonaws_dynamodb.aws_sdk_to_dafny.com_amazonaws_dynamodb_AttributeValue(
10289
value
@@ -121,8 +108,6 @@ def com_amazonaws_dynamodb_AttributeValue(native_input):
121108
elif "BOOL" in native_input.keys():
122109
AttributeValue_union_value = AttributeValue_BOOL(native_input["BOOL"])
123110
else:
124-
raise ValueError(
125-
"No recognized union value in union type: " + str(native_input)
126-
)
111+
raise ValueError("No recognized union value in union type: " + str(native_input))
127112

128113
return AttributeValue_union_value

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/smithygenerated/aws_cryptography_dbencryptionsdk_dynamodb/client.py

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ def _execute_operation(
107107
operation_name: str,
108108
) -> Output:
109109
try:
110-
return self._handle_execution(
111-
input, plugins, serialize, deserialize, config, operation_name
112-
)
110+
return self._handle_execution(input, plugins, serialize, deserialize, config, operation_name)
113111
except Exception as e:
114112
# Make sure every exception that we throw is an instance of ServiceError so
115113
# customers can reliably catch everything we throw.
@@ -173,9 +171,7 @@ def _handle_execution(
173171
interceptor.read_before_serialization(context)
174172

175173
# Step 4: Serialize the request
176-
context_with_transport_request = cast(
177-
InterceptorContext[Input, None, DafnyRequest, None], context
178-
)
174+
context_with_transport_request = cast(InterceptorContext[Input, None, DafnyRequest, None], context)
179175
context_with_transport_request._transport_request = serialize(
180176
context_with_transport_request.request, config
181177
)
@@ -186,8 +182,8 @@ def _handle_execution(
186182

187183
# Step 6: Invoke modify_before_retry_loop
188184
for interceptor in interceptors:
189-
context_with_transport_request._transport_request = (
190-
interceptor.modify_before_retry_loop(context_with_transport_request)
185+
context_with_transport_request._transport_request = interceptor.modify_before_retry_loop(
186+
context_with_transport_request
191187
)
192188

193189
# Step 7: Acquire the retry token.
@@ -237,9 +233,7 @@ def _handle_execution(
237233
# The response will be set either with the modeled output or an exception. The
238234
# transport_request and transport_response may be set or None.
239235
execution_context = cast(
240-
InterceptorContext[
241-
Input, Output, DafnyRequest | None, DafnyResponse | None
242-
],
236+
InterceptorContext[Input, Output, DafnyRequest | None, DafnyResponse | None],
243237
context,
244238
)
245239
return self._finalize_execution(interceptors, execution_context)
@@ -261,14 +255,10 @@ def _handle_attempt(
261255
if config.dafnyImplInterface.impl is None:
262256
raise Exception("No impl found on the operation config.")
263257

264-
context_with_response = cast(
265-
InterceptorContext[Input, None, DafnyRequest, DafnyResponse], context
266-
)
258+
context_with_response = cast(InterceptorContext[Input, None, DafnyRequest, DafnyResponse], context)
267259

268-
context_with_response._transport_response = (
269-
config.dafnyImplInterface.handle_request(
270-
input=context_with_response.transport_request
271-
)
260+
context_with_response._transport_response = config.dafnyImplInterface.handle_request(
261+
input=context_with_response.transport_request
272262
)
273263

274264
# Step 7n: Invoke read_after_transmit
@@ -277,8 +267,8 @@ def _handle_attempt(
277267

278268
# Step 7o: Invoke modify_before_deserialization
279269
for interceptor in interceptors:
280-
context_with_response._transport_response = (
281-
interceptor.modify_before_deserialization(context_with_response)
270+
context_with_response._transport_response = interceptor.modify_before_deserialization(
271+
context_with_response
282272
)
283273

284274
# Step 7p: Invoke read_before_deserialization
@@ -290,9 +280,7 @@ def _handle_attempt(
290280
InterceptorContext[Input, Output, DafnyRequest, DafnyResponse],
291281
context_with_response,
292282
)
293-
context_with_output._response = deserialize(
294-
context_with_output._transport_response, config
295-
)
283+
context_with_output._response = deserialize(context_with_output._transport_response, config)
296284

297285
# Step 7r: Invoke read_after_deserialization
298286
for interceptor in interceptors:
@@ -318,9 +306,7 @@ def _finalize_attempt(
318306
# Step 7s: Invoke modify_before_attempt_completion
319307
try:
320308
for interceptor in interceptors:
321-
context._response = interceptor.modify_before_attempt_completion(
322-
context
323-
)
309+
context._response = interceptor.modify_before_attempt_completion(context)
324310
except Exception as e:
325311
context._response = e
326312

@@ -336,9 +322,7 @@ def _finalize_attempt(
336322
def _finalize_execution(
337323
self,
338324
interceptors: list[Interceptor[Input, Output, DafnyRequest, DafnyResponse]],
339-
context: InterceptorContext[
340-
Input, Output, DafnyRequest | None, DafnyResponse | None
341-
],
325+
context: InterceptorContext[Input, Output, DafnyRequest | None, DafnyResponse | None],
342326
) -> Output:
343327
try:
344328
# Step 9: Invoke modify_before_completion

0 commit comments

Comments
 (0)