fix DeprecationWarnings on 3.10
[relay.git/.git] / relay / __init__.py
1 from . import logging
2
3
4 import asyncio
5 import aiohttp
6 import aiohttp.web
7 import yaml
8 import argparse
9
10 parser = argparse.ArgumentParser(
11     description="A generic LitePub relay (works with all LitePub consumers and Mastodon).",
12     prog="python -m relay")
13 parser.add_argument("-c", "--config", type=str, default="relay.yaml",
14     metavar="<path>", help="the path to your config file")
15 args = parser.parse_args()
16
17 def load_config():
18     with open(args.config) as f:
19         options = {}
20
21         ## Prevent a warning message for pyyaml 5.1+
22         if getattr(yaml, 'FullLoader', None):
23             options['Loader'] = yaml.FullLoader
24
25         yaml_file = yaml.load(f, **options)
26
27         config = {
28             'db': yaml_file.get('db', 'relay.jsonld'),
29             'listen': yaml_file.get('listen', '0.0.0.0'),
30             'port': int(yaml_file.get('port', 8080)),
31             'note': yaml_file.get('note', 'Make a note about your instance here.'),
32             'ap': {
33                 'blocked_software': [v.lower() for v in yaml_file['ap'].get('blocked_software', [])],
34                 'blocked_instances': yaml_file['ap'].get('blocked_instances', []),
35                 'host': yaml_file['ap'].get('host', 'localhost'),
36                 'whitelist': yaml_file['ap'].get('whitelist', []),
37                 'whitelist_enabled': yaml_file['ap'].get('whitelist_enabled', False)
38             }
39         }
40         return config
41
42
43 CONFIG = load_config()
44
45 from .http_signatures import http_signatures_middleware
46
47
48 app = aiohttp.web.Application(middlewares=[
49     http_signatures_middleware
50 ])
51
52
53 from . import database
54 from . import actor
55 from . import webfinger
56 from . import default
57 from . import nodeinfo
58 from . import http_stats