[PR #8497/f0940d82 backport][stable-9] homectl, udm_user: guard crypt imports (#8499)

homectl, udm_user: guard crypt imports (#8497)

Guard crypt import.

(cherry picked from commit f0940d82dc)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2024-06-13 22:01:33 +02:00 committed by GitHub
parent f905a1bc94
commit f84ebed63f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 50 additions and 4 deletions

View file

@ -20,6 +20,12 @@ description:
- "This module allows to manage posix users on a univention corporate
server (UCS).
It uses the python API of the UCS to create a new object or edit it."
notes:
- This module does B(not) work with Python 3.13 or newer. It uses the deprecated L(crypt Python module,
https://docs.python.org/3.12/library/crypt.html) from the Python standard library, which was removed
from Python 3.13.
requirements:
- Python 3.12 or earlier
extends_documentation_fragment:
- community.general.attributes
attributes:
@ -324,10 +330,10 @@ EXAMPLES = '''
RETURN = '''# '''
import crypt
from datetime import date, timedelta
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible_collections.community.general.plugins.module_utils.univention_umc import (
umc_module_for_add,
umc_module_for_edit,
@ -335,6 +341,15 @@ from ansible_collections.community.general.plugins.module_utils.univention_umc i
base_dn,
)
try:
import crypt
except ImportError:
HAS_CRYPT = False
CRYPT_IMPORT_ERROR = traceback.format_exc()
else:
HAS_CRYPT = True
CRYPT_IMPORT_ERROR = None
def main():
expiry = date.strftime(date.today() + timedelta(days=365), "%Y-%m-%d")
@ -451,6 +466,13 @@ def main():
('state', 'present', ['firstname', 'lastname', 'password'])
])
)
if not HAS_CRYPT:
module.fail_json(
msg=missing_required_lib('crypt (part of Python 3.13 standard library)'),
exception=CRYPT_IMPORT_ERROR,
)
username = module.params['username']
position = module.params['position']
ou = module.params['ou']