mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-24 15:31:08 +00:00
more skeleton
This commit is contained in:
parent
1445f3807f
commit
1ff6179a78
|
@ -4,9 +4,19 @@ from . import logging
|
|||
import asyncio
|
||||
import aiohttp
|
||||
import aiohttp.web
|
||||
import yaml
|
||||
|
||||
|
||||
def load_config():
|
||||
with open('viera.yaml') as f:
|
||||
return yaml.load(f)
|
||||
|
||||
|
||||
CONFIG = load_config()
|
||||
|
||||
|
||||
app = aiohttp.web.Application()
|
||||
|
||||
|
||||
from . import database
|
||||
from . import actor
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
import aiohttp.web
|
||||
import logging
|
||||
from Crypto.PublicKey import RSA
|
||||
from .database import DATABASE
|
||||
|
||||
|
||||
# generate actor keys if not present
|
||||
if "actorKeys" not in DATABASE:
|
||||
logging.info("No actor keys present, generating 4096-bit RSA keypair.")
|
||||
|
||||
privkey = RSA.generate(4096)
|
||||
pubkey = privkey.publickey()
|
||||
|
||||
DATABASE["actorKeys"] = {
|
||||
"publicKey": pubkey.exportKey('PEM'),
|
||||
"privateKey": privkey.exportKey('PEM')
|
||||
}
|
||||
|
||||
|
||||
from . import app
|
||||
|
||||
|
||||
async def actor(request):
|
||||
data = {
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"endpoints": {
|
||||
"sharedInbox": "https://{}/inbox".format(request.host)
|
||||
},
|
||||
"followers": "https://{}/followers".format(request.host),
|
||||
"inbox": "https://{}/inbox".format(request.host),
|
||||
"name": "Viera",
|
||||
"type": "Application",
|
||||
"publicKey": {
|
||||
"id": "https://{}/actor#main-key".format(request.host),
|
||||
"owner": "https://{}/actor".format(request.host),
|
||||
"publicKeyPem": DATABASE["actorKeys"]["publicKey"]
|
||||
},
|
||||
"summary": "Viera, the bot"
|
||||
}
|
||||
return aiohttp.web.json_response(data)
|
||||
|
||||
|
||||
app.router.add_get('/actor', actor)
|
24
viera/database.py
Normal file
24
viera/database.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import simplejson as json
|
||||
|
||||
|
||||
from . import CONFIG
|
||||
|
||||
|
||||
try:
|
||||
with open(CONFIG['db']) as f:
|
||||
DATABASE = json.load(f)
|
||||
except:
|
||||
logging.info('No database was found, making a new one.')
|
||||
DATABASE = {}
|
||||
|
||||
|
||||
async def database_save():
|
||||
while True:
|
||||
with open(CONFIG['db'], 'w') as f:
|
||||
json.dump(DATABASE, f)
|
||||
await asyncio.sleep(30)
|
||||
|
||||
|
||||
asyncio.ensure_future(database_save())
|
Loading…
Reference in a new issue