Allow to authenticate to Gerrit with HTTP basic auth

Gerrit instances running at googlesource.com require authentication
with HTTP basic auth.

Add a new config option to allow to specify either basic auth or digest
auth. Default to digest auth if not specified.

Change-Id: Iab6f666082bd3fee2c77a8c489255926cc93edba
Closes-Bug: 291
This commit is contained in:
David Pursehouse 2014-09-10 12:02:10 +02:00
parent 3f32c7d301
commit a2b6b1a12d
3 changed files with 14 additions and 1 deletions

View File

@ -23,6 +23,10 @@ servers:
# username: CHANGEME
# Your password in Gerrit (Settings -> HTTP Password). [required]
# password: CHANGEME
# Authentication type required by the Gerrit server. Can be 'basic' or
# 'digest'. Defaults to 'digest' if not set or set to an unexpected
# value.
# auth-type: digest
# A location where Gertty should store its git repositories. These
# can be the same git repositories where you do your own work --
# Gertty will not modify them unless you tell it to, and even then the

View File

@ -45,6 +45,7 @@ class ConfigSchema(object):
'dburi': str,
v.Required('git-root'): str,
'log-file': str,
'auth-type': str,
}
servers = [server]
@ -133,6 +134,10 @@ class Config(object):
if self.password is None:
self.password = getpass.getpass("Password for %s (%s): "
% (self.url, self.username))
self.auth_type = server.get('auth-type', 'digest')
auth_types = ['digest', 'basic']
if self.auth_type not in auth_types:
self.auth_type = 'digest'
self.verify_ssl = server.get('verify-ssl', True)
if not self.verify_ssl:
os.environ['GIT_SSL_NO_VERIFY']='true'

View File

@ -762,7 +762,11 @@ class Sync(object):
self.log = logging.getLogger('gertty.sync')
self.queue = MultiQueue([HIGH_PRIORITY, NORMAL_PRIORITY, LOW_PRIORITY])
self.session = requests.Session()
self.auth = requests.auth.HTTPDigestAuth(
if self.app.config.auth_type == 'basic':
authclass = requests.auth.HTTPBasicAuth
else:
authclass = requests.auth.HTTPDigestAuth
self.auth = authclass(
self.app.config.username, self.app.config.password)
self.submitTask(SyncOwnAccountTask(HIGH_PRIORITY))
self.submitTask(CheckReposTask(HIGH_PRIORITY))