diff options
author | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2013-08-29 16:36:23 +0300 |
---|---|---|
committer | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2013-08-29 16:36:23 +0300 |
commit | 7bdc174cf33f59a1fd270b276b2b8977cec6c766 (patch) | |
tree | f2ef79283dc62d3b2539ba4fe925a0d83b4f7ad4 /utils | |
parent | e7ca55e304ed0a9244c243427350a665a1043d5c (diff) |
Add ability cache auth credentials in FS ("authorize" command).
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/cmdline-client/android-build-client | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/utils/cmdline-client/android-build-client b/utils/cmdline-client/android-build-client index 9d6ed99..512ef74 100755 --- a/utils/cmdline-client/android-build-client +++ b/utils/cmdline-client/android-build-client @@ -121,12 +121,17 @@ def main(): if len(args) < 1: optparser.error("Wrong number of arguments") + config_dir = os.path.expanduser("~/.config/android-build-client") + password = None if options.cred_file: options.user, password = open(options.cred_file).read().strip().split(":") elif options.apikey_file: password = open(options.passwd_file).read().strip() - else: + elif os.path.exists(config_dir + "/cred"): + options.user, password = open(config_dir + "/cred").read().strip().split(":") + print "INFO: Using cached authorization for: %s" % options.user + elif args[0] != "authorize": password = getpass.getpass("API Token:") if options.url[-1] != '/': @@ -134,7 +139,25 @@ def main(): j = Jenkins(options.url, options.user, password) - if args[0] == "create": + if args[0] == "authorize": + if len(args) != 1: + optparser.error("Usage: authorize") + import getpass + user = raw_input("Enter user name: ") + while True: + key = getpass.getpass("API key: ") + if len(key) == 32: + break + print "This does not look like Jenkisn API key, please try again" + try: + os.makedirs(config_dir) + except OSError: + pass + f = open(config_dir + "/cred", "w") + print >>f, "%s:%s" % (user, key) + f.close() + print "Credentials cached for future use" + elif args[0] == "create": if len(args) != 3: optparser.error("Usage: create <job_name> <build_config_file>") job_group, job_subname = args[1].split("/") |