add fix_collation_mismatch function for db container
This commit is contained in:
172
abra.sh
172
abra.sh
@ -21,43 +21,40 @@ export PG_BACKUP_VERSION=v2
|
||||
export ENTRYPOINT_CSS_VERSION=v1
|
||||
|
||||
customize() {
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Usage: ... customize <assets_path>"
|
||||
exit 1
|
||||
fi
|
||||
asset_dir=$1
|
||||
for asset in $COPY_ASSETS; do
|
||||
source=$(echo $asset | cut -d "|" -f1)
|
||||
target=$(echo $asset | cut -d "|" -f2)
|
||||
echo copy $source to $target
|
||||
abra app cp $APP_NAME $asset_dir/$source $target
|
||||
done
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: ... customize <assets_path>"
|
||||
exit 1
|
||||
fi
|
||||
asset_dir=$1
|
||||
for asset in $COPY_ASSETS; do
|
||||
source=$(echo $asset | cut -d "|" -f1)
|
||||
target=$(echo $asset | cut -d "|" -f2)
|
||||
echo copy $source to $target
|
||||
abra app cp $APP_NAME $asset_dir/$source $target
|
||||
done
|
||||
}
|
||||
|
||||
shell(){
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Usage: ... shell <python code>"
|
||||
exit 1
|
||||
fi
|
||||
ak shell -c "$1" 2>&1 | quieten
|
||||
shell() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: ... shell <python code>"
|
||||
exit 1
|
||||
fi
|
||||
ak shell -c "$1" 2>&1 | quieten
|
||||
}
|
||||
|
||||
import_user() {
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Usage: ... import_user <users.csv>"
|
||||
exit 1
|
||||
fi
|
||||
source_file=$1
|
||||
filename=$(basename $source_file)
|
||||
abra app cp $APP_NAME $source_file worker:/tmp/
|
||||
abra app cmd -T $APP_NAME worker _import_user $filename
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: ... import_user <users.csv>"
|
||||
exit 1
|
||||
fi
|
||||
source_file=$1
|
||||
filename=$(basename $source_file)
|
||||
abra app cp $APP_NAME $source_file worker:/tmp/
|
||||
abra app cmd -T $APP_NAME worker _import_user $filename
|
||||
}
|
||||
|
||||
_import_user() {
|
||||
/manage.py shell -c """
|
||||
/manage.py shell -c """
|
||||
import csv
|
||||
new_user = User()
|
||||
with open('/tmp/$1', newline='') as file:
|
||||
@ -85,9 +82,9 @@ with open('/tmp/$1', newline='') as file:
|
||||
}
|
||||
|
||||
set_admin_pass() {
|
||||
password=$(cat /run/secrets/admin_pass)
|
||||
token=$(cat /run/secrets/admin_token)
|
||||
/manage.py shell -c """
|
||||
password=$(cat /run/secrets/admin_pass)
|
||||
token=$(cat /run/secrets/admin_token)
|
||||
/manage.py shell -c """
|
||||
import time
|
||||
i = 0
|
||||
while (not User.objects.filter(username='akadmin')):
|
||||
@ -122,45 +119,45 @@ else:
|
||||
}
|
||||
|
||||
rotate_db_pass() {
|
||||
db_password=$(cat /run/secrets/db_password)
|
||||
psql -U authentik -c """ALTER USER authentik WITH PASSWORD '$db_password';"""
|
||||
db_password=$(cat /run/secrets/db_password)
|
||||
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() {
|
||||
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 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
|
||||
enable_blueprint $@ 2>&1 | quieten
|
||||
sleep 1
|
||||
apply_blueprint $@
|
||||
sleep 1
|
||||
disable_blueprint $@ 2>&1 | quieten
|
||||
}
|
||||
|
||||
disable_blueprint() {
|
||||
blueprint_state False $@
|
||||
blueprint_state False $@
|
||||
}
|
||||
|
||||
enable_blueprint() {
|
||||
blueprint_state True $@
|
||||
blueprint_state True $@
|
||||
}
|
||||
|
||||
apply_blueprint() {
|
||||
echo apply blueprint $@
|
||||
ak apply_blueprint $@ 2>&1 | quieten
|
||||
echo apply blueprint $@
|
||||
ak apply_blueprint $@ 2>&1 | quieten
|
||||
}
|
||||
|
||||
blueprint_state() {
|
||||
/manage.py shell -c """
|
||||
/manage.py shell -c """
|
||||
import time
|
||||
blueprint_state=$1
|
||||
blueprint_path='$2'
|
||||
@ -178,9 +175,9 @@ print(f'{blueprint.name} enabled: {blueprint.enabled}')
|
||||
}
|
||||
|
||||
# This function adds each application with its name, slug and group if passed
|
||||
add_applications(){
|
||||
export APPLICATIONS
|
||||
/manage.py shell -c """
|
||||
add_applications() {
|
||||
export APPLICATIONS
|
||||
/manage.py shell -c """
|
||||
import json
|
||||
import os
|
||||
if os.environ['APPLICATIONS'] == '':
|
||||
@ -207,7 +204,7 @@ for name, details in applications.items():
|
||||
|
||||
## This function is for renaming apps - usage: rename "old name" "new name"
|
||||
rename() {
|
||||
/manage.py shell -c """
|
||||
/manage.py shell -c """
|
||||
old_name = '$1'
|
||||
new_name = '$2' if '$2' else old_name
|
||||
|
||||
@ -221,55 +218,51 @@ else:
|
||||
""" 2>&1 | quieten
|
||||
}
|
||||
|
||||
|
||||
|
||||
quieten(){
|
||||
# 'SyntaxWarning|version_regex|"http\['
|
||||
# is a workaround to get rid of some verbose syntax warnings, this might be fixed with another version
|
||||
grep -Pv '"level": "(info|debug)"|SyntaxWarning|version_regex|"http\[|RuntimeWarning:'
|
||||
quieten() {
|
||||
# 'SyntaxWarning|version_regex|"http\['
|
||||
# is a workaround to get rid of some verbose syntax warnings, this might be fixed with another version
|
||||
grep -Pv '"level": "(info|debug)"|SyntaxWarning|version_regex|"http\[|RuntimeWarning:'
|
||||
}
|
||||
|
||||
add_email_templates(){
|
||||
for file_path in "$@"; do
|
||||
add_email_templates() {
|
||||
for file_path in "$@"; do
|
||||
echo copy template $file_path
|
||||
abra app cp $APP_NAME $file_path app:/templates/
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
set_icons(){
|
||||
if [ -n "$1" ]
|
||||
then
|
||||
APP_ICONS="$1"
|
||||
fi
|
||||
for icon in $APP_ICONS; do
|
||||
set_icons() {
|
||||
if [ -n "$1" ]; then
|
||||
APP_ICONS="$1"
|
||||
fi
|
||||
for icon in $APP_ICONS; do
|
||||
app=$(echo $icon | cut -d ":" -f1)
|
||||
file_path=$(eval echo $(echo $icon | cut -d ":" -f2))
|
||||
file=$(basename $file_path)
|
||||
echo copy icon $file_path for $app
|
||||
abra app cp $APP_NAME $file_path app:/media/
|
||||
abra app cmd -T $APP_NAME app set_app_icon $app /media/$file
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
set_extra_icons(){
|
||||
if [ -z "$EXTRA_ICONS" ]
|
||||
then
|
||||
echo "Variable EXTRA_ICONS is not set"
|
||||
exit 1
|
||||
fi
|
||||
export EXTRA_ICONS
|
||||
icon_key_values=$(python3 -c "
|
||||
set_extra_icons() {
|
||||
if [ -z "$EXTRA_ICONS" ]; then
|
||||
echo "Variable EXTRA_ICONS is not set"
|
||||
exit 1
|
||||
fi
|
||||
export EXTRA_ICONS
|
||||
icon_key_values=$(python3 -c "
|
||||
import json
|
||||
import os
|
||||
for key, value in json.loads(os.environ['EXTRA_ICONS']).items():
|
||||
print(f'{key}:{value}')
|
||||
")
|
||||
set_icons "$icon_key_values"
|
||||
set_icons "$icon_key_values"
|
||||
}
|
||||
|
||||
set_app_icon() {
|
||||
TOKEN=$(cat /run/secrets/admin_token)
|
||||
python -c """
|
||||
TOKEN=$(cat /run/secrets/admin_token)
|
||||
python -c """
|
||||
import requests
|
||||
import os
|
||||
my_token = '$TOKEN'
|
||||
@ -288,18 +281,18 @@ with open(icon_path, 'rb') as img:
|
||||
}
|
||||
|
||||
blueprint_cleanup() {
|
||||
/manage.py shell -c """
|
||||
/manage.py shell -c """
|
||||
delete_flows = ['default-recovery-flow' , 'custom-authentication-flow' , 'invitation-enrollment-flow' , 'initial-setup']
|
||||
Flow.objects.filter(slug__in=delete_flows).delete()
|
||||
Stage.objects.filter(flow=None).delete()
|
||||
Prompt.objects.filter(promptstage=None).delete()
|
||||
Brand.objects.filter(default=True).delete()
|
||||
""" 2>&1 | quieten
|
||||
apply_blueprints
|
||||
apply_blueprints
|
||||
}
|
||||
|
||||
get_certificate() {
|
||||
/manage.py shell -c """
|
||||
/manage.py shell -c """
|
||||
provider_name='$1'
|
||||
if not provider_name:
|
||||
print('no Provider Name given')
|
||||
@ -312,7 +305,14 @@ print(''.join(cert.certificate_data.splitlines()[1:-1]))
|
||||
}
|
||||
|
||||
get_user_uid() {
|
||||
/manage.py shell -c """
|
||||
/manage.py shell -c """
|
||||
print(User.objects.filter(username='$1').first().uid)
|
||||
""" 2>&1 | quieten
|
||||
}
|
||||
|
||||
fix_collation_mismatch() {
|
||||
psql -U ${POSTGRES_USER} -d authentik -c "ALTER DATABASE authentik REFRESH COLLATION VERSION;"
|
||||
psql -U ${POSTGRES_USER} -d authentik -c "REINDEX DATABASE authentik;"
|
||||
psql -U ${POSTGRES_USER} -d postgres -c "ALTER DATABASE postgres REFRESH COLLATION VERSION;"
|
||||
psql -U ${POSTGRES_USER} -d postgres -c "REINDEX DATABASE postgres;"
|
||||
}
|
||||
|
Reference in New Issue
Block a user