#!/usr/bin/env python ############################################################################## ### Copyright Sun Microsystems, Inc. ALL RIGHTS RESERVED ### Use of this software is authorized pursuant to the ### terms of the license found at ### http://www.sun.com/bigadmin/common/berkeley_license.html ############################################################################## # # store_api_login.py # # Script to store the needed API user/password into # the file $HOME/.uce_python/.netrc (similiar like # using ftp with stored user/password values) # # Author: Juergen.Fleischer@Sun.COM # # v1.0: 23-Apr-2007 # v1.1: 23-May-2007 # Changes: $HOME is now used, not '/'or '/root' anymore # import sys,os,base64,getpass home = os.environ['HOME'] netrc = home + '/.uce_python/.netrc' # ask for user & password, don't show password while typing it! print "Username: ", user=sys.stdin.readline().rstrip() passwd=getpass.getpass("Password: ") # store user & encoded password in netrc f = open(netrc,'w') f.write( user + ' ' + base64.encodestring(passwd)) f.close() os.chmod(netrc,0400) print print "User/Password successfully stored." print