Skip to content

Commit 9a8164e

Browse files
author
Lucas McDonald
committed
ruff
1 parent c20581f commit 9a8164e

File tree

12 files changed

+233
-195
lines changed

12 files changed

+233
-195
lines changed

DynamoDbEncryption/runtimes/python/pyproject.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ exclude = [
6464
line-length=120
6565
indent-width=4
6666
target-version = "py311"
67+
68+
[tool.ruff.lint]
69+
# Choose linting tools
6770
select = [
6871
# pycodestyle: spacing, line length
6972
"E",
@@ -73,11 +76,14 @@ select = [
7376
"I",
7477
# pydocstyle: docstring style
7578
"D",
76-
# pyupgrade: auto-upgrade syntax if possible
77-
"UP",
79+
]
80+
# Ignore incompatible linting options
81+
ignore=[
82+
"D203", # `incorrect-blank-line-before-class`; incompatible with `no-blank-line-before-class` (D211)
83+
"D212", # `multi-line-summary-first-line`; incompatible with `multi-line-summary-second-line` (D213)
7884
]
7985

80-
[tool.ruff.per-file-ignores]
86+
[tool.ruff.lint.per-file-ignores]
8187
"src/aws_dbesdk_dynamodb/internal/*" = [
8288
# Ignore all "public"-related linting errors for internal modules
8389
"D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107",

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
"""Initialization code for AWS DBESDK for DynamoDB."""
34

45
# Initialize generated Dafny, then initialize externs
56
# Disable sorting imports; this order initializes code in the required order
67
# (generated Dafny, then externs)
7-
# ruff: noqa: I001
8+
# ruff: noqa: I001, F401
89
from .internaldafny.generated import module_
910
from .internaldafny import extern
1011

@@ -28,6 +29,8 @@
2829
2930
For DBESDK DynamoDB, change the DynamoDB context to treat "Rounded" as acceptable.
3031
"""
32+
# Keep these imports down here for clarity
33+
# ruff: noqa: E402
3134
from decimal import Rounded
3235

3336
import boto3.dynamodb.types

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
"""Interface for encrypted boto3 interfaces."""
34
import abc
45
from abc import abstractmethod
56
from typing import Any
@@ -11,7 +12,8 @@ class EncryptedBotoInterface(abc.ABC):
1112
def _copy_sdk_response_to_dbesdk_response(
1213
self, sdk_response: dict[str, Any], dbesdk_response: dict[str, Any]
1314
) -> dict[str, Any]:
14-
"""Copy any missing fields from the SDK response to the DBESDK response.
15+
"""
16+
Copy any missing fields from the SDK response to the DBESDK response.
1517
1618
Args:
1719
sdk_response: The raw SDK response
@@ -32,7 +34,8 @@ def _boto_client_attr_name(self) -> str:
3234
"""Name of the attribute containing the underlying boto3 client."""
3335

3436
def __getattr__(self, name: str) -> Any:
35-
"""Delegate unknown attributes to the underlying client.
37+
"""
38+
Delegate unknown attributes to the underlying client.
3639
3740
Args:
3841
name: The name of the attribute to get

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

Lines changed: 69 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838

3939
class EncryptedClient(EncryptedBotoInterface):
40-
"""Wrapper for a boto3 DynamoDB client that transparently encrypts/decrypts items.
40+
"""
41+
Wrapper for a boto3 DynamoDB client that transparently encrypts/decrypts items.
4142
4243
This class implements the complete boto3 DynamoDB client API, allowing it to serve as a
4344
drop-in replacement that transparently handles encryption and decryption of items.
@@ -74,14 +75,17 @@ def __init__(
7475
encryption_config: DynamoDbTablesEncryptionConfig,
7576
expect_standard_dictionaries: bool | None = False,
7677
):
77-
"""Parameters
78-
client (botocore.client.BaseClient): Initialized boto3 DynamoDB client
79-
encryption_config (DynamoDbTablesEncryptionConfig): Initialized DynamoDbTablesEncryptionConfig
80-
expect_standard_dictionaries (Optional[bool]): Does the underlying boto3 client expect items to be standard Python
81-
dictionaries? This should only be set to True if you are using a client obtained
82-
from a service resource or table resource (ex: `table.meta.client`).
83-
If this is True, EncryptedClient will expect item-like shapes to be
84-
standard Python dictionaries (default: False).
78+
"""
79+
Create an EncryptedClient object.
80+
81+
Args:
82+
client (botocore.client.BaseClient): Initialized boto3 DynamoDB client
83+
encryption_config (DynamoDbTablesEncryptionConfig): Initialized DynamoDbTablesEncryptionConfig
84+
expect_standard_dictionaries (Optional[bool]): Does the underlying boto3 client expect items
85+
to be standard Python dictionaries? This should only be set to True if you are using a
86+
client obtained from a service resource or table resource (ex: `table.meta.client`).
87+
If this is True, EncryptedClient will expect item-like shapes to be
88+
standard Python dictionaries (default: False).
8589
8690
"""
8791
self._client = client
@@ -92,21 +96,17 @@ def __init__(
9296
self._client_to_resource_shape_converter = ClientShapeToResourceShapeConverter(delete_table_name=False)
9397

9498
def put_item(self, **kwargs) -> dict[str, Any]:
95-
"""Puts a single item in a table. Encrypts the item before writing to DynamoDB.
99+
"""
100+
Put a single item to a table. Encrypts the item before writing to DynamoDB.
96101
97102
The parameters and return value match the boto3 DynamoDB put_item API:
98103
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/put_item.html
99104
100105
Args:
101-
TableName (str): Name of the table to write to
102-
Item (dict): A map of attribute name/value pairs to write to the table
103-
104-
These are only a list of required args; see boto3 docs for complete request structure.
106+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 put_item API parameters.
105107
106108
Returns:
107-
dict: The response from DynamoDB.
108-
109-
See boto3 docs for complete response structure.
109+
dict: The response from DynamoDB. This matches the boto3 put_item API response.
110110
111111
"""
112112
return self._client_operation_logic(
@@ -123,21 +123,17 @@ def put_item(self, **kwargs) -> dict[str, Any]:
123123
)
124124

125125
def get_item(self, **kwargs) -> dict[str, Any]:
126-
"""Gets a single item from a table. Decrypts the item after reading from DynamoDB.
126+
"""
127+
Get a single item from a table. Decrypts the item after reading from DynamoDB.
127128
128129
The parameters and return value match the boto3 DynamoDB get_item API:
129130
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/get_item.html
130131
131132
Args:
132-
TableName (str): Name of the table to read from
133-
Key (dict): The primary key of the item to retrieve
134-
135-
These are only a list of required args; see boto3 docs for complete request structure.
133+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 get_item API parameters.
136134
137135
Returns:
138-
dict: The response from DynamoDB containing the requested item.
139-
140-
See boto3 docs for complete response structure.
136+
dict: The response from DynamoDB. This matches the boto3 get_item API response.
141137
142138
"""
143139
return self._client_operation_logic(
@@ -154,20 +150,17 @@ def get_item(self, **kwargs) -> dict[str, Any]:
154150
)
155151

156152
def query(self, **kwargs) -> dict[str, Any]:
157-
"""Queries items from a table or index. Decrypts any returned items.
153+
"""
154+
Query items from a table or index. Decrypts any returned items.
158155
159156
The parameters and return value match the boto3 DynamoDB query API:
160157
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/query.html
161158
162159
Args:
163-
TableName (str): Name of the table to query
164-
165-
These are only a list of required args; see boto3 docs for complete request structure.
160+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 query API parameters.
166161
167162
Returns:
168-
dict: The response from DynamoDB containing the matching items.
169-
170-
See boto3 docs for complete response structure.
163+
dict: The response from DynamoDB. This matches the boto3 query API response.
171164
172165
"""
173166
return self._client_operation_logic(
@@ -184,20 +177,17 @@ def query(self, **kwargs) -> dict[str, Any]:
184177
)
185178

186179
def scan(self, **kwargs) -> dict[str, Any]:
187-
"""Scans an entire table or index. Decrypts any returned items.
180+
"""
181+
Scan an entire table or index. Decrypts any returned items.
188182
189183
The parameters and return value match the boto3 DynamoDB scan API:
190184
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/scan.html
191185
192186
Args:
193-
TableName (str): Name of the table to scan
194-
195-
These are only a list of required args; see boto3 docs for complete request structure.
187+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 scan API parameters.
196188
197189
Returns:
198-
dict: The response from DynamoDB containing the scanned items.
199-
200-
See boto3 docs for complete response structure.
190+
dict: The response from DynamoDB. This matches the boto3 scan API response.
201191
202192
"""
203193
return self._client_operation_logic(
@@ -214,21 +204,19 @@ def scan(self, **kwargs) -> dict[str, Any]:
214204
)
215205

216206
def batch_write_item(self, **kwargs) -> dict[str, Any]:
217-
"""Puts or deletes multiple items in one or more tables.
207+
"""
208+
Put or delete multiple items in one or more tables.
209+
218210
For put operations, encrypts items before writing.
219211
220212
The parameters and return value match the boto3 DynamoDB batch_write_item API:
221213
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/batch_write_item.html
222214
223215
Args:
224-
RequestItems (dict): A map of table names to lists of write operations
225-
226-
These are only a list of required args; see boto3 docs for complete request structure.
216+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 batch_write_item API parameters.
227217
228218
Returns:
229-
dict: The response from DynamoDB.
230-
231-
See boto3 docs for complete response structure.
219+
dict: The response from DynamoDB. This matches the boto3 batch_write_item API response.
232220
233221
"""
234222
return self._client_operation_logic(
@@ -245,20 +233,17 @@ def batch_write_item(self, **kwargs) -> dict[str, Any]:
245233
)
246234

247235
def batch_get_item(self, **kwargs) -> dict[str, Any]:
248-
"""Gets multiple items from one or more tables. Decrypts any returned items.
236+
"""
237+
Get multiple items from one or more tables. Decrypts any returned items.
249238
250239
The parameters and return value match the boto3 DynamoDB batch_get_item API:
251240
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/batch_get_item.html
252241
253242
Args:
254-
RequestItems (dict): A map of table names to lists of keys to retrieve
255-
256-
These are only a list of required args; see boto3 docs for complete request structure.
243+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 batch_get_item API parameters.
257244
258245
Returns:
259-
dict: The response from DynamoDB containing the requested items.
260-
261-
See boto3 docs for complete response structure.
246+
dict: The response from DynamoDB. This matches the boto3 batch_get_item API response.
262247
263248
"""
264249
return self._client_operation_logic(
@@ -275,20 +260,18 @@ def batch_get_item(self, **kwargs) -> dict[str, Any]:
275260
)
276261

277262
def transact_get_items(self, **kwargs) -> dict[str, Any]:
278-
"""Gets multiple items in a single transaction. Decrypts any returned items.
263+
"""
264+
Get multiple items in a single transaction. Decrypts any returned items.
279265
280266
The parameters and return value match the boto3 DynamoDB transact_get_items API:
281267
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/transact_get_items.html
282268
283269
Args:
284-
TransactItems (list): List of operations to perform in the transaction
285-
286-
These are only a list of required args; see boto3 docs for complete request structure.
270+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 transact_get_items API
271+
parameters.
287272
288273
Returns:
289-
dict: The response from DynamoDB containing the requested items.
290-
291-
See boto3 docs for complete response structure.
274+
dict: The response from DynamoDB. This matches the boto3 transact_get_items API response.
292275
293276
"""
294277
return self._client_operation_logic(
@@ -305,21 +288,20 @@ def transact_get_items(self, **kwargs) -> dict[str, Any]:
305288
)
306289

307290
def transact_write_items(self, **kwargs) -> dict[str, Any]:
308-
"""Performs multiple write operations in a single transaction.
291+
"""
292+
Perform multiple write operations in a single transaction.
293+
309294
For put operations, encrypts items before writing.
310295
311296
The parameters and return value match the boto3 DynamoDB transact_write_items API:
312297
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/transact_write_items.html
313298
314299
Args:
315-
TransactItems (list): List of operations to perform in the transaction
316-
317-
These are only a list of required args; see boto3 docs for complete request structure.
300+
**kwargs: Keyword arguments to pass to the operation. These match the boto3 transact_write_items API
301+
parameters.
318302
319303
Returns:
320-
dict: The response from DynamoDB.
321-
322-
See boto3 docs for complete response structure.
304+
dict: The response from DynamoDB. This matches the boto3 transact_write_items API response.
323305
324306
"""
325307
return self._client_operation_logic(
@@ -336,7 +318,8 @@ def transact_write_items(self, **kwargs) -> dict[str, Any]:
336318
)
337319

338320
def update_item(self, **kwargs):
339-
"""Not implemented. Raises NotImplementedError.
321+
"""
322+
Not implemented. Raises NotImplementedError.
340323
341324
Args:
342325
**kwargs: Any arguments passed to this method
@@ -348,8 +331,11 @@ def update_item(self, **kwargs):
348331
raise NotImplementedError('"update_item" is not yet implemented')
349332

350333
def get_paginator(self, operation_name: str) -> EncryptedPaginator | botocore.client.Paginator:
351-
"""Get a paginator from the underlying client. If the paginator requested is for
352-
"scan" or "query", the paginator returned will transparently decrypt the returned items.
334+
"""
335+
Get a paginator from the underlying client.
336+
337+
If the paginator requested is for "scan" or "query", the paginator returned will
338+
transparently decrypt the returned items.
353339
354340
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#paginators
355341
@@ -388,22 +374,27 @@ def _client_operation_logic(
388374
output_item_to_ddb_transform_method: callable,
389375
output_item_to_dict_transform_method: callable,
390376
) -> dict[str, Any]:
391-
"""Shared logic to interface between boto3 Client operation inputs and encryption transformers.
377+
"""
378+
Shared logic to interface between boto3 Client operation inputs and encryption transformers.
392379
393380
This captures the shared pattern to call encryption/decryption transformer code
394381
and boto3 Clients across all methods in this class.
395382
396383
Args:
397384
operation_input: The input to the operation
398-
input_item_to_ddb_transform_method: Method to transform input items from standard dictionaries to DynamoDB JSON
399-
input_item_to_dict_transform_method: Method to transform input items from DynamoDB JSON to standard dictionaries
385+
input_item_to_ddb_transform_method: Method to transform input items from standard dictionaries
386+
to DynamoDB JSON
387+
input_item_to_dict_transform_method: Method to transform input items from DynamoDB JSON
388+
to standard dictionaries
400389
input_transform_method: The method to transform the input for encryption
401390
input_transform_shape: The shape of the input transform
402391
output_transform_method: The method to transform the output for decryption
403392
output_transform_shape: The shape of the output transform
404393
client_method: The underlying client method to call
405-
output_item_to_ddb_transform_method: Method to transform output items from standard dictionaries to DynamoDB JSON
406-
output_item_to_dict_transform_method: Method to transform output items from DynamoDB JSON to standard dictionaries
394+
output_item_to_ddb_transform_method: Method to transform output items from standard dictionaries
395+
to DynamoDB JSON
396+
output_item_to_dict_transform_method: Method to transform output items from DynamoDB JSON
397+
to standard dictionaries
407398
408399
Returns:
409400
dict: The transformed response from DynamoDB
@@ -446,10 +437,11 @@ def _client_operation_logic(
446437

447438
@property
448439
def _boto_client_attr_name(self) -> str:
449-
"""Name of the attribute containing the underlying boto3 client.
440+
"""
441+
Name of the attribute containing the underlying boto3 client.
450442
451443
Returns:
452444
str: '_client'
453445
454446
"""
455-
return "_client"
447+
return "_client"

0 commit comments

Comments
 (0)