Skip to content

Commit f0cbb54

Browse files
author
Lucas McDonald
committed
m
2 parents cb32a37 + 981769d commit f0cbb54

File tree

16 files changed

+603
-681
lines changed

16 files changed

+603
-681
lines changed

Diff for: DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
"""AWS Database Encryption SDK for DynamoDB."""
5+
46
# Initialize generated Dafny
57
from .internaldafny.generated import module_ # noqa: F401
68

Diff for: DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted/boto3_interface.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
"""Interface for interacting with DynamoDB using boto3."""
34
import abc
45
from typing import Any, Dict
56
from abc import abstractmethod
67

8+
79
class EncryptedBotoInterface(abc.ABC):
810
"""Interface for encrypted boto3 interfaces."""
911

10-
def _copy_sdk_response_to_dbesdk_response(self, sdk_response: Dict[str, Any], dbesdk_response: Dict[str, Any]) -> Dict[str, Any]:
12+
def _copy_sdk_response_to_dbesdk_response(
13+
self, sdk_response: Dict[str, Any], dbesdk_response: Dict[str, Any]
14+
) -> Dict[str, Any]:
1115
"""Copy any missing fields from the SDK response to the DBESDK response.
1216
1317
Args:
14-
sdk_response: The raw SDK response
15-
dbesdk_response: The current DBESDK response
18+
sdk_response: The raw SDK response.
19+
dbesdk_response: The current DBESDK response.
1620
1721
Returns:
18-
dict: The DBESDK response with any missing fields copied from SDK response
22+
dict: The DBESDK response with any missing fields copied from SDK response.
1923
"""
2024
for sdk_response_key, sdk_response_value in sdk_response.items():
2125
if sdk_response_key not in dbesdk_response:
@@ -42,4 +46,6 @@ def __getattr__(self, name: str) -> Any:
4246
client_attr = getattr(self, self._boto_client_attr_name)
4347
if hasattr(client_attr, name):
4448
return getattr(client_attr, name)
45-
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
49+
raise AttributeError(
50+
f"'{self.__class__.__name__}' object has no attribute '{name}'"
51+
)

Diff for: DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted/client.py

+69-164
Large diffs are not rendered by default.

Diff for: DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted/item.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ddb_to_dict,
2121
)
2222

23+
2324
class ItemEncryptor:
2425
"""Class providing item-level encryption for DynamoDB items / Python dictionaries."""
2526

