diff --git a/relay/application.py b/relay/application.py index 8133d7c..26d8d4a 100644 --- a/relay/application.py +++ b/relay/application.py @@ -21,8 +21,7 @@ class Application(web.Application): self['starttime'] = None self['running'] = False - self['is_docker'] = bool(os.environ.get('DOCKER_RUNNING')) - self['config'] = RelayConfig(cfgpath, self['is_docker']) + self['config'] = RelayConfig(cfgpath) if not self['config'].load(): self['config'].save() @@ -59,11 +58,6 @@ class Application(web.Application): return self['database'] - @property - def is_docker(self): - return self['is_docker'] - - @property def semaphore(self): return self['semaphore'] diff --git a/relay/config.py b/relay/config.py index 090b63c..aa23ee2 100644 --- a/relay/config.py +++ b/relay/config.py @@ -1,6 +1,8 @@ import json +import os import yaml +from functools import cached_property from pathlib import Path from urllib.parse import urlparse @@ -25,22 +27,17 @@ class RelayConfig(DotDict): } - def __init__(self, path, is_docker): + def __init__(self, path): DotDict.__init__(self, {}) - if is_docker: - path = '/data/relay.yaml' + if self.is_docker: + path = '/data/config.yaml' - self._isdocker = is_docker self._path = Path(path).expanduser() - self.reset() def __setitem__(self, key, value): - if self._isdocker and key in ['db', 'listen', 'port']: - return - if key in ['blocked_instances', 'blocked_software', 'whitelist']: assert isinstance(value, (list, set, tuple)) @@ -80,6 +77,11 @@ class RelayConfig(DotDict): return f'{self.actor}#main-key' + @cached_property + def is_docker(self): + return bool(os.environ.get('DOCKER_RUNNING')) + + def reset(self): self.clear() self.update({ @@ -98,6 +100,13 @@ class RelayConfig(DotDict): 'whitelist': [] }) + if self.is_docker: + self.update({ + 'db': Path('/data/relay.jsonld'), + 'listen': '127.0.0.1' + }) + + def ban_instance(self, instance): if instance.startswith('http'): instance = urlparse(instance).hostname diff --git a/relay/manage.py b/relay/manage.py index 48f3700..0429461 100644 --- a/relay/manage.py +++ b/relay/manage.py @@ -51,7 +51,7 @@ def cli_setup(): app.config.save() - if not app['is_docker'] and click.confirm('Relay all setup! Would you like to run it now?'): + if not app.config.is_docker and click.confirm('Relay all setup! Would you like to run it now?'): cli_run.callback()