sedi-relay/relay/__init__.py

59 lines
1.7 KiB
Python
Raw Normal View History

2018-08-10 19:19:38 +00:00
from . import logging
import asyncio
import aiohttp
import aiohttp.web
2018-08-10 19:59:46 +00:00
import yaml
2021-10-15 12:17:10 +00:00
import argparse
2018-08-10 19:59:46 +00:00
2021-10-15 12:17:10 +00:00
parser = argparse.ArgumentParser(
description="A generic LitePub relay (works with all LitePub consumers and Mastodon).",
prog="python -m relay")
parser.add_argument("-c", "--config", type=str, default="relay.yaml",
metavar="<path>", help="the path to your config file")
args = parser.parse_args()
2018-08-10 19:59:46 +00:00
def load_config():
2021-10-15 12:17:10 +00:00
with open(args.config) as f:
2020-12-03 03:41:45 +00:00
options = {}
## Prevent a warning message for pyyaml 5.1+
if getattr(yaml, 'FullLoader', None):
options['Loader'] = yaml.FullLoader
yaml_file = yaml.load(f, **options)
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': {
2020-12-04 07:34:40 +00:00
'blocked_software': [v.lower() for v in yaml_file['ap'].get('blocked_software', [])],
2020-12-03 03:41:45 +00:00
'blocked_instances': yaml_file['ap'].get('blocked_instances', []),
'host': yaml_file['ap'].get('host', 'localhost'),
2020-12-03 03:41:45 +00:00
'whitelist': yaml_file['ap'].get('whitelist', []),
'whitelist_enabled': yaml_file['ap'].get('whitelist_enabled', False)
}
}
return config
2018-08-10 19:59:46 +00:00
CONFIG = load_config()
2018-08-10 19:19:38 +00:00
2018-08-10 21:14:22 +00:00
from .http_signatures import http_signatures_middleware
app = aiohttp.web.Application(middlewares=[
http_signatures_middleware
])
2018-08-10 19:19:38 +00:00
2018-08-10 19:59:46 +00:00
from . import database
2018-08-10 19:19:38 +00:00
from . import actor
from . import webfinger
from . import default
from . import nodeinfo
2018-11-18 22:03:53 +00:00
from . import http_stats