@@ -35,7 +36,7 @@ def __init__(
3536
Parameters:
3637
item_encryptor_config (DynamoDbItemEncryptorConfig): Encryption configuration object.
3738
"""
38-
self._internal_client = DynamoDbItemEncryptor(config = item_encryptor_config)
39+
self._internal_client = DynamoDbItemEncryptor(config=item_encryptor_config)
3940

4041
def encrypt_python_item(
4142
self,
@@ -60,15 +61,15 @@ def encrypt_python_item(
6061
6162
Parameters:
6263
plaintext_dict_item (dict[str, Any]): A standard Python dictionary.
63-
64+
6465
Returns:
6566
EncryptItemOutput: Structure containing the following fields:
6667
- `encrypted_item` (dict[str, Any]): The encrypted Python dictionary.
6768
**Note:** The item was encrypted as DynamoDB JSON, then transformed to a Python dictionary.
6869
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (parsed `aws_dbe_head` value).
6970
7071
Example:
71-
72+
7273
>>> plaintext_item = {
7374
... 'some': 'data',
7475
... 'more': 5
@@ -78,11 +79,13 @@ def encrypt_python_item(
7879
>>> header = encrypt_output.parsed_header
7980
"""
8081
plaintext_ddb_item = dict_to_ddb(plaintext_dict_item)
81-
encrypted_ddb_item: EncryptItemOutput = self.encrypt_dynamodb_item(plaintext_ddb_item)
82+
encrypted_ddb_item: EncryptItemOutput = self.encrypt_dynamodb_item(
83+
plaintext_ddb_item
84+
)
8285
encrypted_dict_item = ddb_to_dict(encrypted_ddb_item.encrypted_item)
8386
return EncryptItemOutput(
84-
encrypted_item = encrypted_dict_item,
85-
parsed_header = encrypted_ddb_item.parsed_header
87+
encrypted_item=encrypted_dict_item,
88+
parsed_header=encrypted_ddb_item.parsed_header,
8689
)
8790

8891
def encrypt_dynamodb_item(
@@ -101,15 +104,15 @@ def encrypt_dynamodb_item(
101104
102105
Parameters:
103106
plaintext_dynamodb_item (dict[str, dict[str, Any]]): The item to encrypt formatted as DynamoDB JSON.
104-
107+
105108
Returns:
106109
EncryptItemOutput: Structure containing the following fields:
107110
- `encrypted_item` (dict[str, Any]): A dictionary containing the encrypted DynamoDB item
108111
formatted as DynamoDB JSON.
109112
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (`aws_dbe_head` value).
110113
111114
Example:
112-
115+
113116
>>> plaintext_item = {
114117
... 'some': {'S': 'data'},
115118
... 'more': {'N': '5'}
@@ -119,9 +122,7 @@ def encrypt_dynamodb_item(
119122
>>> header = encrypt_output.parsed_header
120123
"""
121124
return self.encrypt_item(
122-
EncryptItemInput(
123-
plaintext_item = plaintext_dynamodb_item
124-
)
125+
EncryptItemInput(plaintext_item=plaintext_dynamodb_item)
125126
)
126127

127128
def encrypt_item(
@@ -137,14 +138,14 @@ def encrypt_item(
137138
Parameters:
138139
encrypt_item_input (EncryptItemInput): Structure containing the following field:
139140
- `plaintext_item` (dict[str, Any]): The item to encrypt formatted as DynamoDB JSON.
140-
141+
141142
Returns:
142143
EncryptItemOutput: Structure containing the following fields:
143144
- `encrypted_item` (dict[str, Any]): The encrypted DynamoDB item formatted as DynamoDB JSON.
144145
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (`aws_dbe_head` value).
145146
146147
Example:
147-
148+
148149
>>> plaintext_item = {
149150
... 'some': {'S': 'data'},
150151
... 'more': {'N': '5'}
@@ -182,15 +183,15 @@ def decrypt_python_item(
182183
183184
Parameters:
184185
encrypted_dict_item (dict[str, Any]): A standard Python dictionary with encrypted values.
185-
186+
186187
Returns:
187188
DecryptItemOutput: Structure containing the following fields:
188189
- `plaintext_item` (dict[str, Any]): The decrypted Python dictionary.
189190
**Note:** The item was decrypted as DynamoDB JSON, then transformed to a Python dictionary.
190191
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (parsed `aws_dbe_head` value).
191192
192193
Example:
193-
194+
194195
>>> encrypted_item = {
195196
... 'some': b'ENCRYPTED_DATA',
196197
... 'more': b'ENCRYPTED_DATA',
@@ -200,11 +201,13 @@ def decrypt_python_item(
200201
>>> header = decrypt_output.parsed_header
201202
"""
202203
encrypted_ddb_item = dict_to_ddb(encrypted_dict_item)
203-
plaintext_ddb_item: DecryptItemOutput = self.decrypt_dynamodb_item(encrypted_ddb_item)
204+
plaintext_ddb_item: DecryptItemOutput = self.decrypt_dynamodb_item(
205+
encrypted_ddb_item
206+
)
204207
plaintext_dict_item = ddb_to_dict(plaintext_ddb_item.plaintext_item)
205208
return DecryptItemOutput(
206-
plaintext_item = plaintext_dict_item,
207-
parsed_header = plaintext_ddb_item.parsed_header
209+
plaintext_item=plaintext_dict_item,
210+
parsed_header=plaintext_ddb_item.parsed_header,
208211
)
209212

210213
def decrypt_dynamodb_item(
@@ -223,14 +226,14 @@ def decrypt_dynamodb_item(
223226
224227
Parameters:
225228
encrypted_ddb_item (dict[str, dict[str, Any]]): The item to decrypt formatted as DynamoDB JSON.
226-
229+
227230
Returns:
228231
DecryptItemOutput: Structure containing the following fields:
229232
- `plaintext_item` (dict[str, Any]): The plaintext DynamoDB item formatted as DynamoDB JSON.
230233
- `parsed_header` (Optional[ParsedHeader]): The decrypted DynamoDB item's header (`aws_dbe_head` value).
231234
232235
Example:
233-
236+
234237
>>> encrypted_item = {
235238
... 'some': {'B': b'ENCRYPTED_DATA'},
236239
... 'more': {'B': b'ENCRYPTED_DATA'}
@@ -240,9 +243,7 @@ def decrypt_dynamodb_item(
240243
>>> header = decrypt_output.parsed_header
241244
"""
242245
return self.decrypt_item(
243-
DecryptItemInput(
244-
encrypted_item = encrypted_dynamodb_item
245-
)
246+
DecryptItemInput(encrypted_item=encrypted_dynamodb_item)
246247
)
247248

248249
def decrypt_item(
@@ -258,14 +259,14 @@ def decrypt_item(
258259
Parameters:
259260
decrypt_item_input (DecryptItemInput): Structure containing the following field:
260261
- `encrypted_item` (dict[str, Any]): The item to decrypt formatted as DynamoDB JSON.
261-
262+
262263
Returns:
263264
DecryptItemOutput: Structure containing the following fields:
264265
- `plaintext_item` (dict[str, Any]): The decrypted DynamoDB item formatted as DynamoDB JSON.
265266
- `parsed_header` (Optional[ParsedHeader]): The decrypted DynamoDB item's header (`aws_dbe_head` value).
266267
267268
Example:
268-
269+
269270
>>> encrypted_item = {
270271
... 'some': {'B': b'ENCRYPTED_DATA'},
271272
... 'more': {'B': b'ENCRYPTED_DATA'}

0 commit comments

Comments
 (0)