mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-05-07 22:03:01 +00:00
Add type hints and type checking (#885)
* Enable basic type checking. * Fix first errors. * Add changelog fragment. * Add types to module_utils and plugin_utils (without module backends). * Add typing hints for acme_* modules. * Add typing to X.509 certificate modules, and add more helpers. * Add typing to remaining module backends. * Add typing for action, filter, and lookup plugins. * Bump ansible-core 2.19 beta requirement for typing. * Add more typing definitions. * Add typing to some unit tests.
This commit is contained in:
@@ -239,6 +239,7 @@ csr:
|
||||
"""
|
||||
|
||||
import os
|
||||
import typing as t
|
||||
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.basic import (
|
||||
OpenSSLObjectError,
|
||||
@@ -256,9 +257,18 @@ from ansible_collections.community.crypto.plugins.module_utils.io import (
|
||||
)
|
||||
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.community.crypto.plugins.module_utils.crypto.module_backends.csr import (
|
||||
CertificateSigningRequestBackend,
|
||||
)
|
||||
|
||||
|
||||
class CertificateSigningRequestModule(OpenSSLObject):
|
||||
|
||||
def __init__(self, module, module_backend):
|
||||
def __init__(
|
||||
self, module: AnsibleModule, module_backend: CertificateSigningRequestBackend
|
||||
) -> None:
|
||||
super(CertificateSigningRequestModule, self).__init__(
|
||||
module.params["path"],
|
||||
module.params["state"],
|
||||
@@ -269,11 +279,11 @@ class CertificateSigningRequestModule(OpenSSLObject):
|
||||
self.return_content = module.params["return_content"]
|
||||
|
||||
self.backup = module.params["backup"]
|
||||
self.backup_file = None
|
||||
self.backup_file: str | None = None
|
||||
|
||||
self.module_backend.set_existing(load_file_if_exists(self.path, module))
|
||||
|
||||
def generate(self, module):
|
||||
def generate(self, module: AnsibleModule) -> None:
|
||||
"""Generate the certificate signing request."""
|
||||
if self.force or self.module_backend.needs_regeneration():
|
||||
if not self.check_mode:
|
||||
@@ -292,13 +302,13 @@ class CertificateSigningRequestModule(OpenSSLObject):
|
||||
file_args, self.changed
|
||||
)
|
||||
|
||||
def remove(self, module):
|
||||
def remove(self, module: AnsibleModule) -> None:
|
||||
self.module_backend.set_existing(None)
|
||||
if self.backup and not self.check_mode:
|
||||
self.backup_file = module.backup_local(self.path)
|
||||
super(CertificateSigningRequestModule, self).remove(module)
|
||||
|
||||
def dump(self):
|
||||
def dump(self) -> dict[str, t.Any]:
|
||||
"""Serialize the object into a dictionary."""
|
||||
result = self.module_backend.dump(include_csr=self.return_content)
|
||||
result.update(
|
||||
@@ -312,7 +322,7 @@ class CertificateSigningRequestModule(OpenSSLObject):
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> t.NoReturn:
|
||||
argument_spec = get_csr_argument_spec()
|
||||
argument_spec.argument_spec.update(
|
||||
dict(
|
||||
|
||||
Reference in New Issue
Block a user