Files
mtusi2026lab7/scripts/db-credentials.sh
T

17 lines
622 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
case ${1:-all} in
all) roles='api worker reconciler' ;;
worker) roles=worker ;;
*) exit 2 ;;
esac
for role in $roles; do
password=$(cat "secrets/operator/db_$role")
case "$password" in *[!a-f0-9]*|'') exit 2 ;; esac
# Передача по stdin, аутентификация оператора через Unix socket и peer map.
printf "ALTER ROLE %s PASSWORD '%s';\n" "$role" "$password" |
docker compose exec -T -u postgres postgres psql -X -U messenger -d messenger -v ON_ERROR_STOP=1 >/dev/null
done
echo 'PostgreSQL: SCRAM credentials настроены'