Fmt
This commit is contained in:
parent
53bf982217
commit
1c41b6dca4
8 changed files with 42 additions and 37 deletions
|
@ -1,14 +1,16 @@
|
||||||
import Crypto
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import click
|
|
||||||
import platform
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from relay import misc, __version__
|
import Crypto
|
||||||
from relay.application import Application, request_id_middleware
|
import click
|
||||||
|
from relay import __version__, misc
|
||||||
|
from relay.application import (
|
||||||
|
Application,
|
||||||
|
request_id_middleware,
|
||||||
|
)
|
||||||
from relay.config import relay_software_names
|
from relay.config import relay_software_names
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +41,6 @@ def cli(ctx, config):
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def cli_inbox(ctx: Application):
|
def cli_inbox(ctx: Application):
|
||||||
"Manage the inboxes in the database"
|
"Manage the inboxes in the database"
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@cli_inbox.command("list")
|
@cli_inbox.command("list")
|
||||||
|
@ -161,7 +162,6 @@ def cli_inbox_remove(obj: Application, inbox):
|
||||||
@cli.group("instance")
|
@cli.group("instance")
|
||||||
def cli_instance():
|
def cli_instance():
|
||||||
"Manage instance bans"
|
"Manage instance bans"
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@cli_instance.command("list")
|
@cli_instance.command("list")
|
||||||
|
@ -214,7 +214,6 @@ def cli_instance_unban(obj: Application, target):
|
||||||
@cli.group("software")
|
@cli.group("software")
|
||||||
def cli_software():
|
def cli_software():
|
||||||
"Manage banned software"
|
"Manage banned software"
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@cli_software.command("list")
|
@cli_software.command("list")
|
||||||
|
@ -301,7 +300,6 @@ def cli_software_unban(obj: Application, name, fetch_nodeinfo):
|
||||||
@cli.group("whitelist")
|
@cli.group("whitelist")
|
||||||
def cli_whitelist():
|
def cli_whitelist():
|
||||||
"Manage the instance whitelist"
|
"Manage the instance whitelist"
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@cli_whitelist.command("list")
|
@cli_whitelist.command("list")
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from cachetools import LRUCache
|
from cachetools import LRUCache
|
||||||
from datetime import datetime, timedelta
|
|
||||||
|
|
||||||
from relay.config import RelayConfig
|
from relay.config import RelayConfig
|
||||||
from relay.database import RelayDatabase
|
from relay.database import RelayDatabase
|
||||||
from relay.misc import DotDict, check_open_port, set_app
|
from relay.misc import (
|
||||||
|
check_open_port,
|
||||||
|
DotDict,
|
||||||
|
set_app,
|
||||||
|
)
|
||||||
from relay.views import routes
|
from relay.views import routes
|
||||||
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
|
|
||||||
class Application(web.Application):
|
class Application(web.Application):
|
||||||
def __init__(self, cfgpath, middlewares=None):
|
def __init__(self, cfgpath, middlewares=None):
|
||||||
|
|
|
@ -2,7 +2,6 @@ from pathlib import Path
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from relay.misc import DotDict
|
from relay.misc import DotDict
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
|
|
||||||
class RelayDatabase(dict):
|
class RelayDatabase(dict):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import logging
|
|
||||||
import aiohttp
|
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
|
|
||||||
STATS = {
|
STATS = {
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
import base64
|
import base64
|
||||||
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
from urllib.parse import urlparse
|
||||||
import uuid
|
import uuid
|
||||||
from random import randint
|
|
||||||
|
|
||||||
from Crypto.Hash import SHA, SHA256, SHA512
|
from Crypto.Hash import SHA, SHA256, SHA512
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
from Crypto.Signature import PKCS1_v1_5
|
from Crypto.Signature import PKCS1_v1_5
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from aiohttp.client_exceptions import ClientResponseError, ClientConnectorError
|
from aiohttp.client_exceptions import (
|
||||||
|
ClientConnectorError,
|
||||||
|
ClientResponseError,
|
||||||
|
)
|
||||||
from aiohttp.hdrs import METH_ALL as METHODS
|
from aiohttp.hdrs import METH_ALL as METHODS
|
||||||
from aiohttp.web import Response as AiohttpResponse, View as AiohttpView
|
from aiohttp.web import (
|
||||||
from datetime import datetime
|
Response as AiohttpResponse,
|
||||||
from json.decoder import JSONDecodeError
|
View as AiohttpView,
|
||||||
from urllib.parse import urlparse
|
)
|
||||||
from async_lru import alru_cache
|
from async_lru import alru_cache
|
||||||
|
|
||||||
from relay.http_debug import http_debug
|
from relay.http_debug import http_debug
|
||||||
|
|
||||||
from retry import retry
|
from retry import retry
|
||||||
|
|
||||||
|
|
||||||
|
@ -339,7 +342,7 @@ class DotDict(dict):
|
||||||
# misc properties
|
# misc properties
|
||||||
@property
|
@property
|
||||||
def domain(self):
|
def domain(self):
|
||||||
return urlparse(getattr(self, 'id', None) or getattr(self, 'actor')).hostname
|
return urlparse(getattr(self, "id", None) or getattr(self, "actor")).hostname
|
||||||
|
|
||||||
# actor properties
|
# actor properties
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from relay import misc
|
from relay import misc
|
||||||
|
@ -105,11 +104,11 @@ async def run_processor(request, actor, data, software):
|
||||||
return
|
return
|
||||||
|
|
||||||
logging.info(f'{request.id}: New "{data.type}" from actor: {actor.id}')
|
logging.info(f'{request.id}: New "{data.type}" from actor: {actor.id}')
|
||||||
logging.debug(f'{request.id}: {data!r}')
|
logging.debug(f"{request.id}: {data!r}")
|
||||||
|
|
||||||
env = dict(data=data, actor=actor, software=software)
|
env = dict(data=data, actor=actor, software=software)
|
||||||
try:
|
try:
|
||||||
return await processors.get(data.type, handle_dont)(request, actor, data, software)
|
return await processors.get(data.type, handle_dont)(request, actor, data, software)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
logging.exception(f'{request.id}] {env!r}')
|
logging.exception(f"{request.id}] {env!r}")
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from aiohttp.web import HTTPUnauthorized
|
||||||
from relay import __version__, misc
|
from relay import __version__, misc
|
||||||
from relay.http_debug import STATS
|
from relay.http_debug import STATS
|
||||||
from relay.misc import DotDict, Message, Response, WKNodeinfo
|
from relay.misc import (
|
||||||
|
DotDict,
|
||||||
|
Message,
|
||||||
|
Response,
|
||||||
|
WKNodeinfo,
|
||||||
|
)
|
||||||
from relay.processors import run_processor
|
from relay.processors import run_processor
|
||||||
|
|
||||||
from aiohttp.web import HTTPUnauthorized
|
|
||||||
|
|
||||||
routes = []
|
routes = []
|
||||||
|
|
||||||
|
@ -91,7 +95,7 @@ async def inbox(request):
|
||||||
# This PROBABLY means we can do without this data ever ... but here it is.
|
# This PROBABLY means we can do without this data ever ... but here it is.
|
||||||
|
|
||||||
# Trying to deal with actors/visibility
|
# Trying to deal with actors/visibility
|
||||||
if isinstance(data.object, dict) and not data.object.get('discoverable', True):
|
if isinstance(data.object, dict) and not data.object.get("discoverable", True):
|
||||||
actor = DotDict({"id": "dummy-for-undiscoverable-object"})
|
actor = DotDict({"id": "dummy-for-undiscoverable-object"})
|
||||||
|
|
||||||
# Normal path of looking up the actor...
|
# Normal path of looking up the actor...
|
||||||
|
@ -100,7 +104,7 @@ async def inbox(request):
|
||||||
# FIXME: Needs a cache
|
# FIXME: Needs a cache
|
||||||
actor = await misc.request(data.actorid)
|
actor = await misc.request(data.actorid)
|
||||||
except:
|
except:
|
||||||
logging.exception(f'{request.id}: {data!r}')
|
logging.exception(f"{request.id}: {data!r}")
|
||||||
return
|
return
|
||||||
|
|
||||||
logging.debug(f"Inbox >> {data!r}")
|
logging.debug(f"Inbox >> {data!r}")
|
||||||
|
|
Loading…
Reference in a new issue