Skip to content

Commit 93585ba

Browse files
committed
resolve TODO
1 parent 62b680c commit 93585ba

File tree

9 files changed

+63
-59
lines changed

9 files changed

+63
-59
lines changed

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def Build(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncryptorConfig):
6666
isinstance(legacy_override.encryptor, EncryptedClient)
6767
or isinstance(legacy_override.encryptor, EncryptedTable)
6868
or isinstance(legacy_override.encryptor, EncryptedResource)
69-
or isinstance(legacy_override.encryptor, EncryptedPaginator)
7069
):
7170
return InternalLegacyOverride.CreateBuildFailure(
7271
InternalLegacyOverride.CreateError("Legacy encryptor is not supported")
@@ -99,10 +98,12 @@ def legacyEncryptionContext(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncr
9998
"""Create the legacy encryption context from the config."""
10099
try:
101100
# Convert Dafny types to Python strings for the encryption context
102-
table_name = InternalLegacyOverride.ToNative(config.logicalTableName)
103-
partition_key_name = InternalLegacyOverride.ToNative(config.partitionKeyName)
101+
table_name = InternalLegacyOverride.DafnyStringToNativeString(config.logicalTableName)
102+
partition_key_name = InternalLegacyOverride.DafnyStringToNativeString(config.partitionKeyName)
104103
sort_key_name = (
105-
InternalLegacyOverride.ToNative(config.sortKeyName.value) if config.sortKeyName.is_Some else None
104+
InternalLegacyOverride.DafnyStringToNativeString(config.sortKeyName.value)
105+
if config.sortKeyName.is_Some
106+
else None
106107
)
107108

108109
# Create the legacy encryption context with the extracted values
@@ -128,7 +129,7 @@ def legacyActions(attribute_actions_on_encrypt):
128129
# Map the action from the config to legacy actions
129130
attribute_actions = {}
130131
for key, action in attribute_actions_on_encrypt.items:
131-
key_str = InternalLegacyOverride.ToNative(key)
132+
key_str = InternalLegacyOverride.DafnyStringToNativeString(key)
132133

133134
# Map the action type to the appropriate CryptoAction
134135
if action == CryptoAction_ENCRYPT__AND__SIGN():
@@ -151,11 +152,8 @@ def legacyActions(attribute_actions_on_encrypt):
151152
def EncryptItem(self, input: EncryptItemInput_EncryptItemInput):
152153
"""Encrypt an item using the legacy DynamoDB encryptor.
153154
154-
Args:
155-
input: EncryptItemInput containing the plaintext item to encrypt
156-
157-
Returns:
158-
Result containing the encrypted item or an error
155+
:param input: EncryptItemInput containing the plaintext item to encrypt
156+
:returns Result containing the encrypted item or an error
159157
"""
160158
try:
161159
# Precondition: Policy MUST allow the caller to encrypt.
@@ -190,11 +188,8 @@ def EncryptItem(self, input: EncryptItemInput_EncryptItemInput):
190188
def DecryptItem(self, input: DecryptItemInput_DecryptItemInput):
191189
"""Decrypt an item using the legacy DynamoDB encryptor.
192190
193-
Args:
194-
input: DecryptItemInput containing the encrypted item to decrypt
195-
196-
Returns:
197-
Result containing the decrypted item or an error
191+
:param input: DecryptItemInput containing the encrypted item to decrypt
192+
:returns Result containing the decrypted item or an error
198193
"""
199194
try:
200195
# Precondition: Policy MUST allow the caller to decrypt.
@@ -235,11 +230,8 @@ def IsLegacyInput(self, input: DecryptItemInput_DecryptItemInput):
235230
"""
236231
Determine if the input is from a legacy client.
237232
238-
Args:
239-
input: The decrypt item input to check
240-
241-
Returns:
242-
Boolean indicating if the input is from a legacy client
233+
:param input: The decrypt item input to check
234+
:returns Boolean indicating if the input is from a legacy client
243235
"""
244236
if not input.is_DecryptItemInput:
245237
return False
@@ -258,19 +250,19 @@ def IsLegacyInput(self, input: DecryptItemInput_DecryptItemInput):
258250
)
259251

260252
@staticmethod
261-
def ToNative(dafny_input):
253+
def DafnyStringToNativeString(dafny_input):
262254
return b"".join(ord(c).to_bytes(2, "big") for c in dafny_input).decode("utf-16-be")
263255

264256
@staticmethod
265-
def ToDafny(native_input):
257+
def NativeStringToDafnyString(native_input):
266258
return Seq(
267259
"".join([chr(int.from_bytes(pair, "big")) for pair in zip(*[iter(native_input.encode("utf-16-be"))] * 2)])
268260
)
269261

270262
@staticmethod
271263
def CreateError(message):
272264
"""Create an Error with the given message."""
273-
return Error_DynamoDbItemEncryptorException(InternalLegacyOverride.ToDafny(message))
265+
return Error_DynamoDbItemEncryptorException(InternalLegacyOverride.NativeStringToDafnyString(message))
274266

275267

276268
aws_dbesdk_dynamodb.internaldafny.generated.InternalLegacyOverride.InternalLegacyOverride = InternalLegacyOverride

Examples/runtimes/python/Migration/test/ddbec_to_awsdbe/awsdbe/client/test_migration_step_3.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from different migration stages.
99
"""
1010
import pytest
11+
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_transforms.errors import (
12+
DynamoDbItemEncryptor,
13+
)
1114

1215
from .....src.ddbec_to_awsdbe.awsdbe.client import (
1316
migration_step_1,
@@ -31,10 +34,9 @@ def test_migration_step_3_with_client():
3134
migration_step_0.migration_step_0_with_client(
3235
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
3336
)
34-
# TODO: Fix Exception Handling Correctly & Ensure Correct Exceptions were thrown
3537
# When: Execute Step 3 with sort_read_value=0
36-
# Then: throws Exception (i.e. cannot read values in old format)
37-
with pytest.raises(Exception):
38+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in old format)
39+
with pytest.raises(DynamoDbItemEncryptor):
3840
migration_step_3.migration_step_3_with_client(
3941
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
4042
)
@@ -44,8 +46,8 @@ def test_migration_step_3_with_client():
4446
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
4547
)
4648
# When: Execute Step 3 with sort_read_value=1
47-
# Then: throws Exception (i.e. cannot read values in old format)
48-
with pytest.raises(Exception):
49+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in old format)
50+
with pytest.raises(DynamoDbItemEncryptor):
4951
migration_step_3.migration_step_3_with_client(
5052
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
5153
)

Examples/runtimes/python/Migration/test/ddbec_to_awsdbe/awsdbe/paginator/test_migration_step_3.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from different migration stages.
99
"""
1010
import pytest
11+
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_transforms.errors import (
12+
DynamoDbItemEncryptor,
13+
)
1114

1215
from .....src.ddbec_to_awsdbe.awsdbe.paginator import (
1316
migration_step_1,
@@ -31,10 +34,9 @@ def test_migration_step_3_with_paginator():
3134
migration_step_0.migration_step_0_with_paginator(
3235
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
3336
)
34-
# TODO: Fix Exception Handling Correctly & Ensure Correct Exceptions were thrown
3537
# When: Execute Step 3 with sort_read_value=0
36-
# Then: throws Exception (i.e. cannot read values in old format)
37-
with pytest.raises(Exception):
38+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in old format)
39+
with pytest.raises(DynamoDbItemEncryptor):
3840
migration_step_3.migration_step_3_with_paginator(
3941
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
4042
)
@@ -44,8 +46,8 @@ def test_migration_step_3_with_paginator():
4446
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
4547
)
4648
# When: Execute Step 3 with sort_read_value=1
47-
# Then: throws Exception (i.e. cannot read values in old format)
48-
with pytest.raises(Exception):
49+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in old format)
50+
with pytest.raises(DynamoDbItemEncryptor):
4951
migration_step_3.migration_step_3_with_paginator(
5052
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
5153
)

