[cwc shell] add ``--password`` option to ``reset-admin-pwd`` (close #1794866) stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Fri, 01 Jul 2011 11:27:20 +0200
branchstable
changeset 7594 d177c0755b10
parent 7593 0c1024b3e7fc
child 7595 83872394b5d9
child 7596 f3cdf1694c92
[cwc shell] add ``--password`` option to ``reset-admin-pwd`` (close #1794866) This will help batch. The help warn it's not very secure.
server/serverctl.py
--- a/server/serverctl.py	Fri Jul 01 11:19:12 2011 +0200
+++ b/server/serverctl.py	Fri Jul 01 11:27:20 2011 +0200
@@ -560,6 +560,15 @@
     """
     name = 'reset-admin-pwd'
     arguments = '<instance>'
+    options = (
+        ('password',
+         {'short': 'p', 'type' : 'string', 'metavar' : '<new-password>',
+          'default' : None,
+          'help': 'Use this password instead of prompt for one.\n'
+                  '/!\ THIS IS AN INSECURE PRACTICE /!\ \n'
+                  'the password will appear in shell history'}
+         ),
+        )
 
     def run(self, args):
         """run the command with its specific arguments"""
@@ -586,15 +595,18 @@
             print "   fix your sources file before running this command"
             cnx.close()
             sys.exit(1)
-        # ask for a new password
-        _, passwd = manager_userpasswd(adminlogin, confirm=True,
-                                       passwdmsg='new password for %s' % adminlogin)
+        if self.config.password is None:
+            # ask for a new password
+            msg = 'new password for %s' % adminlogin
+            _, pwd = manager_userpasswd(adminlogin, confirm=True, passwdmsg=msg)
+        else:
+            pwd = self.config.password
         try:
             cursor.execute("UPDATE cw_CWUser SET cw_upassword=%(p)s WHERE cw_login=%(l)s",
-                           {'p': dbhelper.binary_value(crypt_password(passwd)), 'l': adminlogin})
+                           {'p': dbhelper.binary_value(crypt_password(pwd)), 'l': adminlogin})
             sconfig = Configuration(options=USER_OPTIONS)
             sconfig['login'] = adminlogin
-            sconfig['password'] = passwd
+            sconfig['password'] = pwd
             sourcescfg['admin'] = sconfig
             config.write_sources_file(sourcescfg)
         except Exception, ex: