Skip to content

Commit c92fe2a

Browse files
fix
1 parent 37dd008 commit c92fe2a

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

src/aws_encryption_sdk/internal/deprecation.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33

44
def deprecated(reason):
55
def decorator(cls):
6-
@functools.wraps(cls)
7-
def new_cls(*args, **kwargs):
8-
warnings.warn(f"{cls.__name__} is deprecated: {reason}", category=DeprecationWarning, stacklevel=2)
9-
return cls(*args, **kwargs)
10-
return new_cls
6+
# Define a new constructor that issues a deprecation warning
7+
@functools.wraps(cls.__init__)
8+
def new_init(self, *args, **kwargs):
9+
warnings.warn(f"{cls.__name__} is deprecated: {reason}",
10+
category=DeprecationWarning, stacklevel=2)
11+
cls.__init__(self, *args, **kwargs)
12+
# Update the constructor of the class
13+
cls.__init__ = new_init
14+
return cls
1115
return decorator

src/aws_encryption_sdk/key_providers/base.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@
3131

3232
_LOGGER = logging.getLogger(__name__)
3333

34-
35-
@attr.s(hash=True)
3634
@deprecated("Use keyrings from the aws-cryptographic-material-providers library.")
35+
@attr.s(hash=True)
3736
class MasterKeyProviderConfig(object):
3837
"""Provides a common ancestor for MasterKeyProvider configuration objects
3938
and a stand-in point if common params are needed later.
4039
"""
4140

42-
43-
@six.add_metaclass(abc.ABCMeta)
4441
@deprecated("Use keyrings from the aws-cryptographic-material-providers library.")
42+
@six.add_metaclass(abc.ABCMeta)
4543
class MasterKeyProvider(object):
4644
"""Parent interface for Master Key Provider classes.
4745
@@ -326,9 +324,8 @@ def decrypt_data_key_from_list(self, encrypted_data_keys, algorithm, encryption_
326324
raise DecryptKeyError("Unable to decrypt any data key")
327325
return data_key
328326

329-
330-
@attr.s(hash=True)
331327
@deprecated("Use keyrings from the aws-cryptographic-material-providers library.")
328+
@attr.s(hash=True)
332329
class MasterKeyConfig(object):
333330
"""Configuration object for MasterKey objects.
334331
@@ -344,9 +341,8 @@ def __attrs_post_init__(self):
344341
if not hasattr(self, "provider_id"):
345342
raise TypeError('Instances of MasterKeyConfig must have a "provider_id" attribute defined.')
346343

347-
348-
@six.add_metaclass(abc.ABCMeta)
349344
@deprecated("Use keyrings from the aws-cryptographic-material-providers library.")
345+
@six.add_metaclass(abc.ABCMeta)
350346
class MasterKey(MasterKeyProvider):
351347
"""Parent interface for Master Key classes.
352348

src/aws_encryption_sdk/key_providers/kms.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ class DiscoveryFilter(object):
142142
)
143143
partition = attr.ib(default=None, hash=True, validator=attr.validators.optional(attr.validators.instance_of(str)))
144144

145-
146-
@attr.s(hash=True)
147145
@deprecated("Use KMS keyrings from the aws-cryptographic-material-providers library.")
146+
@attr.s(hash=True)
148147
class KMSMasterKeyConfig(MasterKeyConfig):
149148
"""Configuration object for KMSMasterKey objects.
150149
@@ -384,9 +383,8 @@ def _validate_allowed_to_decrypt(self, edk_key_id):
384383
"provider's key_id={}".format(edk_key_id, self._key_id)
385384
)
386385

387-
388-
@attr.s(hash=True)
389386
@deprecated("Use KMS MRK keyrings from the aws-cryptographic-material-providers library.")
387+
@attr.s(hash=True)
390388
class MRKAwareKMSMasterKeyConfig(MasterKeyConfig):
391389
"""Configuration object for MRKAwareKMSMasterKey objects. Mostly the same as KMSMasterKey, except the
392390
client parameter is required rather than optional.
@@ -518,9 +516,8 @@ def owns_data_key(self, data_key):
518516
return True
519517
return False
520518

521-
522-
@attr.s(hash=True)
523519
@deprecated("Use KMS keyrings from the aws-cryptographic-material-providers library.")
520+
@attr.s(hash=True)
524521
class KMSMasterKeyProviderConfig(MasterKeyProviderConfig):
525522
"""Configuration object for KMSMasterKeyProvider objects.
526523
@@ -555,9 +552,8 @@ class KMSMasterKeyProviderConfig(MasterKeyProviderConfig):
555552
hash=True, default=None, validator=attr.validators.optional(attr.validators.instance_of(six.string_types))
556553
)
557554

558-
559-
@six.add_metaclass(abc.ABCMeta)
560555
@deprecated("Use KMS keyrings from the aws-cryptographic-material-providers library.")
556+
@six.add_metaclass(abc.ABCMeta)
561557
class BaseKMSMasterKeyProvider(MasterKeyProvider):
562558
"""Master Key Provider for KMS.
563559

src/aws_encryption_sdk/key_providers/raw.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828

2929
_LOGGER = logging.getLogger(__name__)
3030

31-
32-
@attr.s(hash=True)
3331
@deprecated("Use raw keyrings from the aws-cryptographic-material-providers library.")
32+
@attr.s(hash=True)
3433
class RawMasterKeyConfig(MasterKeyConfig):
3534
"""Configuration object for RawMasterKey objects.
3635
@@ -190,9 +189,8 @@ def _decrypt_data_key(self, encrypted_data_key, algorithm, encryption_context):
190189
encrypted_data_key=encrypted_data_key.encrypted_data_key,
191190
)
192191

193-
194-
@six.add_metaclass(abc.ABCMeta)
195192
@deprecated("Use raw keyrings from the aws-cryptographic-material-providers library.")
193+
@six.add_metaclass(abc.ABCMeta)
196194
class RawMasterKeyProvider(MasterKeyProvider):
197195
"""Raw Master Key Provider.
198196

0 commit comments

Comments
 (0)