Examples/runtimes/python/Migration/test/ddbec_to_awsdbe/awsdbe/resource/test_migration_step_3.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from different migration stages.
99
"""
1010
import pytest
11+
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_transforms.errors import (
12+
DynamoDbItemEncryptor,
13+
)
1114

1215
from .....src.ddbec_to_awsdbe.awsdbe.resource import (
1316
migration_step_1,
@@ -31,10 +34,9 @@ def test_migration_step_3_with_resource():
3134
migration_step_0.migration_step_0_with_resource(
3235
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
3336
)
34-
# TODO: Fix Exception Handling Correctly & Ensure Correct Exceptions were thrown
3537
# When: Execute Step 3 with sort_read_value=0
36-
# Then: throws Exception (i.e. cannot read values in old format)
37-
with pytest.raises(Exception):
38+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in old format)
39+
with pytest.raises(DynamoDbItemEncryptor):
3840
migration_step_3.migration_step_3_with_resource(
3941
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
4042
)
@@ -44,8 +46,8 @@ def test_migration_step_3_with_resource():
4446
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
4547
)
4648
# When: Execute Step 3 with sort_read_value=1
47-
# Then: throws Exception (i.e. cannot read values in old format)
48-
with pytest.raises(Exception):
49+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in old format)
50+
with pytest.raises(DynamoDbItemEncryptor):
4951
migration_step_3.migration_step_3_with_resource(
5052
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
5153
)

Examples/runtimes/python/Migration/test/ddbec_to_awsdbe/awsdbe/table/test_migration_step_3.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from different migration stages.
99
"""
1010
import pytest
11+
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_transforms.errors import (
12+
DynamoDbItemEncryptor,
13+
)
1114

