Skip to content

Commit ace65e7

Browse files
committed
migration 5
1 parent eca80a3 commit ace65e7

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@ def Build(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncryptorConfig):
3434

3535
legacy_override = config.legacyOverride.value
3636

37+
maybe_encryptor = aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb.dafny_to_smithy.aws_cryptography_dbencryptionsdk_dynamodb_LegacyDynamoDbEncryptorReference(
38+
legacy_override.encryptor
39+
)
40+
3741
# Precondition: The encryptor MUST be a DynamoDBEncryptor
3842
if not _HAS_LEGACY_DDBEC:
3943
return InternalLegacyOverride.CreateBuildFailure(
4044
InternalLegacyOverride.CreateError("Could not find aws-dynamodb-encryption-python installation")
4145
)
42-
if not isinstance(legacy_override.encryptor, EncryptedClient):
46+
if not isinstance(maybe_encryptor, EncryptedClient):
4347
return InternalLegacyOverride.CreateBuildFailure(
4448
InternalLegacyOverride.CreateError("Legacy encryptor is not supported")
4549
)
46-
maybe_encryptor = aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb.dafny_to_smithy.aws_cryptography_dbencryptionsdk_dynamodb_LegacyDynamoDbEncryptorReference(
47-
legacy_override.encryptor
48-
)
4950

5051
# Preconditions: MUST be able to create valid encryption context
5152
maybe_encryption_context = InternalLegacyOverride.legacyEncryptionContext(config)
@@ -59,7 +60,9 @@ def Build(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncryptorConfig):
5960

6061
# Create and return the legacy override instance
6162
legacy_instance = InternalLegacyOverride()
62-
legacy_instance.encryptor = maybe_encryptor
63+
# Store both the original encryptor and the wrapped reference
64+
legacy_instance.original_encryptor = legacy_override.encryptor # Store the original EncryptedClient
65+
legacy_instance.encryptor = maybe_encryptor # Store the wrapped LegacyDynamoDbEncryptorReference
6366
legacy_instance.policy = legacy_override.policy
6467
# Access the value property, not calling it as a function
6568
legacy_instance.encryption_context = maybe_encryption_context.value
@@ -200,9 +203,11 @@ def DecryptItem(self, input):
200203
InternalLegacyOverride.CreateError("Item does not contain required legacy fields")
201204
)
202205

203-
# Use the encryptor to decrypt the item using the instance attributes
204-
decrypted_item = self.encryptor.decrypt_item(
205-
encrypted_item, actions=self.attribute_actions, encryption_context=self.encryption_context
206+
# Use the original EncryptedClient to decrypt the item
207+
decrypted_item = self.original_encryptor.decrypt_item(
208+
encrypted_item,
209+
attribute_actions=self.attribute_actions,
210+
encryption_context=self.encryption_context
206211
)
207212

208213
# Create the output with the decrypted item
@@ -215,7 +220,8 @@ def DecryptItem(self, input):
215220

216221
def __init__(self):
217222
super().__init__()
218-
self.encryptor = None
223+
self.encryptor = None # LegacyDynamoDbEncryptorReference
224+
self.original_encryptor = None # Original EncryptedClient with encrypt_item/decrypt_item methods
219225
self.attribute_actions = None
220226
self.encryption_context = None
221227
self.policy = None

0 commit comments

Comments
 (0)