Friday, April 3, 2009

google appengine appcfg.py tweak to allow passing password on command line

to get appcfg.py to accept --password on the command line instead of being prompted for it:


change:

appengine/google_appengine/google/appengine/tools/appcfg.py

add the following in the parser.add_option section:


parser.add_option("-p","--password", action="store", dest="password",
metavar="PASSWORD", default=None,
help="The password")



Then modify the GetUserCredentials function:


def GetUserCredentials():
"""Prompts the user for a username and password."""
email = self.options.email
if email is None:
email = self.raw_input_fn("Email: ")

password = self.options.password
if password is None:
password = self.raw_input_fn("Password: ")

# password_prompt = "Password for %s: " % email
# if self.options.passin:
# password = self.raw_input_fn(password_prompt)
# else:
# password = self.password_input_fn(password_prompt)

return (email, password)


That's it, now you can call:

appcfg.py update demos/guestbook --email=email@gmail.com --password=xxxx

2 comments:

  1. And how about:

    echo "your secret password" | appcfg.py update demos/guestbook --email=email@gmail.com --passin

    ReplyDelete
  2. I was totally psyched to see this and used it, ad it worked. It seemed odd, though, that Google would not have done something like this. Thoose people hate typing passwords as next as the next person. Here's why they didn't.

    https://developers.google.com/appengine/docs/python/tools/uploadinganapp shows that if you do this:

    appcfg.py --oauth2 update myapp/

    your authentication will be saved and you won't have to log in again. It also has the advantage of not putting your password where other people can see it (e.g., ps -ax).

    ReplyDelete