1215
from .....src.ddbec_to_awsdbe.awsdbe.table import (
1316
migration_step_1,
@@ -31,10 +34,9 @@ def test_migration_step_3_with_table():
3134
migration_step_0.migration_step_0_with_table(
3235
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
3336
)
34-
# TODO: Fix Exception Handling Correctly & Ensure Correct Exceptions were thrown
3537
# When: Execute Step 3 with sort_read_value=0
36-
# Then: throws Exception (i.e. cannot read values in old format)
37-
with pytest.raises(Exception):
38+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in old format)
39+
with pytest.raises(DynamoDbItemEncryptor):
3840
migration_step_3.migration_step_3_with_table(
3941
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=0
4042
)
@@ -44,8 +46,8 @@ def test_migration_step_3_with_table():
4446
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
4547
)
4648
# When: Execute Step 3 with sort_read_value=1
47-
# Then: throws Exception (i.e. cannot read values in old format)
48-
with pytest.raises(Exception):
49+
# Then: throws DynamoDbItemEncryptor Exception (i.e. cannot read values in old format)
50+
with pytest.raises(DynamoDbItemEncryptor):
4951
migration_step_3.migration_step_3_with_table(
5052
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=1
5153
)

Examples/runtimes/python/Migration/test/ddbec_to_awsdbe/ddbec/client/test_migration_step_0.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
with data from different migration stages.
99
"""
1010
import pytest
11+
from dynamodb_encryption_sdk.exceptions import DecryptionError
1112

1213
from .....src.ddbec_to_awsdbe.awsdbe.client import (
1314
migration_step_1,
@@ -42,8 +43,8 @@ def test_migration_step_0_with_client():
4243
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
4344
)
4445
# When: Execute Step 0 with sort_read_value=2
45-
# Then: throws Exception (i.e. cannot read values in new format)
46-
with pytest.raises(Exception): # The exact exception may vary in Python implementation
46+
# Then: throws DecryptionError Exception (i.e. cannot read values in new format)
47+
with pytest.raises(DecryptionError): # The exact exception may vary in Python implementation
4748
migration_step_0.migration_step_0_with_client(
4849
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
4950
)
@@ -53,8 +54,8 @@ def test_migration_step_0_with_client():
5354
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
5455
)
5556
# When: Execute Step 0 with sort_read_value=3
56-
# Then: throws Exception (i.e. cannot read values in new format)
57-
with pytest.raises(Exception): # The exact exception may vary in Python implementation
57+
# Then: throws DecryptionError Exception (i.e. cannot read values in new format)
58+
with pytest.raises(DecryptionError): # The exact exception may vary in Python implementation
5859
migration_step_0.migration_step_0_with_client(
5960
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
6061
)

Examples/runtimes/python/Migration/test/ddbec_to_awsdbe/ddbec/paginator/test_migration_step_0.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
with data from different migration stages.
99
"""
1010
import pytest
11+
from dynamodb_encryption_sdk.exceptions import DecryptionError
1112

