9
9
10
10
import attr
11
11
import six
12
- from attr .validators import deep_iterable , instance_of , optional
12
+ from attr .validators import deep_iterable , instance_of , is_callable , optional
13
13
14
14
from aws_encryption_sdk .exceptions import DecryptKeyError , EncryptKeyError
15
15
from aws_encryption_sdk .identifiers import AlgorithmSuite
23
23
24
24
try : # Python 3.5.0 and 3.5.1 have incompatible typing modules
25
25
from typing import Any , Dict , Iterable , Union # noqa pylint: disable=unused-import
26
+ from .client_suppliers import ClientSupplierType # noqa pylint: disable=unused-import
26
27
except ImportError : # pragma: no cover
27
28
# We only actually need these imports when running the mypy checks
28
29
pass
@@ -77,7 +78,7 @@ class KmsKeyring(Keyring):
77
78
:param List[str] grant_tokens: AWS KMS grant tokens to include in requests (optional)
78
79
"""
79
80
80
- _client_supplier = attr .ib (default = attr .Factory (DefaultClientSupplier ), validator = instance_of ( ClientSupplier ))
81
+ _client_supplier = attr .ib (default = attr .Factory (DefaultClientSupplier ), validator = is_callable ( ))
81
82
_generator_key_id = attr .ib (default = None , validator = optional (instance_of (six .string_types )))
82
83
_child_key_ids = attr .ib (
83
84
default = attr .Factory (tuple ),
@@ -154,7 +155,7 @@ class _AwsKmsSingleCmkKeyring(Keyring):
154
155
"""
155
156
156
157
_key_id = attr .ib (validator = instance_of (six .string_types ))
157
- _client_supplier = attr .ib (validator = instance_of ( ClientSupplier ))
158
+ _client_supplier = attr .ib (validator = is_callable ( ))
158
159
_grant_tokens = attr .ib (
159
160
default = attr .Factory (tuple ),
160
161
validator = (deep_iterable (member_validator = instance_of (six .string_types )), value_is_not_a_string ),
@@ -231,7 +232,7 @@ class _AwsKmsDiscoveryKeyring(Keyring):
231
232
:param List[str] grant_tokens: AWS KMS grant tokens to include in requests (optional)
232
233
"""
233
234
234
- _client_supplier = attr .ib (validator = instance_of ( ClientSupplier ))
235
+ _client_supplier = attr .ib (validator = is_callable ( ))
235
236
_grant_tokens = attr .ib (
236
237
default = attr .Factory (tuple ),
237
238
validator = (deep_iterable (member_validator = instance_of (six .string_types )), value_is_not_a_string ),
@@ -261,7 +262,7 @@ def on_decrypt(self, decryption_materials, encrypted_data_keys):
261
262
262
263
263
264
def _try_aws_kms_decrypt (client_supplier , decryption_materials , grant_tokens , encrypted_data_key ):
264
- # type: (ClientSupplier , DecryptionMaterials, Iterable[str], EncryptedDataKey) -> DecryptionMaterials
265
+ # type: (ClientSupplierType , DecryptionMaterials, Iterable[str], EncryptedDataKey) -> DecryptionMaterials
265
266
"""Attempt to call ``kms:Decrypt`` and return the resulting plaintext data key.
266
267
267
268
Any errors encountered are caught and logged.
@@ -291,7 +292,7 @@ def _try_aws_kms_decrypt(client_supplier, decryption_materials, grant_tokens, en
291
292
292
293
293
294
def _do_aws_kms_decrypt (client_supplier , key_name , encrypted_data_key , encryption_context , grant_tokens ):
294
- # type: (ClientSupplier , str, EncryptedDataKey, Dict[str, str], Iterable[str]) -> RawDataKey
295
+ # type: (ClientSupplierType , str, EncryptedDataKey, Dict[str, str], Iterable[str]) -> RawDataKey
295
296
"""Attempt to call ``kms:Decrypt`` and return the resulting plaintext data key.
296
297
297
298
Any errors encountered are passed up the chain without comment.
@@ -318,7 +319,7 @@ def _do_aws_kms_decrypt(client_supplier, key_name, encrypted_data_key, encryptio
318
319
319
320
320
321
def _do_aws_kms_encrypt (client_supplier , key_name , plaintext_data_key , encryption_context , grant_tokens ):
321
- # type: (ClientSupplier , str, RawDataKey, Dict[str, str], Iterable[str]) -> EncryptedDataKey
322
+ # type: (ClientSupplierType , str, RawDataKey, Dict[str, str], Iterable[str]) -> EncryptedDataKey
322
323
"""Attempt to call ``kms:Encrypt`` and return the resulting encrypted data key.
323
324
324
325
Any errors encountered are passed up the chain without comment.
@@ -338,7 +339,7 @@ def _do_aws_kms_encrypt(client_supplier, key_name, plaintext_data_key, encryptio
338
339
339
340
340
341
def _do_aws_kms_generate_data_key (client_supplier , key_name , encryption_context , algorithm , grant_tokens ):
341
- # type: (ClientSupplier , str, Dict[str, str], AlgorithmSuite, Iterable[str]) -> (RawDataKey, EncryptedDataKey)
342
+ # type: (ClientSupplierType , str, Dict[str, str], AlgorithmSuite, Iterable[str]) -> (RawDataKey, EncryptedDataKey)
342
343
"""Attempt to call ``kms:GenerateDataKey`` and return the resulting plaintext and encrypted data keys.
343
344
344
345
Any errors encountered are passed up the chain without comment.
0 commit comments