From 2cee2e5379cbbf010839b31007b20199d7cb984c Mon Sep 17 00:00:00 2001 From: Stoned Elipot Date: Fri, 4 Oct 2013 03:18:17 +0200 Subject: [PATCH] Fix compatibility issue with passlib version < 1.6 (as encountered on eg EL6 systems) - passlib.apache.HtpasswdFile's 'default_scheme' was called 'default' before passlib version 1.6 - while here also deal with passlib.apache.HtpasswdFile's older 'autoload' paramter vs the newer 'new' one. --- web_infrastructure/htpasswd | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/web_infrastructure/htpasswd b/web_infrastructure/htpasswd index adcc8566bc4..a634fb62737 100644 --- a/web_infrastructure/htpasswd +++ b/web_infrastructure/htpasswd @@ -76,9 +76,11 @@ EXAMPLES = """ import os +from distutils.version import StrictVersion try: from passlib.apache import HtpasswdFile + import passlib except ImportError: passlib_installed = False else: @@ -101,14 +103,10 @@ def present(dest, username, password, crypt_scheme, create, check_mode): if check_mode: return ("Create %s" % dest, True) create_missing_directories(dest) - try: + if StrictVersion(passlib.__version__) >= StrictVersion('1.6'): ht = HtpasswdFile(dest, new=True, default_scheme=crypt_scheme) - except: - # library version doesn't take 'new', deal with it. - fh = open(dest, 'w') - fh.write('') - fh.close() - ht = HtpasswdFile(dest, default_scheme=crypt_scheme) + else: + ht = HtpasswdFile(dest, autoload=False, default=crypt_scheme) if getattr(ht, 'set_password', None): ht.set_password(username, password) else: @@ -116,10 +114,10 @@ def present(dest, username, password, crypt_scheme, create, check_mode): ht.save() return ("Created %s and added %s" % (dest, username), True) else: - try: + if StrictVersion(passlib.__version__) >= StrictVersion('1.6'): ht = HtpasswdFile(dest, new=False, default_scheme=crypt_scheme) - except: - ht = HtpasswdFile(dest, default_scheme=crypt_scheme) + else: + ht = HtpasswdFile(dest, default=crypt_scheme) found = None if getattr(ht, 'check_password', None): @@ -146,9 +144,9 @@ def absent(dest, username, check_mode): if not os.path.exists(dest): raise ValueError("%s does not exists" % dest) - try: + if StrictVersion(passlib.__version__) >= StrictVersion('1.6'): ht = HtpasswdFile(dest, new=False) - except: + else: ht = HtpasswdFile(dest) if username not in ht.users():