fediseer/overseer/classes/__init__.py

32 lines
957 B
Python
Raw Normal View History

2023-06-21 17:37:34 +00:00
import os
from loguru import logger
from overseer.argparser import args
from importlib import import_module
from overseer.flask import db, OVERSEER
from overseer.utils import hash_api_key
# Importing for DB creation
from overseer.classes.instance import Instance, Guarantee
with OVERSEER.app_context():
db.create_all()
2023-06-22 00:04:45 +00:00
admin_domain = os.getenv("OVERSEER_LEMMY_DOMAIN")
2023-06-21 17:37:34 +00:00
admin = db.session.query(Instance).filter_by(domain=admin_domain).first()
if not admin:
admin = Instance(
id=0,
domain=admin_domain,
2023-06-22 00:04:45 +00:00
api_key=hash_api_key(os.getenv("ADMIN_API_KEY")),
2023-06-21 17:37:34 +00:00
open_registrations=False,
email_verify=False,
2023-06-22 00:04:45 +00:00
software="lemmy",
2023-06-21 17:37:34 +00:00
)
admin.create()
guarantee = Guarantee(
guarantor_id = admin.id,
guaranteed_id = admin.id,
)
db.session.add(guarantee)
db.session.commit()