authentik.root.install_id
install ID
1"""install ID""" 2 3from functools import lru_cache 4from uuid import uuid4 5 6from psycopg import connect 7 8from authentik.lib.config import CONFIG 9 10# We need to string format the query as tables and schemas can't be set by parameters 11# not a security issue as the config value is set by the person installing authentik 12# which also has postgres credentials etc 13QUERY = """SELECT id FROM {}.authentik_install_id ORDER BY id LIMIT 1;""".format( # nosec 14 CONFIG.get("postgresql.default_schema") 15) 16 17 18@lru_cache 19def get_install_id() -> str: 20 """Get install ID of this instance. The method is cached as the install ID is 21 not expected to change""" 22 from django.conf import settings 23 from django.db import connection 24 25 if settings.TEST: 26 return str(uuid4()) 27 with connection.cursor() as cursor: 28 cursor.execute(QUERY) 29 return cursor.fetchone()[0] 30 31 32@lru_cache 33def get_install_id_raw(): 34 """Get install_id without django loaded, this is required for the startup when we get 35 the install_id but django isn't loaded yet and we can't use the function above.""" 36 conn = connect( 37 dbname=CONFIG.get("postgresql.name"), 38 user=CONFIG.get("postgresql.user"), 39 password=CONFIG.get("postgresql.password"), 40 host=CONFIG.get("postgresql.host"), 41 port=CONFIG.get_int("postgresql.port"), 42 sslmode=CONFIG.get("postgresql.sslmode"), 43 sslrootcert=CONFIG.get("postgresql.sslrootcert"), 44 sslcert=CONFIG.get("postgresql.sslcert"), 45 sslkey=CONFIG.get("postgresql.sslkey"), 46 ) 47 cursor = conn.cursor() 48 cursor.execute(QUERY) 49 return cursor.fetchone()[0]
QUERY =
'SELECT id FROM public.authentik_install_id ORDER BY id LIMIT 1;'
@lru_cache
def
get_install_id() -> str:
19@lru_cache 20def get_install_id() -> str: 21 """Get install ID of this instance. The method is cached as the install ID is 22 not expected to change""" 23 from django.conf import settings 24 from django.db import connection 25 26 if settings.TEST: 27 return str(uuid4()) 28 with connection.cursor() as cursor: 29 cursor.execute(QUERY) 30 return cursor.fetchone()[0]
Get install ID of this instance. The method is cached as the install ID is not expected to change
@lru_cache
def
get_install_id_raw():
33@lru_cache 34def get_install_id_raw(): 35 """Get install_id without django loaded, this is required for the startup when we get 36 the install_id but django isn't loaded yet and we can't use the function above.""" 37 conn = connect( 38 dbname=CONFIG.get("postgresql.name"), 39 user=CONFIG.get("postgresql.user"), 40 password=CONFIG.get("postgresql.password"), 41 host=CONFIG.get("postgresql.host"), 42 port=CONFIG.get_int("postgresql.port"), 43 sslmode=CONFIG.get("postgresql.sslmode"), 44 sslrootcert=CONFIG.get("postgresql.sslrootcert"), 45 sslcert=CONFIG.get("postgresql.sslcert"), 46 sslkey=CONFIG.get("postgresql.sslkey"), 47 ) 48 cursor = conn.cursor() 49 cursor.execute(QUERY) 50 return cursor.fetchone()[0]
Get install_id without django loaded, this is required for the startup when we get the install_id but django isn't loaded yet and we can't use the function above.