Files
cemmetering-preprocessor/deployment/roll-db-credential.sh
2023-11-09 17:57:55 +01:00

34 lines
622 B
Bash
Executable File

#!/bin/bash
. ~/Workspace/MyKubernetesEnv/ENVDB
DATABASE=cem_monitoring_berresheim
LOGIN=cem_preprocessor
PASSWORD=`openssl rand -base64 24`
NAMESPACE=`cat namespace`
psql <<EOF
do
\$\$
begin
if not exists (SELECT * FROM pg_user WHERE usename = '$LOGIN') then
CREATE USER $LOGIN WITH PASSWORD '$PASSWORD';
else
ALTER USER $LOGIN WITH PASSWORD '$PASSWORD';
end if;
end
\$\$
;
commit;
EOF
kubectl create secret generic cemmetering-db-cred \
--dry-run=client \
-o yaml \
--save-config \
--from-literal=PGUSER="$LOGIN" \
--from-literal=PGPASSWORD="$PASSWORD" | \
kubectl apply -f - -n $NAMESPACE