1213
from .....src.ddbec_to_awsdbe.awsdbe.paginator import (
1314
migration_step_1,
@@ -42,8 +43,8 @@ def test_migration_step_0_with_paginator():
4243
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
4344
)
4445
# When: Execute Step 0 with sort_read_value=2
45-
# Then: throws Exception (i.e. cannot read values in new format)
46-
with pytest.raises(Exception): # The exact exception may vary in Python implementation
46+
# Then: throws DecryptionError Exception (i.e. cannot read values in new format)
47+
with pytest.raises(DecryptionError): # The exact exception may vary in Python implementation
4748
migration_step_0.migration_step_0_with_paginator(
4849
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
4950
)
@@ -53,8 +54,8 @@ def test_migration_step_0_with_paginator():
5354
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
5455
)
5556
# When: Execute Step 0 with sort_read_value=3
56-
# Then: throws Exception (i.e. cannot read values in new format)
57-
with pytest.raises(Exception): # The exact exception may vary in Python implementation
57+
# Then: throws DecryptionError Exception (i.e. cannot read values in new format)
58+
with pytest.raises(DecryptionError): # The exact exception may vary in Python implementation
5859
migration_step_0.migration_step_0_with_paginator(
5960
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
6061
)

Examples/runtimes/python/Migration/test/ddbec_to_awsdbe/ddbec/resource/test_migration_step_0.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
with data from different migration stages.
99
"""
1010
import pytest
11+
from dynamodb_encryption_sdk.exceptions import DecryptionError
1112

1213
from .....src.ddbec_to_awsdbe.awsdbe.resource import (
1314
migration_step_1,
@@ -42,8 +43,8 @@ def test_migration_step_0_with_resource():
4243
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
4344
)
4445
# When: Execute Step 0 with sort_read_value=2
45-
# Then: throws Exception (i.e. cannot read values in new format)
46-
with pytest.raises(Exception): # The exact exception may vary in Python implementation
46+
# Then: throws DecryptionError Exception (i.e. cannot read values in new format)
47+
with pytest.raises(DecryptionError): # The exact exception may vary in Python implementation
4748
migration_step_0.migration_step_0_with_resource(
4849
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
4950
)
@@ -53,8 +54,8 @@ def test_migration_step_0_with_resource():
5354
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
5455
)
5556
# When: Execute Step 0 with sort_read_value=3
56-
# Then: throws Exception (i.e. cannot read values in new format)
57-
with pytest.raises(Exception): # The exact exception may vary in Python implementation
57+
# Then: throws DecryptionError Exception (i.e. cannot read values in new format)
58+
with pytest.raises(DecryptionError): # The exact exception may vary in Python implementation
5859
migration_step_0.migration_step_0_with_resource(
5960
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
6061
)

Examples/runtimes/python/Migration/test/ddbec_to_awsdbe/ddbec/table/test_migration_step_0.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
with data from different migration stages.
99
"""
1010
import pytest
11+
from dynamodb_encryption_sdk.exceptions import DecryptionError
1112

1213
from .....src.ddbec_to_awsdbe.awsdbe.table import (
1314
migration_step_1,
@@ -42,8 +43,8 @@ def test_migration_step_0_with_table():
4243
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
4344
)
4445
# When: Execute Step 0 with sort_read_value=2
45-
# Then: throws Exception (i.e. cannot read values in new format)
46-
with pytest.raises(Exception): # The exact exception may vary in Python implementation
46+
# Then: throws DecryptionError Exception (i.e. cannot read values in new format)
47+
with pytest.raises(DecryptionError): # The exact exception may vary in Python implementation
4748
migration_step_0.migration_step_0_with_table(
4849
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=2
4950
)
@@ -53,8 +54,8 @@ def test_migration_step_0_with_table():
5354
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
5455
)
5556
# When: Execute Step 0 with sort_read_value=3
56-
# Then: throws Exception (i.e. cannot read values in new format)
57-
with pytest.raises(Exception): # The exact exception may vary in Python implementation
57+
# Then: throws DecryptionError Exception (i.e. cannot read values in new format)
58+
with pytest.raises(DecryptionError): # The exact exception may vary in Python implementation
5859
migration_step_0.migration_step_0_with_table(
5960
kms_key_id=TEST_KMS_KEY_ID, ddb_table_name=TEST_DDB_TABLE_NAME, sort_read_value=3
6061
)

0 commit comments

Comments
 (0)