From 01ea85d802d00c9a3ccb80594180cce192aeb0ee Mon Sep 17 00:00:00 2001 From: ran Date: Sun, 28 Jul 2013 17:18:53 +0300 Subject: [PATCH 1/2] tomcat.passwd function, convert clear-text password to tomcat-users.xml file --- salt/modules/tomcat.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/salt/modules/tomcat.py b/salt/modules/tomcat.py index 8f0ba31127..c9c62d0748 100644 --- a/salt/modules/tomcat.py +++ b/salt/modules/tomcat.py @@ -42,6 +42,7 @@ Notes: # Import python libs import glob +import hashlib import urllib import urllib2 import tempfile @@ -461,6 +462,37 @@ def deploy_war(war, context, force='no', url='http://localhost:8080/manager', en return res +def passwd(user, passwd, alg='md5', realm=None): + ''' + This function replaces the $CATALINS_HOME/bin/digest.sh script + convert a clear-text password to be hashed in $CATALINA_BASE/conf/tomcat-users.xml file + + CLI Examples:: + + salt '*' tomcat.passwd tomcat secret + salt '*' tomcat.passwd tomcat secret sha1 + salt '*' tomcat.passwd tomcat secret sha1 'Protected Realm' + ''' + + if alg == 'md5': + m = hashlib.md5() + elif alg == 'sha1': + m = hashlib.sha1() + else: + return False + + if realm: + m.update('{0}:{1}:{2}'.format( + user, + realm, + passwd, + )) + else: + m.update(passwd) + + return m.hexdigest() + + # Non-Manager functions def version(): ''' From 7903b5d7856a7adbfe8cefef0ebee0b67c42ac70 Mon Sep 17 00:00:00 2001 From: ran Date: Sun, 28 Jul 2013 17:23:34 +0300 Subject: [PATCH 2/2] docstring fix --- salt/modules/tomcat.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/salt/modules/tomcat.py b/salt/modules/tomcat.py index c9c62d0748..f13a3e391b 100644 --- a/salt/modules/tomcat.py +++ b/salt/modules/tomcat.py @@ -462,16 +462,16 @@ def deploy_war(war, context, force='no', url='http://localhost:8080/manager', en return res -def passwd(user, passwd, alg='md5', realm=None): +def passwd(passwd, user='', alg='md5', realm=None): ''' This function replaces the $CATALINS_HOME/bin/digest.sh script - convert a clear-text password to be hashed in $CATALINA_BASE/conf/tomcat-users.xml file + convert a clear-text password to the $CATALINA_BASE/conf/tomcat-users.xml format CLI Examples:: - salt '*' tomcat.passwd tomcat secret - salt '*' tomcat.passwd tomcat secret sha1 - salt '*' tomcat.passwd tomcat secret sha1 'Protected Realm' + salt '*' tomcat.passwd secret + salt '*' tomcat.passwd secret tomcat sha1 + salt '*' tomcat.passwd secret tomcat sha1 'Protected Realm' ''' if alg == 'md5':