2f469d2709
* stages/email: directly use email credentials from config Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use custom database backend that supports dynamic credentials Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add crude config reloader Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make method names for CONFIG clearer Signed-off-by: Jens Langhammer <jens@goauthentik.io> * replace config.set with environ Not sure if this is the cleanest way, but it persists through a config reload Signed-off-by: Jens Langhammer <jens@goauthentik.io> * re-add set for @patch Signed-off-by: Jens Langhammer <jens@goauthentik.io> * even more crudeness Signed-off-by: Jens Langhammer <jens@goauthentik.io> * clean up some old stuff? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * somewhat rewrite config loader to keep track of a source of an attribute so we can refresh it Signed-off-by: Jens Langhammer <jens@goauthentik.io> * cleanup old things Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix flow e2e Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io>
46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
# flake8: noqa
|
|
from uuid import uuid4
|
|
|
|
from authentik.lib.config import CONFIG
|
|
from lifecycle.migrate import BaseMigration
|
|
|
|
SQL_STATEMENT = """BEGIN TRANSACTION;
|
|
CREATE TABLE IF NOT EXISTS authentik_install_id (
|
|
id TEXT NOT NULL
|
|
);
|
|
COMMIT;"""
|
|
|
|
|
|
class Migration(BaseMigration):
|
|
def needs_migration(self) -> bool:
|
|
self.cur.execute(
|
|
"select * from information_schema.tables where table_name = 'authentik_install_id';"
|
|
)
|
|
return not bool(self.cur.rowcount)
|
|
|
|
def upgrade(self, migrate=False):
|
|
self.cur.execute(SQL_STATEMENT)
|
|
self.con.commit()
|
|
if migrate:
|
|
# If we already have migrations in the database, assume we're upgrading an existing install
|
|
# and set the install id to the secret key
|
|
self.cur.execute(
|
|
"INSERT INTO authentik_install_id (id) VALUES (%s)", (CONFIG.get("secret_key"),)
|
|
)
|
|
else:
|
|
# Otherwise assume a new install, generate an install ID based on a UUID
|
|
install_id = str(uuid4())
|
|
self.cur.execute("INSERT INTO authentik_install_id (id) VALUES (%s)", (install_id,))
|
|
self.con.commit()
|
|
|
|
def run(self):
|
|
self.cur.execute(
|
|
"select * from information_schema.tables where table_name = 'django_migrations';"
|
|
)
|
|
if not bool(self.cur.rowcount):
|
|
# No django_migrations table, so generate a new id
|
|
return self.upgrade(migrate=False)
|
|
self.cur.execute("select count(*) from django_migrations;")
|
|
migrations = self.cur.fetchone()[0]
|
|
return self.upgrade(migrate=migrations > 0)
|