Fix nondeterministic blueprint behaviour

This commit is contained in:
2023-08-01 02:20:40 +02:00
parent 3df66b1be7
commit 566bffb7af
6 changed files with 107 additions and 25 deletions

39
abra.sh
View File

@ -95,15 +95,24 @@ rotate_db_pass() {
psql -U authentik -c """ALTER USER authentik WITH PASSWORD '$db_password';"""
}
# This function is for blueprints that are overwriting custom blueprints
# It deactivates the affected custom blueprints to avoid changes to be reverted
apply_blueprints() {
enable_blueprint default/flow-default-authentication-flow.yaml
enable_blueprint default/flow-default-user-settings-flow.yaml
enable_blueprint default/flow-password-change.yaml
ak apply_blueprint 6_flow_invalidation.yaml 2>&1 | quieten
ak apply_blueprint 5_system_tenant.yaml 2>&1 | quieten
disable_blueprint default/flow-default-authentication-flow.yaml
disable_blueprint default/flow-default-user-settings-flow.yaml
disable_blueprint default/flow-password-change.yaml
update_and_disable_blueprint default/flow-password-change.yaml
update_and_disable_blueprint default/flow-default-authentication-flow.yaml
update_and_disable_blueprint default/flow-default-user-settings-flow.yaml
update_and_disable_blueprint default/flow-default-source-enrollment.yaml
apply_blueprint 3_flow_translation.yaml
apply_blueprint 2_flow_authentication.yaml
}
update_and_disable_blueprint() {
enable_blueprint $@ 2>&1 | quieten
sleep 1
apply_blueprint $@
sleep 1
disable_blueprint $@ 2>&1 | quieten
}
disable_blueprint() {
@ -114,12 +123,24 @@ enable_blueprint() {
blueprint_state True $@
}
apply_blueprint() {
echo apply blueprint $@
ak apply_blueprint $@ 2>&1 | quieten
}
blueprint_state() {
/manage.py shell -c """
import time
blueprint_state=$1
blueprint_path='$2'
blueprint = BlueprintInstance.objects.filter(path=blueprint_path).first()
blueprint.enabled = blueprint_state
# Hacky workaround to reduce chance of a race condition
blueprint.save()
time.sleep(1)
blueprint.save()
time.sleep(1)
blueprint.save()
print(f'{blueprint.name} enabled: {blueprint.enabled}')
""" 2>&1 | quieten
@ -146,7 +167,7 @@ for name, url in applications.items():
quieten(){
grep -v '{"event"'
grep -v -e '{"event"' -e '{"action"'
}
set_icons(){