From 7037d8a92a305f3a1c0c050af2314efa09a276ea Mon Sep 17 00:00:00 2001 From: patdyn Date: Wed, 28 Aug 2024 14:37:51 +0200 Subject: [PATCH] Update secret generation and tests --- src/main/cljc/dda/c4k_keycloak/keycloak.cljc | 8 +++++--- src/main/resources/keycloak/secret.yaml | 5 ++--- src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc | 11 ++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/cljc/dda/c4k_keycloak/keycloak.cljc b/src/main/cljc/dda/c4k_keycloak/keycloak.cljc index 8a33df4..89e3355 100644 --- a/src/main/cljc/dda/c4k_keycloak/keycloak.cljc +++ b/src/main/cljc/dda/c4k_keycloak/keycloak.cljc @@ -42,12 +42,14 @@ [config config? auth auth?] (let [{:keys [namespace]} config - {:keys [keycloak-admin-user keycloak-admin-password]} auth] + {:keys [keycloak-admin-user keycloak-admin-password postgres-db-user postgres-db-password]} auth] (-> (yaml/load-as-edn "keycloak/secret.yaml") (cm/replace-all-matching "NAMESPACE" namespace) - (cm/replace-key-value :keycloak-user (b64/encode keycloak-admin-user)) - (cm/replace-key-value :keycloak-password (b64/encode keycloak-admin-password))))) + (cm/replace-all-matching "DBUSER" (b64/encode postgres-db-user)) + (cm/replace-all-matching "DBPW" (b64/encode postgres-db-password)) + (cm/replace-all-matching "ADMIN_USER" (b64/encode keycloak-admin-user)) + (cm/replace-all-matching "ADMIN_PASS" (b64/encode keycloak-admin-password))))) (defn-spec generate-service cp/map-or-seq? [config config?] diff --git a/src/main/resources/keycloak/secret.yaml b/src/main/resources/keycloak/secret.yaml index e10e2df..62fc1bd 100644 --- a/src/main/resources/keycloak/secret.yaml +++ b/src/main/resources/keycloak/secret.yaml @@ -1,4 +1,3 @@ -# TODO: Update generate-secret function apiVersion: v1 kind: Secret metadata: @@ -6,7 +5,7 @@ metadata: namespace: NAMESPACE type: Opaque data: - DB_USER: DBUSER - DB_PASSWORD: DBPW + KC_DB_USERNAME: DBUSER + KC_DB_PASSWORD: DBPW KEYCLOAK_ADMIN: ADMIN_USER KEYCLOAK_ADMIN_PASSWORD: ADMIN_PASS diff --git a/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc b/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc index 630a38f..1ca53e3 100644 --- a/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc +++ b/src/test/cljc/dda/c4k_keycloak/keycloak_test.cljc @@ -13,9 +13,14 @@ :metadata {:name "keycloak-secret", :namespace "keycloak"} :type "Opaque" :data - {:keycloak-user "dXNlcg==" - :keycloak-password "cGFzc3dvcmQ="}} - (cut/generate-secret {:namespace "keycloak" :fqdn "test.de"} {:keycloak-admin-user "user" :keycloak-admin-password "password"})))) + {:KEYCLOAK_ADMIN "dXNlcg==" + :KEYCLOAK_ADMIN_PASSWORD "cGFzc3dvcmQ=" + :DB_USER "a2V5Y2xvYWs=" + :DB_PASSWORD "ZGItcGFzc3dvcmQ="}} + (cut/generate-secret {:namespace "keycloak" :fqdn "test.de"} + {:keycloak-admin-user "user" :keycloak-admin-password "password" + :postgres-db-user "keycloak" + :postgres-db-password "db-password"})))) (deftest should-generate-deployment (is (= {:name "keycloak", :namespace "keycloak", :labels {:app "keycloak"}}