__init__.py 1.68 KB
Newer Older
kaniini's avatar
kaniini committed
1
2
3
4
5
6
from . import logging


import asyncio
import aiohttp
import aiohttp.web
kaniini's avatar
kaniini committed
7
import yaml
8
import argparse
kaniini's avatar
kaniini committed
9

10
11
12
13
14
15
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()
kaniini's avatar
kaniini committed
16
17

def load_config():
18
    with open(args.config) as f:
Izalia Mae's avatar
Izalia Mae committed
19
20
21
22
23
24
25
        options = {}

        ## Prevent a warning message for pyyaml 5.1+
        if getattr(yaml, 'FullLoader', None):
            options['Loader'] = yaml.FullLoader

        yaml_file = yaml.load(f, **options)
26
27
28
29
30
31
32

        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': {
33
                'blocked_software': [v.lower() for v in yaml_file['ap'].get('blocked_software', [])],
Izalia Mae's avatar
Izalia Mae committed
34
                'blocked_instances': yaml_file['ap'].get('blocked_instances', []),
35
                'host': yaml_file['ap'].get('host', 'localhost'),
Izalia Mae's avatar
Izalia Mae committed
36
                'whitelist': yaml_file['ap'].get('whitelist', []),
37
38
39
40
                'whitelist_enabled': yaml_file['ap'].get('whitelist_enabled', False)
            }
        }
        return config
kaniini's avatar
kaniini committed
41
42
43


CONFIG = load_config()
kaniini's avatar
kaniini committed
44

kaniini's avatar
kaniini committed
45
46
47
48
49
50
from .http_signatures import http_signatures_middleware


app = aiohttp.web.Application(middlewares=[
    http_signatures_middleware
])
kaniini's avatar
kaniini committed
51
52


kaniini's avatar
kaniini committed
53
from . import database
kaniini's avatar
kaniini committed
54
from . import actor
55
from . import webfinger
56
from . import default
57
from . import nodeinfo
kaniini's avatar
kaniini committed
58
from . import http_stats