add generic bash function addBasicAuthUser

This commit is contained in:
p.delpy@dkfz-heidelberg.de
2023-07-25 14:08:54 +02:00
parent 7feb903dfa
commit 788e4ea9f7
5 changed files with 42 additions and 2 deletions

View File

@ -183,3 +183,27 @@ function bk_is_running {
##Setting Network properties
# currently not needed
#export HOSTIP=$(MSYS_NO_PATHCONV=1 docker run --rm --add-host=host.docker.internal:host-gateway ubuntu cat /etc/hosts | grep 'host.docker.internal' | awk '{print $1}');
addBasicAuthUser() {
USER="${1}"
PASSWORD="${2}"
NAME="${3}"
PROJECT="${4}"
FILE="/etc/bridgehead/${PROJECT}.local.conf"
ENCRY_CREDENTIALS="$(docker run --rm docker.verbis.dkfz.de/cache/httpd:alpine htpasswd -nb $USER $PASSWORD | tr -d '\n' | tr -d '\r')"
if [ -f $FILE ] && grep -R -q "$NAME=" $FILE # if a basic auth user already exists:
then
sed -i "/$NAME/ s/$/,$ENCRY_CREDENTIALS/" $FILE
else
echo -e "\n## Basic Authentication Credentials for:\n$NAME=$ENCRY_CREDENTIALS" >> $FILE;
fi
read -p "Do you want to have your cleartext credentials saved in your $FILE: [y/n]" yn
case $yn in
[yYjJ] )
echo "ok, variables are saved in $FILE"
echo -e "# User: $USER\n# Password: $PASSWORD" >> $FILE;
;;
[nN] )
echo "skip saving cleartext LDM credentials; make sure to save them somewhere else"
;;
esac
}