diff options
| author | David Pursehouse <david.pursehouse@sonymobile.com> | 2014-03-14 12:20:31 +0900 |
|---|---|---|
| committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2014-04-28 16:26:50 +0900 |
| commit | f0b77968389966cd7bad0cac1fe7f04526eafde1 (patch) | |
| tree | 8be265591681d9a1cc470ff77525dcfaa4ccdb68 /pygerrit/auth.py | |
| parent | c499b43b9cbf1f98364b75a1ea718b6b756b9c93 (diff) | |
| download | pygerrit-f0b77968389966cd7bad0cac1fe7f04526eafde1.tar.gz | |
Remove support for Gerrit over ssh
From now only the REST API is supported.
This makes installation of the package a bit lighter as we no
longer depend on paramiko and pycrypto
Change-Id: Ieda773d596fd43047c05895f3304690ddf709094
Diffstat (limited to 'pygerrit/auth.py')
| -rw-r--r-- | pygerrit/auth.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/pygerrit/auth.py b/pygerrit/auth.py new file mode 100644 index 0000000..c43c3fa --- /dev/null +++ b/pygerrit/auth.py @@ -0,0 +1,56 @@ +# The MIT License +# +# Copyright 2013 Sony Mobile Communications. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +""" Authentication classes. """ + +from requests.auth import HTTPDigestAuth, HTTPBasicAuth +from requests.utils import get_netrc_auth + + +class HTTPDigestAuthFromNetrc(HTTPDigestAuth): + + """ HTTP Digest Auth with netrc credentials. """ + + def __init__(self, url): + auth = get_netrc_auth(url) + if not auth: + raise ValueError("netrc missing or no credentials found in netrc") + username, password = auth + super(HTTPDigestAuthFromNetrc, self).__init__(username, password) + + def __call__(self, req): + return super(HTTPDigestAuthFromNetrc, self).__call__(req) + + +class HTTPBasicAuthFromNetrc(HTTPBasicAuth): + + """ HTTP Basic Auth with netrc credentials. """ + + def __init__(self, url): + auth = get_netrc_auth(url) + if not auth: + raise ValueError("netrc missing or no credentials found in netrc") + username, password = auth + super(HTTPBasicAuthFromNetrc, self).__init__(username, password) + + def __call__(self, req): + return super(HTTPBasicAuthFromNetrc, self).__call__(req) |
