mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-14 16:05:04 +00:00
[PR #11222/c7f6a28d backport][stable-12] Add basic typing for module_utils (#11243)
Add basic typing for module_utils (#11222) * Add basic typing for module_utils. * Apply some suggestions. * Make pass again. * Add more types as suggested. * Normalize extra imports. * Add more type hints. * Improve typing. * Add changelog fragment. * Reduce changelog. * Apply suggestions from code review. * Fix typo. * Cleanup. * Improve types and make type checking happy. * Let's see whether older Pythons barf on this. * Revert "Let's see whether older Pythons barf on this." This reverts commit9973af3dbe. * Add noqa. --------- (cherry picked from commitc7f6a28d89) Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
a2c7f9f89a
commit
377a599372
56 changed files with 725 additions and 469 deletions
|
|
@ -9,6 +9,10 @@ from __future__ import annotations
|
|||
|
||||
import re
|
||||
import traceback
|
||||
import typing as t
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
try:
|
||||
import ldap
|
||||
|
|
@ -26,7 +30,7 @@ except ImportError:
|
|||
HAS_LDAP = False
|
||||
|
||||
|
||||
def gen_specs(**specs):
|
||||
def gen_specs(**specs: t.Any) -> dict[str, t.Any]:
|
||||
specs.update(
|
||||
{
|
||||
"bind_dn": dict(),
|
||||
|
|
@ -47,12 +51,12 @@ def gen_specs(**specs):
|
|||
return specs
|
||||
|
||||
|
||||
def ldap_required_together():
|
||||
def ldap_required_together() -> list[list[str]]:
|
||||
return [["client_cert", "client_key"]]
|
||||
|
||||
|
||||
class LdapGeneric:
|
||||
def __init__(self, module):
|
||||
def __init__(self, module: AnsibleModule) -> None:
|
||||
# Shortcuts
|
||||
self.module = module
|
||||
self.bind_dn = self.module.params["bind_dn"]
|
||||
|
|
@ -76,11 +80,11 @@ class LdapGeneric:
|
|||
else:
|
||||
self.dn = self.module.params["dn"]
|
||||
|
||||
def fail(self, msg, exn):
|
||||
def fail(self, msg: str, exn: str | Exception) -> t.NoReturn:
|
||||
self.module.fail_json(msg=msg, details=f"{exn}", exception=traceback.format_exc())
|
||||
|
||||
def _find_dn(self):
|
||||
dn = self.module.params["dn"]
|
||||
def _find_dn(self) -> str:
|
||||
dn: str = self.module.params["dn"]
|
||||
|
||||
explode_dn = ldap.dn.explode_dn(dn)
|
||||
|
||||
|
|
@ -130,7 +134,7 @@ class LdapGeneric:
|
|||
|
||||
return connection
|
||||
|
||||
def _xorder_dn(self):
|
||||
def _xorder_dn(self) -> bool:
|
||||
# match X_ORDERed DNs
|
||||
regex = r".+\{\d+\}.+"
|
||||
explode_dn = ldap.dn.explode_dn(self.module.params["dn"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue