diff options
author | Robert Gogolok <gogo@cs.uni-sb.de> | 2008-01-09 22:08:01 +0000 |
---|---|---|
committer | Robert Gogolok <gogo@cs.uni-sb.de> | 2008-01-09 22:08:01 +0000 |
commit | f5adadec0bf8467c79a5b61d129e8e733f330906 (patch) | |
tree | 533bd85dfe4508ed1b386240cf738a28a8407777 /src/lib/Server/Admin/Init.py | |
parent | f7b1b5f0e9055324005ea9003fb8474ec1d08f18 (diff) | |
download | bcfg2-f5adadec0bf8467c79a5b61d129e8e733f330906.tar.gz bcfg2-f5adadec0bf8467c79a5b61d129e8e733f330906.tar.bz2 bcfg2-f5adadec0bf8467c79a5b61d129e8e733f330906.zip |
bcfg-admin init: generate random password if no password specified
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4228 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Admin/Init.py')
-rw-r--r-- | src/lib/Server/Admin/Init.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py index 048a65647..0a1c631c8 100644 --- a/src/lib/Server/Admin/Init.py +++ b/src/lib/Server/Admin/Init.py @@ -1,4 +1,4 @@ -import getpass, os, socket +import getpass, os, random, socket, string import Bcfg2.Server.Admin import Bcfg2.Options @@ -95,12 +95,11 @@ class Init(Bcfg2.Server.Admin.Mode): if repopath == '': repopath = opts['repo'] - password = '' - while ( password == '' ): - password = getpass.getpass( + password = getpass.getpass( "Input password used for communication verification " - "(without echoing): " - ) + "(without echoing; leave blank for a random): ") + if len(password.strip()) == 0: + password = self.genPassword() server = "https://%s:6789" % socket.getfqdn() rs = raw_input( "Input the server location [%s]: " % server) @@ -116,6 +115,13 @@ class Init(Bcfg2.Server.Admin.Mode): self.initializeRepo(configfile, repopath, server, password, os_sel, opts) print "Repository created successfuly in %s" % (repopath) + def genPassword(self): + chars = string.letters + string.digits + newpasswd = '' + for i in range(8): + newpasswd = newpasswd + random.choice(chars) + return newpasswd + def initializeRepo(self, configfile, repo, server_uri, password, os_selection, opts): '''Setup a new repo''' keypath = os.path.dirname(os.path.abspath(configfile)) |