From 4cce11af4ca0491b3da92321ddc44169909a6c26 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 7 May 2020 21:40:01 +0100 Subject: Move Downstream Host type-specific code into modules * Introduce hosts module and DownstreamHost abstract base class * Define a subclass of this for each Downstream Host type * Define a name-type map for these in the lorrycontroller package * Use these classes to replace type-specific code elsewhere Related to #5. --- lorry-controller-webapp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lorry-controller-webapp') diff --git a/lorry-controller-webapp b/lorry-controller-webapp index 9e3a310..6fc827e 100755 --- a/lorry-controller-webapp +++ b/lorry-controller-webapp @@ -131,17 +131,21 @@ class WEBAPP(cliapp.Application): self.settings.choice( ['downstream-host-type', 'git-server-type'], - ['gitano', 'gerrit', 'gitlab', 'local'], + # Default is the first choice, and must be 'gitano' for backward + # compatibility + ['gitano'] + + sorted(host_type + for host_type in lorrycontroller.downstream_types.keys() + if host_type != 'gitano'), 'what API the Downstream Host speaks') - self.settings.string( - ['gitlab-private-token'], - 'private token for GitLab API access') - self.settings.boolean( ['publish-failures'], 'make the status page show failure logs from lorry') + for downstream_type in lorrycontroller.downstream_types.values(): + downstream_type.add_app_settings(self.settings) + def find_routes(self): '''Return all classes that are API routes. @@ -166,11 +170,8 @@ class WEBAPP(cliapp.Application): def process_args(self, args): self.settings.require('statedb') - if (self.settings['git-server-type'] == 'gitlab' and - not self.settings['gitlab-private-token']): - logging.error('A private token must be provided to create ' - 'repositories on a GitLab instance.') - self.settings.require('gitlab-private-token') + lorrycontroller.downstream_types[self.settings['git-server-type']] \ + .check_app_settings(self.settings) self.setup_proxy() -- cgit v1.2.1