From 441f65594b999a690999aae1dea647d9f7267412 Mon Sep 17 00:00:00 2001 From: Daan Asscheman Date: Mon, 24 Jun 2024 16:16:14 +0200 Subject: [PATCH] Add database credentials --- openshift/config/06_sample-app.yaml | 12 ++++++------ openshift/openshift.env | 3 +++ openshift/scripts/sample-app.sh | 27 +++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/openshift/config/06_sample-app.yaml b/openshift/config/06_sample-app.yaml index 752ede0..0e85cbb 100644 --- a/openshift/config/06_sample-app.yaml +++ b/openshift/config/06_sample-app.yaml @@ -21,32 +21,32 @@ spec: ports: - containerPort: 9000 env: - - name: LARAVEL_DATABASE_TYPE + - name: DB_CONNECTION valueFrom: configMapKeyRef: name: sample-config key: database-type - - name: LARAVEL_DATABASE_HOST + - name: DB_HOST valueFrom: configMapKeyRef: name: sample-config key: database-host - - name: LARAVEL_DATABASE_PORT_NUMBER + - name: DB_PORT valueFrom: configMapKeyRef: name: sample-config key: database-port-number - - name: LARAVEL_DATABASE_NAME + - name: DB_DATABASE valueFrom: configMapKeyRef: name: sample-config key: database-name - - name: LARAVEL_DATABASE_USER + - name: DB_USERNAME valueFrom: configMapKeyRef: name: mariadb-config key: mariadb-user - - name: LARAVEL_DATABASE_PASSWORD + - name: DB_PASSWORD valueFrom: secretKeyRef: name: mariadb-secret diff --git a/openshift/openshift.env b/openshift/openshift.env index 2e4c2bd..3c8a98e 100644 --- a/openshift/openshift.env +++ b/openshift/openshift.env @@ -11,6 +11,9 @@ LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=mariadb-sample DB_PORT=3306 +DB_DATABASE=development +DB_USERNAME=development +DB_PASSWORD=secret BROADCAST_DRIVER=log CACHE_DRIVER=file diff --git a/openshift/scripts/sample-app.sh b/openshift/scripts/sample-app.sh index 81d0fe3..788e01b 100755 --- a/openshift/scripts/sample-app.sh +++ b/openshift/scripts/sample-app.sh @@ -12,8 +12,31 @@ create_app() { search_dir=../config for entry in "$search_dir"/* do - echo "$entry" - oc apply -f $entry + filename=$(basename -- "$entry") + if [ -f ../temp/"$filename" ]; then + echo "Use previously made file with credentials" + oc apply -f ../temp/"$filename" + continue + fi + + echo "Check for file with credential" + match=$(grep -o \<.*\> "$entry" | wc -l) + if [ "$match" -ne "0" ]; then + echo "Found credentials in file" + # TODO: Create loop and ceck ninimal length of password + word1=$(shuf -n1 /usr/share/dict/american-english | sed "s/'//g") + word2=$(shuf -n1 /usr/share/dict/american-english | sed "s/'//g") + word3=$(shuf -n1 /usr/share/dict/american-english | sed "s/'//g") + word="${word1}-${word2}-${word3}" + echo "used password: $word for $filename" + hash="$(echo -n $word | base64)" + echo $hash + sed "s/<.*>/"$hash"/g" "$entry" > ../temp/"$filename" + oc apply -f ../temp/"$filename" + continue + fi + echo "$entry" + oc apply -f "$entry" done }