Commit 132cd1ea authored by kaniini's avatar kaniini

Merge branch 'fix' into 'master'

Fix db wipe on json error and default config checking

See merge request !19
parents f3b4fc44 b4f08351
...@@ -9,7 +9,23 @@ import yaml ...@@ -9,7 +9,23 @@ import yaml
def load_config(): def load_config():
with open('relay.yaml') as f: with open('relay.yaml') as f:
return yaml.load(f) yaml_file = yaml.load(f)
whitelist = yaml_file['ap'].get('whitelist', [])
blocked = yaml_file['ap'].get('blocked_instances', [])
config = {
'db': yaml_file.get('db', 'relay.jsonld'),
'listen': yaml_file.get('listen', '0.0.0.0'),
'port': int(yaml_file.get('port', 8080)),
'note': yaml_file.get('note', 'Make a note about your instance here.'),
'ap': {
'blocked_instances': [] if blocked is None else blocked,
'host': yaml_file['ap'].get('host', 'localhost'),
'whitelist': [] if whitelist is None else whitelist,
'whitelist_enabled': yaml_file['ap'].get('whitelist_enabled', False)
}
}
return config
CONFIG = load_config() CONFIG = load_config()
......
...@@ -36,7 +36,7 @@ from . import app, CONFIG ...@@ -36,7 +36,7 @@ from . import app, CONFIG
from .remote_actor import fetch_actor from .remote_actor import fetch_actor
AP_CONFIG = CONFIG.get('ap', {'host': 'localhost','blocked_instances':[], 'whitelist_enabled': False, 'whitelist': []}) AP_CONFIG = CONFIG['ap']
CACHE_SIZE = CONFIG.get('cache-size', 16384) CACHE_SIZE = CONFIG.get('cache-size', 16384)
......
...@@ -2,19 +2,24 @@ import asyncio ...@@ -2,19 +2,24 @@ import asyncio
import logging import logging
import urllib.parse import urllib.parse
import simplejson as json import simplejson as json
from sys import exit
from . import CONFIG from . import CONFIG
AP_CONFIG = CONFIG.get('ap', {'blocked_instances':[], 'whitelist_enabled': False, 'whitelist': []}) AP_CONFIG = CONFIG['ap']
try: try:
with open(CONFIG['db']) as f: with open(CONFIG['db']) as f:
DATABASE = json.load(f) DATABASE = json.load(f)
except:
except FileNotFoundError:
logging.info('No database was found, making a new one.') logging.info('No database was found, making a new one.')
DATABASE = {} DATABASE = {}
except json.decoder.JSONDecodeError:
logging.info('Invalid JSON in db. Exiting...')
exit(1)
following = DATABASE.get('relay-list', []) following = DATABASE.get('relay-list', [])
for inbox in following: for inbox in following:
if urllib.parse.urlsplit(inbox).hostname in AP_CONFIG['blocked_instances']: if urllib.parse.urlsplit(inbox).hostname in AP_CONFIG['blocked_instances']:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment