From ce311a3c803515eb95c761a3a2838b093a4ea3cd Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 14 May 2020 00:45:02 +0100 Subject: Introduce and use downstream-{http,ssh}-url settings Replace the current hardcoded Downstream Host parameters with application settings. In general, Downstream Host connectors will use some combination of HTTP(S) and/or SSH, so these are added in lorry-controller-webapp. Currently only the gerrit connector will use downstream-ssh-url and only the gitlab connector will use downstream-http-url. Turn *on* StrictHostKeyChecking for the gerrit connector when not talking to localhost. Closes #4. --- lorrycontroller/gerrit.py | 11 ++++++++--- lorrycontroller/gitlab.py | 15 +++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'lorrycontroller') diff --git a/lorrycontroller/gerrit.py b/lorrycontroller/gerrit.py index dad964f..0970d63 100644 --- a/lorrycontroller/gerrit.py +++ b/lorrycontroller/gerrit.py @@ -32,9 +32,14 @@ class GerritDownstream(hosts.DownstreamHost): ''' def __init__(self, app_settings): - # XXX This needs to be configurable - url = 'ssh://lorry@localhost:29418' - self._ssh_command = hosts.SshCommand(url, StrictHostKeyChecking='no') + url = app_settings['downstream-ssh-url'] + if url is None: + url = 'ssh://lorry@localhost:29418' + key_check = 'no' + else: + key_check = 'yes' + self._ssh_command = hosts.SshCommand( + url, StrictHostKeyChecking=key_check) def _has_project(self, name): # There's no 'does this project exist' command in Gerrit 2.9.4; 'list diff --git a/lorrycontroller/gitlab.py b/lorrycontroller/gitlab.py index 4f70f0a..58bf67f 100644 --- a/lorrycontroller/gitlab.py +++ b/lorrycontroller/gitlab.py @@ -37,9 +37,8 @@ class MissingGitlabModuleError(Exception): pass -def _init_gitlab(host, token): +def _init_gitlab(url, token): if gitlab: - url = "http://" + host return gitlab.Gitlab(url, token) else: raise MissingGitlabModuleError('gitlab module missing\n' @@ -61,10 +60,10 @@ class GitlabDownstream(hosts.DownstreamHost): app_settings.require('gitlab-private-token') def __init__(self, app_settings): - # XXX This needs to be configurable - host = 'localhost' - - self.gl = _init_gitlab(host, app_settings['gitlab-private-token']) + url = app_settings['downstream-http-url'] + if url is None: + url = 'http://localhost/' + self.gl = _init_gitlab(url, app_settings['gitlab-private-token']) def prepare_repo(self, repo_path, metadata): @@ -131,8 +130,8 @@ class GitlabUpstream(hosts.UpstreamHost): def __init__(self, host_info): self._protocol = host_info['protocol'] - self.gl = _init_gitlab(host_info['host'], - host_info['type_params']['private-token']) + url = 'http://%(host)s/' % host_info + self.gl = _init_gitlab(url, host_info['type_params']['private-token']) def list_repos(self): '''List projects on a GitLab instance.''' -- cgit v1.2.1