From 2b30fc78faf63179dcabfd472b61325acc44218d Mon Sep 17 00:00:00 2001 From: Scott Hiland Date: Fri, 8 Apr 2016 10:17:33 -0400 Subject: [PATCH] Adds a -P option to allow separate specification of the password or to prompt for it from user input to keep .bash_history clean of credentials Retains prior functionality for folks who have already scripted with it. Uses -P ! to prompt, kludgy, but means we don't have to import argparse --- tools/deploy.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tools/deploy.py b/tools/deploy.py index dc6cb5cb..f50a3d84 100755 --- a/tools/deploy.py +++ b/tools/deploy.py @@ -117,15 +117,17 @@ def printDeployments(dep): print ' Error: %s' % d['error'] ApigeeHost = 'https://api.enterprise.apigee.com' -UserPW = None +User = None +PW = None Directory = None Organization = None Environment = None Name = None BasePath = '/' ShouldDeploy = True +PassSpecified = False -Options = 'h:u:d:e:n:p:o:i:z:' +Options = 'h:u:d:e:n:p:o:i:z:P:' opts = getopt.getopt(sys.argv[1:], Options)[0] @@ -143,26 +145,39 @@ def printDeployments(dep): elif o[0] == '-p': BasePath = o[1] elif o[0] == '-u': - UserPW = o[1] + User = o[1] + elif o[0] == '-P': + PW = o[1] + PassSpecified = True elif o[0] == '-i': ShouldDeploy = False elif o[0] == '-z': ZipFile = o[1] +if PW == '!': + PW = raw_input("Password: ") + PW = str(PW) -if UserPW == None or \ +if User == None or \ (Directory == None and ZipFile == None) or \ Environment == None or \ Name == None or \ - Organization == None: + Organization == None or \ + (PW == None and PassSpecified == True): print """Usage: deploy -n [name] (-d [directory name] | -z [zipfile]) - -e [environment] -u [username:password] -o [organization] - [-p [base path] -h [apigee API url] -i] + -e [environment] (-u [username:password] | -u [username] -P [password:!]) + -o [organization][-p [base path] -h [apigee API url] -i] base path defaults to "/" Apigee URL defaults to "https://api.enterprise.apigee.com" -i denotes to import only and not actually deploy + Specifying -P ! will prompt for password """ sys.exit(1) +if PW == None: + UserPW = User +else: + UserPW = User + ':' + PW + url = urlparse.urlparse(ApigeeHost) httpScheme = url[0] httpHost = url[1]