37
37
38
38
39
39
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.
41
42
42
43
This class implements the complete boto3 DynamoDB client API, allowing it to serve as a
43
44
drop-in replacement that transparently handles encryption and decryption of items.
@@ -74,14 +75,17 @@ def __init__(
74
75
encryption_config : DynamoDbTablesEncryptionConfig ,
75
76
expect_standard_dictionaries : bool | None = False ,
76
77
):
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).
85
89
86
90
"""
87
91
self ._client = client
@@ -92,21 +96,17 @@ def __init__(
92
96
self ._client_to_resource_shape_converter = ClientShapeToResourceShapeConverter (delete_table_name = False )
93
97
94
98
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.
96
101
97
102
The parameters and return value match the boto3 DynamoDB put_item API:
98
103
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/put_item.html
99
104
100
105
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.
105
107
106
108
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.
110
110
111
111
"""
112
112
return self ._client_operation_logic (
@@ -123,21 +123,17 @@ def put_item(self, **kwargs) -> dict[str, Any]:
123
123
)
124
124
125
125
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.
127
128
128
129
The parameters and return value match the boto3 DynamoDB get_item API:
129
130
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/get_item.html
130
131
131
132
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.
136
134
137
135
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.
141
137
142
138
"""
143
139
return self ._client_operation_logic (
@@ -154,20 +150,17 @@ def get_item(self, **kwargs) -> dict[str, Any]:
154
150
)
155
151
156
152
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.
158
155
159
156
The parameters and return value match the boto3 DynamoDB query API:
160
157
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/query.html
161
158
162
159
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.
166
161
167
162
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.
171
164
172
165
"""
173
166
return self ._client_operation_logic (
@@ -184,20 +177,17 @@ def query(self, **kwargs) -> dict[str, Any]:
184
177
)
185
178
186
179
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.
188
182
189
183
The parameters and return value match the boto3 DynamoDB scan API:
190
184
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/scan.html
191
185
192
186
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.
196
188
197
189
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.
201
191
202
192
"""
203
193
return self ._client_operation_logic (
@@ -214,21 +204,19 @@ def scan(self, **kwargs) -> dict[str, Any]:
214
204
)
215
205
216
206
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
+
218
210
For put operations, encrypts items before writing.
219
211
220
212
The parameters and return value match the boto3 DynamoDB batch_write_item API:
221
213
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/batch_write_item.html
222
214
223
215
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.
227
217
228
218
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.
232
220
233
221
"""
234
222
return self ._client_operation_logic (
@@ -245,20 +233,17 @@ def batch_write_item(self, **kwargs) -> dict[str, Any]:
245
233
)
246
234
247
235
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.
249
238
250
239
The parameters and return value match the boto3 DynamoDB batch_get_item API:
251
240
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/batch_get_item.html
252
241
253
242
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.
257
244
258
245
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.
262
247
263
248
"""
264
249
return self ._client_operation_logic (
@@ -275,20 +260,18 @@ def batch_get_item(self, **kwargs) -> dict[str, Any]:
275
260
)
276
261
277
262
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.
279
265
280
266
The parameters and return value match the boto3 DynamoDB transact_get_items API:
281
267
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/transact_get_items.html
282
268
283
269
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.
287
272
288
273
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.
292
275
293
276
"""
294
277
return self ._client_operation_logic (
@@ -305,21 +288,20 @@ def transact_get_items(self, **kwargs) -> dict[str, Any]:
305
288
)
306
289
307
290
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
+
309
294
For put operations, encrypts items before writing.
310
295
311
296
The parameters and return value match the boto3 DynamoDB transact_write_items API:
312
297
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/transact_write_items.html
313
298
314
299
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.
318
302
319
303
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.
323
305
324
306
"""
325
307
return self ._client_operation_logic (
@@ -336,7 +318,8 @@ def transact_write_items(self, **kwargs) -> dict[str, Any]:
336
318
)
337
319
338
320
def update_item (self , ** kwargs ):
339
- """Not implemented. Raises NotImplementedError.
321
+ """
322
+ Not implemented. Raises NotImplementedError.
340
323
341
324
Args:
342
325
**kwargs: Any arguments passed to this method
@@ -348,8 +331,11 @@ def update_item(self, **kwargs):
348
331
raise NotImplementedError ('"update_item" is not yet implemented' )
349
332
350
333
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.
353
339
354
340
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#paginators
355
341
@@ -388,22 +374,27 @@ def _client_operation_logic(
388
374
output_item_to_ddb_transform_method : callable ,
389
375
output_item_to_dict_transform_method : callable ,
390
376
) -> 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.
392
379
393
380
This captures the shared pattern to call encryption/decryption transformer code
394
381
and boto3 Clients across all methods in this class.
395
382
396
383
Args:
397
384
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
400
389
input_transform_method: The method to transform the input for encryption
401
390
input_transform_shape: The shape of the input transform
402
391
output_transform_method: The method to transform the output for decryption
403
392
output_transform_shape: The shape of the output transform
404
393
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
407
398
408
399
Returns:
409
400
dict: The transformed response from DynamoDB
@@ -446,10 +437,11 @@ def _client_operation_logic(
446
437
447
438
@property
448
439
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.
450
442
451
443
Returns:
452
444
str: '_client'
453
445
454
446
"""
455
- return "_client"
447
+ return "_client"
0 commit comments