reformat; add expiration time to tokens
This commit is contained in:
parent
a2ad9ea428
commit
f85d0a0f20
6 changed files with 25 additions and 16 deletions
|
@ -2,7 +2,6 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import signal
|
|
||||||
|
|
||||||
from .env import CREDENTIALS_FILE
|
from .env import CREDENTIALS_FILE
|
||||||
from .client import create_client
|
from .client import create_client
|
||||||
|
@ -31,4 +30,5 @@ async def go():
|
||||||
|
|
||||||
await bot.run()
|
await bot.run()
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(go())
|
asyncio.run(go())
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
|
from .env import INVITE_CODE_EXPIRATION
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -46,6 +49,7 @@ class SynapseAdmin:
|
||||||
},
|
},
|
||||||
json={
|
json={
|
||||||
"uses_allowed": 1,
|
"uses_allowed": 1,
|
||||||
|
"expiry_time": int((time.time() + INVITE_CODE_EXPIRATION.total_seconds())*1000),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if not resp.ok:
|
if not resp.ok:
|
||||||
|
|
|
@ -47,14 +47,10 @@ if os.path.isfile(_ENV_FILE):
|
||||||
continue
|
continue
|
||||||
_DOTENV[split[0]] = "=".join(split[1:])
|
_DOTENV[split[0]] = "=".join(split[1:])
|
||||||
|
|
||||||
USER_REQUIRED_AGE = env(
|
USER_REQUIRED_AGE = env(td_parse, "USER_REQUIRED_AGE", datetime.timedelta(days=14))
|
||||||
td_parse, "USER_REQUIRED_AGE", datetime.timedelta(days=14)
|
|
||||||
)
|
|
||||||
|
|
||||||
SYNAPSE_ADMIN_ACCESS_TOKEN = env(str, "SYNAPSE_ADMIN_ACCESS_TOKEN", "")
|
SYNAPSE_ADMIN_ACCESS_TOKEN = env(str, "SYNAPSE_ADMIN_ACCESS_TOKEN", "")
|
||||||
SYNAPSE_ADMIN_HOMESERVER = env(
|
SYNAPSE_ADMIN_HOMESERVER = env(str, "SYNAPSE_ADMIN_HOMESERVER", "http://127.0.0.1:8008")
|
||||||
str, "SYNAPSE_ADMIN_HOMESERVER", "http://127.0.0.1:8008"
|
|
||||||
)
|
|
||||||
|
|
||||||
DATABASE_FILE = env(Path, "DATABASE_FILE", "data.sqlite")
|
DATABASE_FILE = env(Path, "DATABASE_FILE", "data.sqlite")
|
||||||
CREDENTIALS_FILE = env(Path, "CREDENTIALS_FILE", "credentials.json")
|
CREDENTIALS_FILE = env(Path, "CREDENTIALS_FILE", "credentials.json")
|
||||||
|
@ -68,3 +64,6 @@ icq_amount, icq_timespan = INVITE_CODE_QUOTA.split("/")
|
||||||
INVITE_CODE_QUOTA_AMOUNT = int(icq_amount)
|
INVITE_CODE_QUOTA_AMOUNT = int(icq_amount)
|
||||||
INVITE_CODE_QUOTA_TIMESPAN = td_parse(icq_timespan)
|
INVITE_CODE_QUOTA_TIMESPAN = td_parse(icq_timespan)
|
||||||
|
|
||||||
|
INVITE_CODE_EXPIRATION = env(
|
||||||
|
td_parse, "INVITE_CODE_EXPIRATION", datetime.timedelta(days=7)
|
||||||
|
)
|
||||||
|
|
|
@ -245,5 +245,3 @@ class Bot:
|
||||||
# TODO: better restart system
|
# TODO: better restart system
|
||||||
logger.exception("Restarting")
|
logger.exception("Restarting")
|
||||||
await asyncio.sleep(15)
|
await asyncio.sleep(15)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ from .env import DATABASE_FILE
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def db_apply_migrations():
|
async def db_apply_migrations():
|
||||||
if not os.path.exists(DATABASE_FILE):
|
if not os.path.exists(DATABASE_FILE):
|
||||||
async with aiosqlite.connect(DATABASE_FILE) as db:
|
async with aiosqlite.connect(DATABASE_FILE) as db:
|
||||||
|
@ -24,9 +25,11 @@ async def db_apply_migrations():
|
||||||
if file.name not in already_applied:
|
if file.name not in already_applied:
|
||||||
try:
|
try:
|
||||||
await db.executescript(file.read_text())
|
await db.executescript(file.read_text())
|
||||||
await db.execute("INSERT INTO sch_updates (filename) VALUES (?)", file.name)
|
await db.execute(
|
||||||
|
"INSERT INTO sch_updates (filename) VALUES (?)", file.name
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception('Failed to migrate!')
|
logger.exception("Failed to migrate!")
|
||||||
await db.rollback()
|
await db.rollback()
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -35,7 +35,7 @@ async def matrix_account_setup():
|
||||||
homeserver = MATRIX_HOMESERVER
|
homeserver = MATRIX_HOMESERVER
|
||||||
|
|
||||||
if not (homeserver.startswith("https://") or homeserver.startswith("http://")):
|
if not (homeserver.startswith("https://") or homeserver.startswith("http://")):
|
||||||
homeserver = "https://"+MATRIX_HOMESERVER
|
homeserver = "https://" + MATRIX_HOMESERVER
|
||||||
|
|
||||||
cfg = AsyncClientConfig(
|
cfg = AsyncClientConfig(
|
||||||
encryption_enabled=True,
|
encryption_enabled=True,
|
||||||
|
@ -44,7 +44,9 @@ async def matrix_account_setup():
|
||||||
)
|
)
|
||||||
os.makedirs(STORE_PATH, exist_ok=True)
|
os.makedirs(STORE_PATH, exist_ok=True)
|
||||||
|
|
||||||
client = AsyncClient(homeserver, MATRIX_USER_ID, config=cfg, store_path=str(STORE_PATH))
|
client = AsyncClient(
|
||||||
|
homeserver, MATRIX_USER_ID, config=cfg, store_path=str(STORE_PATH)
|
||||||
|
)
|
||||||
|
|
||||||
resp = await client.login(MATRIX_USER_PASSWORD, device_name=MATRIX_DEVICE_NAME)
|
resp = await client.login(MATRIX_USER_PASSWORD, device_name=MATRIX_DEVICE_NAME)
|
||||||
|
|
||||||
|
@ -56,10 +58,13 @@ async def matrix_account_setup():
|
||||||
write_details_to_disk(resp, homeserver)
|
write_details_to_disk(resp, homeserver)
|
||||||
|
|
||||||
assert client.olm is not None
|
assert client.olm is not None
|
||||||
key = client.olm.account.identity_keys['ed25519']
|
key = client.olm.account.identity_keys["ed25519"]
|
||||||
|
|
||||||
logger.info('Logged in as %s. Please manually verify this session.')
|
logger.info("Logged in as %s. Please manually verify this session.")
|
||||||
logger.info('Session fingerprint %s', ' '.join([key[i:i+4] for i in range(0, len(key), 4)]))
|
logger.info(
|
||||||
|
"Session fingerprint %s",
|
||||||
|
" ".join([key[i : i + 4] for i in range(0, len(key), 4)]),
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f'homeserver = "{homeserver}"; user = "{MATRIX_USER_ID}"')
|
print(f'homeserver = "{homeserver}"; user = "{MATRIX_USER_ID}"')
|
||||||
|
|
Loading…
Reference in a new issue