diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2013-09-24 14:35:35 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2013-09-24 15:24:39 +0900 |
commit | bc0220489e12f71b5c77d8d62acf80abd6064156 (patch) | |
tree | 4a42096fc35f56454ab079c384393f2690741942 /rest_example.py | |
parent | 8aa4f816f7dbf424bf55b865fff83ceeef943aaa (diff) | |
download | pygerrit-bc0220489e12f71b5c77d8d62acf80abd6064156.tar.gz |
Add support for Kerberos authentication in example script
Add a --kerberos-auth option that can be used to enable kerberos
authentication.
The option is only present if the HTTPKerberosAuth handler can be
successfully imported the from requests_kerberos module.
Change-Id: Id6c2beca1bf76fbe01f7a6aa8dfccc5844269454
Diffstat (limited to 'rest_example.py')
-rwxr-xr-x | rest_example.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/rest_example.py b/rest_example.py index 132765f..ad762fd 100755 --- a/rest_example.py +++ b/rest_example.py @@ -30,6 +30,10 @@ import optparse import sys from requests.auth import HTTPBasicAuth, HTTPDigestAuth +try: + from requests_kerberos import HTTPKerberosAuth, OPTIONAL +except ImportError: + HTTPKerberosAuth = None from pygerrit.rest import GerritRestAPI from pygerrit.rest.auth import HTTPDigestAuthFromNetrc, HTTPBasicAuthFromNetrc @@ -44,6 +48,10 @@ def _main(): parser.add_option('-b', '--basic-auth', dest='basic_auth', action='store_true', help='use basic auth instead of digest') + if HTTPKerberosAuth: + parser.add_option('-k', '--kerberos-auth', dest='kerberos_auth', + action='store_true', + help='use kerberos auth') parser.add_option('-u', '--username', dest='username', help='username') parser.add_option('-p', '--password', dest='password', @@ -64,7 +72,13 @@ def _main(): if not options.gerrit_url: parser.error("Must specify Gerrit URL with --gerrit-url") - if options.username and options.password: + if HTTPKerberosAuth and options.kerberos_auth: + if options.username or options.password \ + or options.basic_auth or options.netrc: + parser.error("--kerberos-auth may not be used together with " + "--username, --password, --basic-auth or --netrc") + auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL) + elif options.username and options.password: if options.netrc: logging.warning("--netrc option ignored") if options.basic_auth: |