cc6824fd7c
* core: bump django from 4.1.7 to 4.2 (#5151) * core: bump django from 4.1.7 to 4.2 Bumps [django](https://github.com/django/django) from 4.1.7 to 4.2. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/4.1.7...4.2) --- updated-dependencies: - dependency-name: django dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * upgrade to psycopg3, use custom engine for prometheus metrics See https://github.com/korfuri/django-prometheus/issues/350 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make scripts use pscopg3 Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start changelog Signed-off-by: Jens Langhammer <jens@goauthentik.io> * initial postgres upgrade guide Signed-off-by: Jens Langhammer <jens@goauthentik.io> * Apply suggestions from code review Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com> Signed-off-by: Jens L. <jens@beryju.org> Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update header Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Jens L. <jens@beryju.org> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com>
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""install ID"""
|
|
from functools import lru_cache
|
|
from uuid import uuid4
|
|
|
|
from psycopg import connect
|
|
|
|
from authentik.lib.config import CONFIG
|
|
|
|
|
|
@lru_cache
|
|
def get_install_id() -> str:
|
|
"""Get install ID of this instance. The method is cached as the install ID is
|
|
not expected to change"""
|
|
from django.conf import settings
|
|
from django.db import connection
|
|
|
|
if settings.TEST:
|
|
return str(uuid4())
|
|
with connection.cursor() as cursor:
|
|
cursor.execute("SELECT id FROM authentik_install_id LIMIT 1;")
|
|
return cursor.fetchone()[0]
|
|
|
|
|
|
@lru_cache
|
|
def get_install_id_raw():
|
|
"""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."""
|
|
conn = connect(
|
|
dbname=CONFIG.get("postgresql.name"),
|
|
user=CONFIG.get("postgresql.user"),
|
|
password=CONFIG.get("postgresql.password"),
|
|
host=CONFIG.get("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"),
|
|
)
|
|
cursor = conn.cursor()
|
|
cursor.execute("SELECT id FROM authentik_install_id LIMIT 1;")
|
|
return cursor.fetchone()[0]
|