mirror of
https://github.com/goauthentik/authentik
synced 2026-04-26 01:25:02 +02:00
* start db cache Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update codeowners Signed-off-by: Jens Langhammer <jens@goauthentik.io> * handle db error in keys Signed-off-by: Jens Langhammer <jens@goauthentik.io> * implement rest of the methods Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix unrelated warning on startup for cache Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix migrations? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add readme Signed-off-by: Jens Langhammer <jens@goauthentik.io> * dynamic dependency...? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * types Signed-off-by: Jens Langhammer <jens@goauthentik.io> * rip out django_redis Signed-off-by: Jens Langhammer <jens@goauthentik.io> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix get default Signed-off-by: Jens Langhammer <jens@goauthentik.io> * some cleanup Signed-off-by: Jens Langhammer <jens@goauthentik.io> * simplify to use ORM Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove old migrations that use cache instead of doing dynamic things Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix migration Signed-off-by: Jens Langhammer <jens@goauthentik.io> * Update packages/django-postgres-cache/django_postgres_cache/models.py Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * Update packages/django-postgres-cache/django_postgres_cache/migrations/0001_initial.py Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix redis imports Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * more redis removal Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * lint Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
58 lines
2.0 KiB
Python
Executable File
58 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
"""This file needs to be run from the root of the project to correctly
|
|
import authentik. This is done by the dockerfile."""
|
|
|
|
from sys import exit as sysexit
|
|
from time import sleep
|
|
|
|
from psycopg import OperationalError, connect
|
|
|
|
from authentik.lib.config import CONFIG
|
|
|
|
CHECK_THRESHOLD = 30
|
|
|
|
|
|
def check_postgres():
|
|
attempt = 0
|
|
while True:
|
|
if attempt >= CHECK_THRESHOLD:
|
|
sysexit(1)
|
|
try:
|
|
conn = connect(
|
|
dbname=CONFIG.refresh("postgresql.name"),
|
|
user=CONFIG.refresh("postgresql.user"),
|
|
password=CONFIG.refresh("postgresql.password"),
|
|
host=CONFIG.refresh("postgresql.host"),
|
|
port=CONFIG.get_int("postgresql.port"),
|
|
sslmode=CONFIG.get("postgresql.sslmode"),
|
|
sslrootcert=CONFIG.get("postgresql.sslrootcert"),
|
|
sslcert=CONFIG.get("postgresql.sslcert"),
|
|
sslkey=CONFIG.get("postgresql.sslkey"),
|
|
)
|
|
conn.cursor()
|
|
break
|
|
except OperationalError as exc:
|
|
sleep(1)
|
|
CONFIG.log("info", f"PostgreSQL connection failed, retrying... ({exc})")
|
|
finally:
|
|
attempt += 1
|
|
CONFIG.log("info", "PostgreSQL connection successful")
|
|
|
|
|
|
def wait_for_db():
|
|
CONFIG.log("info", "Starting authentik bootstrap")
|
|
# Sanity check, ensure SECRET_KEY is set before we even check for database connectivity
|
|
if CONFIG.get("secret_key") is None or len(CONFIG.get("secret_key")) == 0:
|
|
CONFIG.log("info", "----------------------------------------------------------------------")
|
|
CONFIG.log(
|
|
"info", "Secret key missing, check https://docs.goauthentik.io/docs/install-config/"
|
|
)
|
|
CONFIG.log("info", "----------------------------------------------------------------------")
|
|
sysexit(1)
|
|
check_postgres()
|
|
CONFIG.log("info", "Finished authentik bootstrap")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
wait_for_db()
|