deprecate more attributes in acme (#9369)

* deprecate more attributes in acme

* Deprecate .Authorization.combinations by renaming the field and
  deprecating in getters/setters

* Silence deprecation warnings from our own imports of acme.mixins

Co-authored-by: Brad Warren <bmw@users.noreply.github.com>
This commit is contained in:
alexzorin
2022-08-30 14:41:53 -07:00
committed by GitHub
co-authored by Brad Warren
parent f9d148be56
commit f7e61edcb2
6 changed files with 67 additions and 8 deletions
+6 -2
View File
@@ -14,6 +14,7 @@ from typing import Tuple
from typing import Type from typing import Type
from typing import TypeVar from typing import TypeVar
from typing import Union from typing import Union
import warnings
from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hashes
import josepy as jose import josepy as jose
@@ -24,8 +25,11 @@ import requests
from acme import crypto_util from acme import crypto_util
from acme import errors from acme import errors
from acme import fields from acme import fields
from acme.mixins import ResourceMixin
from acme.mixins import TypeMixin with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
from acme.mixins import ResourceMixin
from acme.mixins import TypeMixin
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
+7 -2
View File
@@ -45,7 +45,9 @@ from acme import crypto_util
from acme import errors from acme import errors
from acme import jws from acme import jws
from acme import messages from acme import messages
from acme.mixins import VersionedLEACMEMixin with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
from acme.mixins import VersionedLEACMEMixin
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -57,6 +59,9 @@ DER_CONTENT_TYPE = 'application/pkix-cert'
class ClientBase: class ClientBase:
"""ACME client base object. """ACME client base object.
.. deprecated:: 1.30.0
Use `ClientV2` instead.
:ivar messages.Directory directory: :ivar messages.Directory directory:
:ivar .ClientNetwork net: Client network. :ivar .ClientNetwork net: Client network.
:ivar int acme_version: ACME protocol version. 1 or 2. :ivar int acme_version: ACME protocol version. 1 or 2.
@@ -1312,7 +1317,7 @@ class _ClientDeprecationModule:
self.__dict__['_module'] = module self.__dict__['_module'] = module
def __getattr__(self, attr: str) -> Any: def __getattr__(self, attr: str) -> Any:
if attr in ('Client', 'BackwardsCompatibleClientV2'): if attr in ('Client', 'ClientBase', 'BackwardsCompatibleClientV2'):
warnings.warn('The {0} attribute in acme.client is deprecated ' warnings.warn('The {0} attribute in acme.client is deprecated '
'and will be removed soon.'.format(attr), 'and will be removed soon.'.format(attr),
DeprecationWarning, stacklevel=2) DeprecationWarning, stacklevel=2)
+41 -4
View File
@@ -14,6 +14,7 @@ from typing import Type
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import TypeVar from typing import TypeVar
from typing import Union from typing import Union
import warnings
import josepy as jose import josepy as jose
@@ -22,7 +23,9 @@ from acme import errors
from acme import fields from acme import fields
from acme import jws from acme import jws
from acme import util from acme import util
from acme.mixins import ResourceMixin with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
from acme.mixins import ResourceMixin
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Protocol # pragma: no cover from typing_extensions import Protocol # pragma: no cover
@@ -573,14 +576,14 @@ class Authorization(ResourceBody):
:ivar acme.messages.Identifier identifier: :ivar acme.messages.Identifier identifier:
:ivar list challenges: `list` of `.ChallengeBody` :ivar list challenges: `list` of `.ChallengeBody`
:ivar tuple combinations: Challenge combinations (`tuple` of `tuple` :ivar tuple combinations: Challenge combinations (`tuple` of `tuple`
of `int`, as opposed to `list` of `list` from the spec). of `int`, as opposed to `list` of `list` from the spec). (deprecated since 1.30.0)
:ivar acme.messages.Status status: :ivar acme.messages.Status status:
:ivar datetime.datetime expires: :ivar datetime.datetime expires:
""" """
identifier: Identifier = jose.field('identifier', decoder=Identifier.from_json, omitempty=True) identifier: Identifier = jose.field('identifier', decoder=Identifier.from_json, omitempty=True)
challenges: List[ChallengeBody] = jose.field('challenges', omitempty=True) challenges: List[ChallengeBody] = jose.field('challenges', omitempty=True)
combinations: Tuple[Tuple[int, ...], ...] = jose.field('combinations', omitempty=True) _combinations: Tuple[Tuple[int, ...], ...] = jose.field('combinations', omitempty=True)
status: Status = jose.field('status', omitempty=True, decoder=Status.from_json) status: Status = jose.field('status', omitempty=True, decoder=Status.from_json)
# TODO: 'expires' is allowed for Authorization Resources in # TODO: 'expires' is allowed for Authorization Resources in
@@ -590,15 +593,49 @@ class Authorization(ResourceBody):
expires: datetime.datetime = fields.rfc3339('expires', omitempty=True) expires: datetime.datetime = fields.rfc3339('expires', omitempty=True)
wildcard: bool = jose.field('wildcard', omitempty=True) wildcard: bool = jose.field('wildcard', omitempty=True)
# combinations is temporarily renamed to _combinations during its deprecation
# period. See https://github.com/certbot/certbot/pull/9369#issuecomment-1199849262.
def __init__(self, **kwargs: Any) -> None:
if 'combinations' in kwargs:
kwargs['_combinations'] = kwargs.pop('combinations')
super().__init__(**kwargs)
# Mypy does not understand the josepy magic happening here, and falsely claims # Mypy does not understand the josepy magic happening here, and falsely claims
# that challenge is redefined. Let's ignore the type check here. # that challenge is redefined. Let's ignore the type check here.
@challenges.decoder # type: ignore @challenges.decoder # type: ignore
def challenges(value: List[Dict[str, Any]]) -> Tuple[ChallengeBody, ...]: # type: ignore[misc] # pylint: disable=no-self-argument,missing-function-docstring def challenges(value: List[Dict[str, Any]]) -> Tuple[ChallengeBody, ...]: # type: ignore[misc] # pylint: disable=no-self-argument,missing-function-docstring
return tuple(ChallengeBody.from_json(chall) for chall in value) return tuple(ChallengeBody.from_json(chall) for chall in value)
@property
def combinations(self) -> Tuple[Tuple[int, ...], ...]:
"""Challenge combinations.
(`tuple` of `tuple` of `int`, as opposed to `list` of `list` from the spec).
.. deprecated: 1.30.0
"""
warnings.warn(
"acme.messages.Authorization.combinations is deprecated and will be "
"removed in a future release.", DeprecationWarning)
return self._combinations
@combinations.setter
def combinations(self, combos: Tuple[Tuple[int, ...], ...]) -> None: # pragma: no cover
warnings.warn(
"acme.messages.Authorization.combinations is deprecated and will be "
"removed in a future release.", DeprecationWarning)
self._combinations = combos
@property @property
def resolved_combinations(self) -> Tuple[Tuple[ChallengeBody, ...], ...]: def resolved_combinations(self) -> Tuple[Tuple[ChallengeBody, ...], ...]:
"""Combinations with challenges instead of indices.""" """Combinations with challenges instead of indices.
.. deprecated: 1.30.0
"""
warnings.warn(
"acme.messages.Authorization.resolved_combinations is deprecated and will be "
"removed in a future release.", DeprecationWarning)
return tuple(tuple(self.challenges[idx] for idx in combo) return tuple(tuple(self.challenges[idx] for idx in combo)
for combo in self.combinations) # pylint: disable=not-an-iterable for combo in self.combinations) # pylint: disable=not-an-iterable
+4
View File
@@ -1,6 +1,10 @@
"""Useful mixins for Challenge and Resource objects""" """Useful mixins for Challenge and Resource objects"""
from typing import Any from typing import Any
from typing import Dict from typing import Dict
import warnings
warnings.warn(f'The module {__name__} is deprecated and will be removed in a future release',
DeprecationWarning, stacklevel=2)
class VersionedLEACMEMixin: class VersionedLEACMEMixin:
+3
View File
@@ -10,6 +10,9 @@ Certbot adheres to [Semantic Versioning](https://semver.org/).
### Changed ### Changed
* `acme.client.ClientBase`, `acme.messages.Authorization.resolved_combinations`,
`acme.messages.Authorization.combinations` and `acme.mixins` are deprecated and
will be removed in a future release.
* The `certbot-dns-cloudxns` plugin is now deprecated and will be removed in the * The `certbot-dns-cloudxns` plugin is now deprecated and will be removed in the
next major release of Certbot. next major release of Certbot.
* The `source_address` argument for `acme.client.ClientNetwork` is deprecated * The `source_address` argument for `acme.client.ClientNetwork` is deprecated
+6
View File
@@ -24,6 +24,9 @@
# certbot-dns-rfc2136. # certbot-dns-rfc2136.
# 6) botocore is currently using deprecated urllib3 functionality. See # 6) botocore is currently using deprecated urllib3 functionality. See
# https://github.com/boto/botocore/issues/2744. # https://github.com/boto/botocore/issues/2744.
# 7) ACMEv1 deprecations in acme.client which will be resolved by Certbot 2.0.
# 8) acme.mixins deprecation in acme.client which will be resolved by Certbot 2.0.
# 9) acme.messages.Authorization.combinations which will be resolved by Certbot 2.0.
filterwarnings = filterwarnings =
error error
ignore:The external mock module:PendingDeprecationWarning ignore:The external mock module:PendingDeprecationWarning
@@ -32,3 +35,6 @@ filterwarnings =
ignore:.*attribute in certbot.display.util module is deprecated:DeprecationWarning ignore:.*attribute in certbot.display.util module is deprecated:DeprecationWarning
ignore:decodestring\(\) is a deprecated alias:DeprecationWarning:dns ignore:decodestring\(\) is a deprecated alias:DeprecationWarning:dns
ignore:'urllib3.contrib.pyopenssl:DeprecationWarning:botocore ignore:'urllib3.contrib.pyopenssl:DeprecationWarning:botocore
ignore:.*attribute in acme.client is deprecated:DeprecationWarning
ignore:.*acme.mixins is deprecated:DeprecationWarning
ignore:.*Authorization.combinations is deprecated:DeprecationWarning