mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-06 21:33:00 +00:00
Ensure that *everything* is typed in community.crypto (#917)
* Ensure that *everything* is typed in community.crypto. * Fix comment. * Ignore type definitions/imports and AssertionErrors for code coverage.
This commit is contained in:
@@ -18,7 +18,7 @@ from ansible_collections.community.crypto.plugins.module_utils._acme.errors impo
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import (
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import ( # pragma: no cover
|
||||
ACMEClient,
|
||||
)
|
||||
|
||||
|
||||
@@ -49,13 +49,15 @@ from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
import os
|
||||
import http.client # pragma: no cover
|
||||
import os # pragma: no cover
|
||||
import urllib.error # pragma: no cover
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.account import (
|
||||
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.account import ( # pragma: no cover
|
||||
ACMEAccount,
|
||||
)
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import (
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import ( # pragma: no cover
|
||||
CertificateInformation,
|
||||
CryptoBackend,
|
||||
)
|
||||
@@ -68,7 +70,11 @@ RETRY_COUNT = 10
|
||||
|
||||
|
||||
def _decode_retry(
|
||||
*, module: AnsibleModule, response: t.Any, info: dict[str, t.Any], retry_count: int
|
||||
*,
|
||||
module: AnsibleModule,
|
||||
response: urllib.error.HTTPError | http.client.HTTPResponse | None,
|
||||
info: dict[str, t.Any],
|
||||
retry_count: int,
|
||||
) -> bool:
|
||||
if info["status"] not in RETRY_STATUS_CODES:
|
||||
return False
|
||||
@@ -102,7 +108,7 @@ def _decode_retry(
|
||||
def _assert_fetch_url_success(
|
||||
*,
|
||||
module: AnsibleModule,
|
||||
response: t.Any,
|
||||
response: urllib.error.HTTPError | http.client.HTTPResponse | None,
|
||||
info: dict[str, t.Any],
|
||||
allow_redirect: bool = False,
|
||||
allow_client_error: bool = True,
|
||||
@@ -288,7 +294,9 @@ class ACMEClient:
|
||||
In case of an error, raises KeyParsingError.
|
||||
"""
|
||||
if key_file is None and key_content is None:
|
||||
raise AssertionError("One of key_file and key_content must be specified!")
|
||||
raise AssertionError(
|
||||
"One of key_file and key_content must be specified!"
|
||||
) # pragma: no cover
|
||||
return self.backend.parse_key(
|
||||
key_file=key_file, key_content=key_content, passphrase=passphrase
|
||||
)
|
||||
|
||||
@@ -80,10 +80,10 @@ else:
|
||||
)
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
import datetime
|
||||
import datetime # pragma: no cover
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import (
|
||||
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import ( # pragma: no cover
|
||||
CertificateChain,
|
||||
Criterium,
|
||||
)
|
||||
|
||||
@@ -39,8 +39,8 @@ from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import (
|
||||
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import ( # pragma: no cover
|
||||
Criterium,
|
||||
)
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
import os
|
||||
import os # pragma: no cover
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import (
|
||||
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import ( # pragma: no cover
|
||||
ChainMatcher,
|
||||
Criterium,
|
||||
)
|
||||
@@ -132,12 +132,24 @@ class CryptoBackend(metaclass=abc.ABCMeta):
|
||||
start + percentage * (end - start), with_timezone=self._with_timezone
|
||||
)
|
||||
|
||||
def get_utc_datetime(self, *args, **kwargs) -> datetime.datetime:
|
||||
kwargs_ext: dict[str, t.Any] = dict(kwargs)
|
||||
if self._with_timezone and ("tzinfo" not in kwargs_ext and len(args) < 8):
|
||||
kwargs_ext["tzinfo"] = UTC
|
||||
result = datetime.datetime(*args, **kwargs_ext)
|
||||
if self._with_timezone and ("tzinfo" in kwargs or len(args) >= 8):
|
||||
def get_utc_datetime(
|
||||
self,
|
||||
year: int,
|
||||
month: int,
|
||||
day: int,
|
||||
hour: int = 0,
|
||||
minute: int = 0,
|
||||
second: int = 0,
|
||||
microsecond: int = 0,
|
||||
tzinfo: datetime.timezone | None = None,
|
||||
) -> datetime.datetime:
|
||||
has_tzinfo = tzinfo is not None
|
||||
if self._with_timezone and not has_tzinfo:
|
||||
tzinfo = UTC
|
||||
result = datetime.datetime(
|
||||
year, month, day, hour, minute, second, microsecond, tzinfo
|
||||
)
|
||||
if self._with_timezone and has_tzinfo:
|
||||
result = ensure_utc_timezone(result)
|
||||
return result
|
||||
|
||||
|
||||
@@ -37,14 +37,14 @@ from ansible_collections.community.crypto.plugins.module_utils._acme.utils impor
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import (
|
||||
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import ( # pragma: no cover
|
||||
CryptoBackend,
|
||||
)
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import (
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.certificates import ( # pragma: no cover
|
||||
ChainMatcher,
|
||||
)
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.challenges import (
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.challenges import ( # pragma: no cover
|
||||
Challenge,
|
||||
)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ from ansible_collections.community.crypto.plugins.module_utils._crypto.pem impor
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import (
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import ( # pragma: no cover
|
||||
ACMEClient,
|
||||
)
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ from ansible_collections.community.crypto.plugins.module_utils._acme.utils impor
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import (
|
||||
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import ( # pragma: no cover
|
||||
ACMEClient,
|
||||
)
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ from ansible.module_utils.common.text.converters import to_text
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
import http.client # pragma: no cover
|
||||
import urllib.error # pragma: no cover
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||
|
||||
|
||||
def format_http_status(status_code: int) -> str:
|
||||
@@ -59,7 +62,7 @@ class ModuleFailException(Exception):
|
||||
self.msg = msg
|
||||
self.module_fail_args = args
|
||||
|
||||
def do_fail(self, *, module: AnsibleModule, **arguments) -> t.NoReturn:
|
||||
def do_fail(self, *, module: AnsibleModule, **arguments: t.Any) -> t.NoReturn:
|
||||
module.fail_json(msg=self.msg, other=self.module_fail_args, **arguments)
|
||||
|
||||
|
||||
@@ -70,11 +73,11 @@ class ACMEProtocolException(ModuleFailException):
|
||||
module: AnsibleModule,
|
||||
msg: str | None = None,
|
||||
info: dict[str, t.Any] | None = None,
|
||||
response=None,
|
||||
response: urllib.error.HTTPError | http.client.HTTPResponse | None = None,
|
||||
content: bytes | None = None,
|
||||
content_json: object | bytes | None = None,
|
||||
extras: dict[str, t.Any] | None = None,
|
||||
):
|
||||
) -> None:
|
||||
# Try to get hold of content, if response is given and content is not provided
|
||||
if content is None and content_json is None and response is not None:
|
||||
try:
|
||||
|
||||
@@ -21,7 +21,7 @@ from ansible_collections.community.crypto.plugins.module_utils._acme.errors impo
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule # pragma: no cover
|
||||
|
||||
|
||||
def read_file(fn: str | os.PathLike) -> bytes:
|
||||
|
||||
@@ -25,7 +25,7 @@ from ansible_collections.community.crypto.plugins.module_utils._acme.utils impor
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import (
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.acme import ( # pragma: no cover
|
||||
ACMEClient,
|
||||
)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ from ansible_collections.community.crypto.plugins.module_utils._time import (
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import (
|
||||
from ansible_collections.community.crypto.plugins.module_utils._acme.backends import ( # pragma: no cover
|
||||
CertificateInformation,
|
||||
CryptoBackend,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user