summaryrefslogtreecommitdiff
path: root/lorrycontroller/readconf.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/readconf.py')
-rw-r--r--lorrycontroller/readconf.py78
1 files changed, 38 insertions, 40 deletions
diff --git a/lorrycontroller/readconf.py b/lorrycontroller/readconf.py
index 4e162a9..3303f68 100644
--- a/lorrycontroller/readconf.py
+++ b/lorrycontroller/readconf.py
@@ -61,7 +61,7 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
statedb = self.open_statedb()
with statedb:
lorries_to_remove = set(statedb.get_lorries_paths())
- troves_to_remove = set(statedb.get_troves())
+ hosts_to_remove = set(statedb.get_hosts())
for section in conf_obj:
if not 'type' in section:
@@ -70,13 +70,13 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
added = self.add_matching_lorries_to_statedb(
statedb, section)
lorries_to_remove = lorries_to_remove.difference(added)
- elif section['type'] in ('trove', 'troves', 'gitlab'):
- self.add_trove(statedb, section)
- trovehost = section.get('host') or section['trovehost']
- if trovehost in troves_to_remove:
- troves_to_remove.remove(trovehost)
+ elif section['type'] in lorrycontroller.upstream_types:
+ self.add_host(statedb, section)
+ host = section.get('host') or section['trovehost']
+ if host in hosts_to_remove:
+ hosts_to_remove.remove(host)
lorries_to_remove = lorries_to_remove.difference(
- statedb.get_lorries_for_trove(trovehost))
+ statedb.get_lorries_for_host(host))
else:
logging.error(
'Unknown section in configuration: %r', section)
@@ -87,9 +87,9 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
for path in lorries_to_remove:
statedb.remove_lorry(path)
- for trovehost in troves_to_remove:
- statedb.remove_trove(trovehost)
- statedb.remove_lorries_for_trovehost(trovehost)
+ for host in hosts_to_remove:
+ statedb.remove_host(host)
+ statedb.remove_lorries_for_host(host)
if 'redirect' in bottle.request.forms:
bottle.redirect(bottle.request.forms.redirect)
@@ -215,7 +215,7 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
old_lorry_info = None
statedb.add_to_lorries(
- path=path, text=text, from_trovehost='', from_path='',
+ path=path, text=text, from_host='', from_path='',
interval=interval, timeout=timeout)
added_paths.add(path)
@@ -282,7 +282,7 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
new_obj = { path: obj }
return json.dumps(new_obj, indent=4)
- def add_trove(self, statedb, section):
+ def add_host(self, statedb, section):
username = None
password = None
if 'auth' in section:
@@ -290,22 +290,22 @@ class ReadConfiguration(lorrycontroller.LorryControllerRoute):
username = auth.get('username')
password = auth.get('password')
- gitlab_token = None
- if section['type'] == 'gitlab':
- gitlab_token = section['private-token']
+ type_params = lorrycontroller.upstream_types[section['type']] \
+ .get_host_type_params(section)
- statedb.add_trove(
- trovehost=section.get('host') or section['trovehost'],
+ statedb.add_host(
+ host=section.get('host') or section['trovehost'],
protocol=section['protocol'],
username=username,
password=password,
+ host_type=section['type'],
+ type_params=type_params,
lorry_interval=section['interval'],
lorry_timeout=section.get(
'lorry-timeout', self.DEFAULT_LORRY_TIMEOUT),
ls_interval=section['ls-interval'],
prefixmap=json.dumps(section['prefixmap']),
- ignore=json.dumps(section.get('ignore', [])),
- gitlab_token=gitlab_token)
+ ignore=json.dumps(section.get('ignore', [])))
class ValidationError(Exception):
@@ -318,19 +318,22 @@ class LorryControllerConfValidator(object):
def validate_config(self, conf_obj):
try:
- self._check_is_list(conf_obj)
- self._check_is_list_of_dicts(conf_obj)
+ self.check_is_list(conf_obj)
+ self.check_is_list_of_dicts(conf_obj)
for section in conf_obj:
if 'type' not in section:
raise ValidationError(
'section without type: %r' % section)
- elif section['type'] in ('trove', 'troves'):
- self._check_troves_section(section)
+ # Backward compatibility
+ if section['type'] == 'troves':
+ section['type'] = 'trove'
+ if section['type'] in lorrycontroller.upstream_types:
+ self._check_host_section(section)
+ lorrycontroller.upstream_types[section['type']] \
+ .check_host_type_params(self, section)
elif section['type'] == 'lorries':
self._check_lorries_section(section)
- elif section['type'] == 'gitlab':
- self._check_gitlab_section(section)
else:
raise ValidationError(
'unknown section type %r' % section['type'])
@@ -339,31 +342,26 @@ class LorryControllerConfValidator(object):
return None
- def _check_is_list(self, conf_obj):
+ def check_is_list(self, conf_obj):
if type(conf_obj) is not list:
raise ValidationError(
'type %r is not a JSON list' % type(conf_obj))
- def _check_is_list_of_dicts(self, conf_obj):
+ def check_is_list_of_dicts(self, conf_obj):
for item in conf_obj:
if type(item) is not dict:
raise ValidationError('all items must be dicts')
- def _check_gitlab_section(self, section):
- # gitlab section inherits trove configurations, perform the same checks.
- self._check_troves_section(section)
- self._check_has_required_fields(section, ['private-token'])
-
- def _check_troves_section(self, section):
+ def _check_host_section(self, section):
if not any(i in ('trovehost', 'host') for i in section):
- self._check_has_required_fields(section, ['host'])
- self._check_has_required_fields(
+ self.check_has_required_fields(section, ['host'])
+ self.check_has_required_fields(
section,
['protocol', 'interval', 'ls-interval', 'prefixmap'])
self._check_protocol(section)
self._check_prefixmap(section)
if 'ignore' in section:
- self._check_is_list_of_strings(section, 'ignore')
+ self.check_is_list_of_strings(section, 'ignore')
def _check_protocol(self, section):
valid = ('ssh', 'http', 'https')
@@ -380,18 +378,18 @@ class LorryControllerConfValidator(object):
pass
def _check_lorries_section(self, section):
- self._check_has_required_fields(
+ self.check_has_required_fields(
section, ['interval', 'prefix', 'globs'])
- self._check_is_list_of_strings(section, 'globs')
+ self.check_is_list_of_strings(section, 'globs')
- def _check_has_required_fields(self, section, fields):
+ def check_has_required_fields(self, section, fields):
for field in fields:
if field not in section:
raise ValidationError(
'mandatory field %s missing in section %r' %
(field, section))
- def _check_is_list_of_strings(self, section, field):
+ def check_is_list_of_strings(self, section, field):
obj = section[field]
if not isinstance(obj, list) or not all(
isinstance(s, str) for s in obj):