Skip to content

Commit b227e64

Browse files
author
Lucas McDonald
committed
m
1 parent 309c2a3 commit b227e64

File tree

8 files changed

+34
-185
lines changed

8 files changed

+34
-185
lines changed

.github/workflows/ci_test_vector_python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@ jobs:
9999
- name: Test Python TestVectors with ${{matrix.interface}} interface
100100
working-directory: ${{matrix.library}}
101101
run: |
102-
cp ../java/*.json runtimes/python/
102+
cp runtimes/java/*.json runtimes/python
103103
make test_python_${{matrix.interface}}_interface

DynamoDbEncryption/runtimes/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ select = [
8282
# Ignore all "public"-related linting errors for internal modules
8383
"D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107",
8484
# Ignore opinionated docstring linting errors for internal modules
85-
"D205", "D400", "D401", "D403"
85+
"D205", "D400", "D401", "D403", "D404", "D415",
8686
]
8787

8888
[tool.black]

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
# (generated Dafny, then externs)
66
# ruff: noqa: I
77
# Initialize generated Dafny
8-
from .internaldafny.generated import module_
9-
108
# Initialize externs
119
# noqa: F401, F403
1210
from .internaldafny import extern
11+
from .internaldafny.generated import module_
1312

1413
"""
1514
boto3 uses Python's decimal library to deserialize numbers retrieved by resources

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def batch_get_item(self, **kwargs):
169169
)
170170

171171
def batch_write_item(self, **kwargs):
172-
"""Puts or deletes multiple items in one or more tables.
172+
"""Put or delete multiple items in one or more tables.
173173
For put operations, encrypts items before writing.
174174
175175
The parameters and return value match the boto3 DynamoDB batch_write_item API:

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

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ def __init__(
5757
table: ServiceResource,
5858
encryption_config: DynamoDbTablesEncryptionConfig,
5959
):
60-
"""Parameters
61-
table (ServiceResource): Initialized boto3 DynamoDB table
62-
encryption_config (DynamoDbTablesEncryptionConfig): Initialized DynamoDbTablesEncryptionConfig
60+
"""Create an EncryptedTable object.
61+
62+
Args:
63+
table (ServiceResource): Initialized boto3 DynamoDB table
64+
encryption_config (DynamoDbTablesEncryptionConfig): Initialized DynamoDbTablesEncryptionConfig
6365
6466
"""
6567
self._table = table
@@ -71,20 +73,16 @@ def __init__(
7173
)
7274

7375
def put_item(self, **kwargs) -> dict[str, Any]:
74-
"""Puts a single item in the table. Encrypts the item before writing to DynamoDB.
76+
"""Put a single item to the table. Encrypts the item before writing to DynamoDB.
7577
7678
The parameters and return value match the boto3 DynamoDB table put_item API:
7779
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/put_item.html
7880
7981
Args:
80-
Item (dict): A map of attribute name/value pairs to write to the table
81-
82-
These are only a list of required args; see boto3 docs for complete request structure.
82+
**kwargs: Keyword arguments to pass to the scan operation. These match the boto3 scan API parameters.
8383
8484
Returns:
85-
dict: The response from DynamoDB.
86-
87-
See boto3 docs for complete response structure.
85+
dict: The response from DynamoDB containing the scanned items. This matches the boto3 scan API response.
8886
8987
"""
9088
return self._table_operation_logic(
@@ -101,20 +99,16 @@ def put_item(self, **kwargs) -> dict[str, Any]:
10199
)
102100

103101
def get_item(self, **kwargs) -> dict[str, Any]:
104-
"""Gets a single item from the table. Decrypts the item after reading from DynamoDB.
102+
"""Get a single item from the table. Decrypts the item after reading from DynamoDB.
105103
106104
The parameters and return value match the boto3 DynamoDB table get_item API:
107105
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/get_item.html
108106
109107
Args:
110-
Key (dict): The primary key of the item to retrieve
111-
112-
These are only a list of required args; see boto3 docs for complete request structure.
108+
**kwargs: Keyword arguments to pass to the scan operation. These match the boto3 scan API parameters.
113109
114110
Returns:
115-
dict: The response from DynamoDB containing the requested item.
116-
117-
See boto3 docs for complete response structure.
111+
dict: The response from DynamoDB containing the scanned items. This matches the boto3 scan API response.
118112
119113
"""
120114
return self._table_operation_logic(
@@ -131,20 +125,16 @@ def get_item(self, **kwargs) -> dict[str, Any]:
131125
)
132126

133127
def query(self, **kwargs) -> dict[str, Any]:
134-
"""Queries items from the table or index. Decrypts any returned items.
128+
"""Query items from the table or index. Decrypts any returned items.
135129
136130
The parameters and return value match the boto3 DynamoDB table query API:
137131
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/query.html
138132
139133
Args:
140-
KeyConditionExpression (str): The condition that specifies the key value(s) for items to be retrieved
141-
142-
These are only a list of required args; see boto3 docs for complete request structure.
134+
**kwargs: Keyword arguments to pass to the scan operation. These match the boto3 scan API parameters.
143135
144136
Returns:
145-
dict: The response from DynamoDB containing the matching items.
146-
147-
See boto3 docs for complete response structure.
137+
dict: The response from DynamoDB containing the scanned items. This matches the boto3 scan API response.
148138
149139
"""
150140
return self._table_operation_logic(
@@ -161,20 +151,16 @@ def query(self, **kwargs) -> dict[str, Any]:
161151
)
162152

163153
def scan(self, **kwargs) -> dict[str, Any]:
164-
"""Scans the entire table or index. Decrypts any returned items.
154+
"""Scan the entire table or index. Decrypts any returned items.
165155
166156
The parameters and return value match the boto3 DynamoDB table scan API:
167157
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/scan.html
168158
169159
Args:
170-
FilterExpression (str, optional): A string that contains conditions that DynamoDB applies after the scan operation
171-
172-
These are only a list of required args; see boto3 docs for complete request structure.
160+
**kwargs: Keyword arguments to pass to the scan operation. These match the boto3 scan API parameters.
173161
174162
Returns:
175-
dict: The response from DynamoDB containing the scanned items.
176-
177-
See boto3 docs for complete response structure.
163+
dict: The response from DynamoDB containing the scanned items. This matches the boto3 scan API response.
178164
179165
"""
180166
return self._table_operation_logic(
@@ -207,13 +193,11 @@ def batch_writer(self, overwrite_by_pkeys: list[str] | None = None) -> BatchWrit
207193
208194
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/batch_writer.html
209195
210-
Parameters
211-
----------
196+
Args:
212197
overwrite_by_pkeys: De-duplicate request items in buffer if match new request
213198
item on specified primary keys. i.e ``["partition_key1", "sort_key2", "sort_key3"]``
214199
215-
Returns
216-
-------
200+
Returns:
217201
BatchWriter: A batch writer that will transparently encrypt requests
218202
219203
"""
@@ -240,8 +224,7 @@ def _table_operation_logic(
240224
output_client_to_resource_shape_transform_method: Any,
241225
table_method: Callable,
242226
) -> dict[str, Any]:
243-
"""Shared logic to interface between user-supplied input, encryption/decryption transformers,
244-
and boto3 Tables.
227+
"""Interface between user-supplied input, encryption/decryption transformers, and boto3 Tables.
245228
246229
Args:
247230
operation_input: User-supplied input to the operation

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/internal/client_to_resource.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ def condition_handler(self, expression_key, request):
1818
# Resources accept either strings or Attrs.
1919
condition = request[expression_key]
2020

21-
# This conversion in client_to_resource does not update ExpressionAttributeNames nor ExpressionAttributeValues.
22-
# However, resource_to_client condition_handler may add new ExpressionAttributeNames and ExpressionAttributeValues.
23-
# Smithy-generated code expects condition_handlers to return ExpressionAttributeNames and ExpressionAttributeValues.
21+
# This conversion in client_to_resource does not update neither
22+
# ExpressionAttributeNames nor ExpressionAttributeValues.
23+
# However, resource_to_client condition_handler may add new
24+
# ExpressionAttributeNames and ExpressionAttributeValues.
25+
# Smithy-generated code expects condition_handlers to return
26+
# ExpressionAttributeNames and ExpressionAttributeValues.
2427
try:
2528
names = request["ExpressionAttributeNames"]
2629
except KeyError:

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/internal/condition_expression_builder.py

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -186,139 +186,3 @@ def _build_value_placeholder(self, value, attribute_value_placeholders, has_grou
186186
self._value_count += 1
187187
attribute_value_placeholders[value_placeholder] = value
188188
return value_placeholder
189-
190-
191-
# class InternalDBESDKDynamoDBConditionExpressionBuilder:
192-
# """
193-
# This internal class is used to transform boto3 DyamoDB conditions from
194-
# Python classes to DynamoDB ConditionExpressions
195-
# for use by internal DBESDK DyanmoDB operation transformers.
196-
197-
# This class is a modified version of boto3's ConditionExpressionBuilder:
198-
# https://github.com/boto/boto3/blob/c5c634b53be589d6e913e6dca51ad8d6480f58c7/boto3/dynamodb/conditions.py#L304
199-
# The original class is intended to interface from boto3 Table resources to boto3 clients.
200-
# The class defined here is intended to interface from boto3 Table resources
201-
# to internal DBESDK DynamoDB operation transformers.
202-
# The placeholder insertion logic has been removed from this class, along with supporting logic,
203-
# but this class maintains boto3's recursive ConditionExpression traversal logic.
204-
# """
205-
206-
# def __init__(self):
207-
# self._name_count = 0
208-
# self._value_count = 0
209-
# self._name_placeholder = 'n'
210-
# self._value_placeholder = 'v'
211-
212-
# def _get_name_placeholder(self):
213-
# return '#' + self._name_placeholder + str(self._name_count)
214-
215-
# def _get_value_placeholder(self):
216-
# return ':' + self._value_placeholder + str(self._value_count)
217-
218-
# def reset(self):
219-
# """Resets the placeholder name and values"""
220-
# self._name_count = 0
221-
# self._value_count = 0
222-
223-
# def build_expression(
224-
# self,
225-
# condition,
226-
# expression_attribute_names,
227-
# expression_attribute_values,
228-
# ):
229-
# """Builds the condition expression.
230-
231-
# :type condition: ConditionBase
232-
# :param condition: A condition to be built into a condition expression string.
233-
234-
# :rtype: (string, dict, dict)
235-
# :returns: Will return a string representing the condition expression,
236-
# the original dictionary of attribute names,
237-
# and the original dictionary of attribute values.
238-
# """
239-
# if not isinstance(condition, ConditionBase):
240-
# raise DynamoDBNeedsConditionError(condition)
241-
# condition_expression = self._build_expression(condition, expression_attribute_names, expression_attribute_values)
242-
# return BuiltConditionExpression(
243-
# condition_expression=condition_expression,
244-
# # BuiltConditionExpression uses "placeholders" nomenclature;
245-
# # this is an artifact of the original boto3 ConditionExpressionBuilder.
246-
# # This class neither creates placeholders, nor even uses the provided name/values dicts.
247-
# # They are only here as required arguments for the BuiltConditionExpression class.
248-
# attribute_name_placeholders=expression_attribute_names,
249-
# attribute_value_placeholders=expression_attribute_values,
250-
# )
251-
252-
# def _build_expression(
253-
# self,
254-
# condition,
255-
# expression_attribute_names,
256-
# expression_attribute_values,
257-
# ):
258-
# expression_dict = condition.get_expression()
259-
# replaced_values = []
260-
# for value in expression_dict['values']:
261-
# # Recurse for each value in the expression.
262-
# replaced_value = self._build_expression_component(
263-
# condition,
264-
# value,
265-
# expression_attribute_names,
266-
# expression_attribute_values,
267-
# )
268-
# replaced_values.append(replaced_value)
269-
# # Fill out the expression using the operator and its recursive expressions.
270-
# return expression_dict['format'].format(
271-
# *replaced_values, operator=expression_dict['operator']
272-
# )
273-
274-
# def _build_expression_component(
275-
# self,
276-
# condition,
277-
# value,
278-
# expression_attribute_names,
279-
# expression_attribute_values,
280-
# ):
281-
# # Continue to recurse if the value is a ConditionBase in order
282-
# # to extract out all parts of the expression.
283-
# if isinstance(value, ConditionBase):
284-
# return self._build_expression(
285-
# value,
286-
# )
287-
# # If it is not a ConditionBase, we can recurse no further.
288-
# # If it's an attribute, insert its name.
289-
# elif isinstance(value, AttributeBase):
290-
# return self._build_name_placeholder(
291-
# value, attribute_name_placeholders
292-
# )
293-
# # If it is anything else, we treat it as a value.
294-
# else:
295-
# if condition.has_grouped_values:
296-
# # Assuming the values are grouped by parenthesis.
297-
# # IN is the currently the only one that uses this so it maybe
298-
# # needed to be changed in future.
299-
# return '(' + ', '.join(value) + ')'
300-
# return value
301-
302-
# def _build_value_placeholder(
303-
# self, value, attribute_value_placeholders, has_grouped_values=False
304-
# ):
305-
# # If the values are grouped, we need to add a placeholder for
306-
# # each element inside of the actual value.
307-
# if has_grouped_values:
308-
# placeholder_list = []
309-
# for v in value:
310-
# value_placeholder = self._get_value_placeholder()
311-
# self._value_count += 1
312-
# placeholder_list.append(value_placeholder)
313-
# attribute_value_placeholders[value_placeholder] = v
314-
# # Assuming the values are grouped by parenthesis.
315-
# # IN is the currently the only one that uses this so it maybe
316-
# # needed to be changed in future.
317-
# return '(' + ', '.join(placeholder_list) + ')'
318-
# # Otherwise, treat the value as a single value that needs only
319-
# # one placeholder.
320-
# else:
321-
# value_placeholder = self._get_value_placeholder()
322-
# self._value_count += 1
323-
# attribute_value_placeholders[value_placeholder] = value
324-
# return value_placeholder

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
def dict_to_ddb(item: dict[str, Any]) -> dict[str, Any]:
16-
"""Converts a native Python dictionary to a DynamoDB-JSON item.
16+
"""Convert a native Python dictionary to a DynamoDB-JSON item.
1717
1818
Args:
1919
item (Dict[str, Any]): Native Python dictionary.
@@ -27,7 +27,7 @@ def dict_to_ddb(item: dict[str, Any]) -> dict[str, Any]:
2727

2828

2929
def list_of_dict_to_list_of_ddb(items: list[dict[str, Any]]) -> list[dict[str, Any]]:
30-
"""Converts a list of Python dictionaries into a list of DynamoDB-JSON formatted items.
30+
"""Convert a list of Python dictionaries into a list of DynamoDB-JSON formatted items.
3131
3232
Args:
3333
items (List[Dict[str, Any]]): List of native Python dictionaries.
@@ -40,7 +40,7 @@ def list_of_dict_to_list_of_ddb(items: list[dict[str, Any]]) -> list[dict[str, A
4040

4141

4242
def ddb_to_dict(item: dict[str, Any]) -> dict[str, Any]:
43-
"""Converts a DynamoDB-JSON item to a native Python dictionary.
43+
"""Convert a DynamoDB-JSON item to a native Python dictionary.
4444
4545
Args:
4646
item (Dict[str, Any]): DynamoDB-formatted item.
@@ -54,7 +54,7 @@ def ddb_to_dict(item: dict[str, Any]) -> dict[str, Any]:
5454

5555

5656
def list_of_ddb_to_list_of_dict(items: list[dict[str, Any]]) -> list[dict[str, Any]]:
57-
"""Converts a list of DynamoDB-JSON formatted items to a list of Python dictionaries.
57+
"""Convert a list of DynamoDB-JSON formatted items to a list of Python dictionaries.
5858
5959
Args:
6060
items (List[Dict[str, Any]]): List of DynamoDB-formatted items.

0 commit comments

Comments
 (0)