From 9e998d645e1e9a83de6067267f656a3711dcee63 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky Date: Mon, 3 Jul 2023 23:19:19 +1200 Subject: [PATCH 1/4] htpasswd: rename crypt_scheme with hash_scheme --- plugins/modules/htpasswd.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/modules/htpasswd.py b/plugins/modules/htpasswd.py index 25911a001fe..31ea56c16bd 100644 --- a/plugins/modules/htpasswd.py +++ b/plugins/modules/htpasswd.py @@ -39,12 +39,12 @@ description: - Password associated with user. - Must be specified if user does not exist yet. - crypt_scheme: + hash_scheme: type: str required: false default: "apr_md5_crypt" description: - - Encryption scheme to be used. As well as the four choices listed + - Hashing scheme to be used. As well as the four choices listed here, you can also use any other hash supported by passlib, such as V(portable_apache22) and V(host_apache24); or V(md5_crypt) and V(sha256_crypt), which are Linux passwd hashes. Only some schemes in addition to @@ -52,6 +52,7 @@ supported schemes depend on passlib version and its dependencies. - See U(https://passlib.readthedocs.io/en/stable/lib/passlib.apache.html#passlib.apache.HtpasswdFile) parameter C(default_scheme). - 'Some of the available choices might be: V(apr_md5_crypt), V(des_crypt), V(ldap_sha1), V(plaintext).' + aliases: [crypt_scheme] state: type: str required: false @@ -215,7 +216,7 @@ def main(): path=dict(type='path', required=True, aliases=["dest", "destfile"]), name=dict(type='str', required=True, aliases=["username"]), password=dict(type='str', required=False, default=None, no_log=True), - crypt_scheme=dict(type='str', required=False, default="apr_md5_crypt"), + hash_scheme=dict(type='str', required=False, default="apr_md5_crypt", aliases=["crypt_scheme"]), state=dict(type='str', required=False, default="present", choices=["present", "absent"]), create=dict(type='bool', default=True), From cc65ad4b0e785adaf98f496e5f3af691d50273fc Mon Sep 17 00:00:00 2001 From: Alexei Znamensky Date: Mon, 3 Jul 2023 23:26:23 +1200 Subject: [PATCH 2/4] add changelog frag --- changelogs/fragments/6841-htpasswd-crypt-scheme.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/fragments/6841-htpasswd-crypt-scheme.yml diff --git a/changelogs/fragments/6841-htpasswd-crypt-scheme.yml b/changelogs/fragments/6841-htpasswd-crypt-scheme.yml new file mode 100644 index 00000000000..22e80019c45 --- /dev/null +++ b/changelogs/fragments/6841-htpasswd-crypt-scheme.yml @@ -0,0 +1,4 @@ +minor_changes: + - htpasswd - the parameter ``crypt_scheme`` is being renamed as ``hash_scheme`` and added as an alias to it (https://github.com/ansible-collections/community.general/pull/6841). +deprecated_features: + - htpasswd - the alias ``crypt_scheme`` is being deprecated and it shoudl be removed in community.general 9.0.0 (https://github.com/ansible-collections/community.general/pull/6841). From 7cb6e81f0e3508013a54f63ed66bfe9ef2d659bd Mon Sep 17 00:00:00 2001 From: Alexei Znamensky Date: Tue, 4 Jul 2023 08:17:32 +1200 Subject: [PATCH 3/4] fixed chglog frag --- changelogs/fragments/6841-htpasswd-crypt-scheme.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/changelogs/fragments/6841-htpasswd-crypt-scheme.yml b/changelogs/fragments/6841-htpasswd-crypt-scheme.yml index 22e80019c45..cfa416419c0 100644 --- a/changelogs/fragments/6841-htpasswd-crypt-scheme.yml +++ b/changelogs/fragments/6841-htpasswd-crypt-scheme.yml @@ -1,4 +1,2 @@ minor_changes: - htpasswd - the parameter ``crypt_scheme`` is being renamed as ``hash_scheme`` and added as an alias to it (https://github.com/ansible-collections/community.general/pull/6841). -deprecated_features: - - htpasswd - the alias ``crypt_scheme`` is being deprecated and it shoudl be removed in community.general 9.0.0 (https://github.com/ansible-collections/community.general/pull/6841). From 5a526d15f00cf957c1faeb0a270ef30c782ab91d Mon Sep 17 00:00:00 2001 From: Alexei Znamensky Date: Wed, 5 Jul 2023 21:30:01 +1200 Subject: [PATCH 4/4] adjusted code for parameter name change --- plugins/modules/htpasswd.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/modules/htpasswd.py b/plugins/modules/htpasswd.py index 31ea56c16bd..ed510991a49 100644 --- a/plugins/modules/htpasswd.py +++ b/plugins/modules/htpasswd.py @@ -100,7 +100,7 @@ path: /etc/mail/passwords name: alex password: oedu2eGh - crypt_scheme: md5_crypt + hash_scheme: md5_crypt """ @@ -132,14 +132,14 @@ def create_missing_directories(dest): os.makedirs(destpath) -def present(dest, username, password, crypt_scheme, create, check_mode): +def present(dest, username, password, hash_scheme, create, check_mode): """ Ensures user is present Returns (msg, changed) """ - if crypt_scheme in apache_hashes: + if hash_scheme in apache_hashes: context = htpasswd_context else: - context = CryptContext(schemes=[crypt_scheme] + apache_hashes) + context = CryptContext(schemes=[hash_scheme] + apache_hashes) if not os.path.exists(dest): if not create: raise ValueError('Destination %s does not exist' % dest) @@ -147,9 +147,9 @@ def present(dest, username, password, crypt_scheme, create, check_mode): return ("Create %s" % dest, True) create_missing_directories(dest) if LooseVersion(passlib.__version__) >= LooseVersion('1.6'): - ht = HtpasswdFile(dest, new=True, default_scheme=crypt_scheme, context=context) + ht = HtpasswdFile(dest, new=True, default_scheme=hash_scheme, context=context) else: - ht = HtpasswdFile(dest, autoload=False, default=crypt_scheme, context=context) + ht = HtpasswdFile(dest, autoload=False, default=hash_scheme, context=context) if getattr(ht, 'set_password', None): ht.set_password(username, password) else: @@ -158,9 +158,9 @@ def present(dest, username, password, crypt_scheme, create, check_mode): return ("Created %s and added %s" % (dest, username), True) else: if LooseVersion(passlib.__version__) >= LooseVersion('1.6'): - ht = HtpasswdFile(dest, new=False, default_scheme=crypt_scheme, context=context) + ht = HtpasswdFile(dest, new=False, default_scheme=hash_scheme, context=context) else: - ht = HtpasswdFile(dest, default=crypt_scheme, context=context) + ht = HtpasswdFile(dest, default=hash_scheme, context=context) found = None if getattr(ht, 'check_password', None): @@ -228,7 +228,7 @@ def main(): path = module.params['path'] username = module.params['name'] password = module.params['password'] - crypt_scheme = module.params['crypt_scheme'] + hash_scheme = module.params['hash_scheme'] state = module.params['state'] create = module.params['create'] check_mode = module.check_mode @@ -268,7 +268,7 @@ def main(): try: if state == 'present': - (msg, changed) = present(path, username, password, crypt_scheme, create, check_mode) + (msg, changed) = present(path, username, password, hash_scheme, create, check_mode) elif state == 'absent': if not os.path.exists(path): module.exit_json(msg="%s not present" % username,