use replace named value function instead of index

* updated gitignore
* fixed tests
This commit is contained in:
bom 2021-05-28 12:18:05 +02:00
parent e56d261d91
commit 7df0ec866b
3 changed files with 26 additions and 12 deletions

4
.gitignore vendored
View file

@ -21,5 +21,5 @@ public/js/
*.iml
.idea/
myauth.edn
myconfig.edn
valid-auth.edn
valid-config.edn

View file

@ -30,6 +30,13 @@
(def auth? (s/keys :req-un [::keycloak-admin-user ::keycloak-admin-password
::postgres-db-user ::postgres-db-password]))
(defn replace-named-value
[coll name value]
(clojure.walk/postwalk #(if (and (map? %)
(= name (:name %)))
{:name name :value value}
%) coll))
(defn replace-all-matching-values-by-new-value
[coll value-to-match value-to-replace]
(clojure.walk/postwalk #(if (and (= (type value-to-match) (type %))
@ -51,17 +58,17 @@
keycloak-admin-user keycloak-admin-password]} my-auth]
(->
(yaml/from-string (yaml/load-resource "deployment.yaml"))
(assoc-in [:spec :template :spec :containers 0 :env 3 :value] postgres-db-user)
(assoc-in [:spec :template :spec :containers 0 :env 5 :value] postgres-db-password)
(assoc-in [:spec :template :spec :containers 0 :env 6 :value] keycloak-admin-user)
(assoc-in [:spec :template :spec :containers 0 :env 7 :value] keycloak-admin-password))))
(replace-named-value "KEYCLOAK_USER" keycloak-admin-user)
(replace-named-value "DB_USER" postgres-db-user)
(replace-named-value "DB_PASSWORD" postgres-db-password)
(replace-named-value "KEYCLOAK_PASSWORD" keycloak-admin-password))))
(defn generate-postgres-deployment [my-auth]
(let [{:keys [postgres-db-user postgres-db-password]} my-auth]
(->
(yaml/from-string (yaml/load-resource "postgres/postgres-deployment.yaml"))
(assoc-in [:spec :template :spec :containers 0 :env 0 :value] postgres-db-user)
(assoc-in [:spec :template :spec :containers 0 :env 2 :value] postgres-db-password))))
(replace-named-value "POSTGRES_USER" postgres-db-user)
(replace-named-value "POSTGRES_PASSWORD" postgres-db-password))))
(defn generate-certificate [config]
(let [{:keys [fqdn issuer]

View file

@ -77,12 +77,19 @@
[{:name "keycloak"
:image "quay.io/keycloak/keycloak:13.0.0"
:env
[{:name "KEYCLOAK_USER", :value "testuser"}
[{:name "DB_VENDOR", :value "POSTGRES"}
{:name "DB_ADDR", :value "postgresql-service"}
{:name "DB_DATABASE", :value "keycloak"}
{:name "DB_USER", :value "db-user"}
{:name "DB_SCHEMA", :value "public"}
{:name "DB_PASSWORD", :value "db-password"}
{:name "KEYCLOAK_USER", :value "testuser"}
{:name "KEYCLOAK_PASSWORD", :value "test1234"}
{:name "PROXY_ADDRESS_FORWARDING", :value "true"}]
:ports [{:name "http", :containerPort 8080}]
:readinessProbe {:httpGet {:path "/auth/realms/master", :port 8080}}}]}}}}
(cut/generate-deployment {:user-name "testuser" :user-password "test1234"}))))
(cut/generate-deployment {:keycloak-admin-user "testuser" :keycloak-admin-password "test1234"
:postgres-db-user "db-user" :postgres-db-password "db-password"}))))
(deftest should-generate-postgres-deployment
(is (= {:apiVersion "apps/v1"
@ -109,4 +116,4 @@
:subPath "postgresql.conf"
:readOnly true}]}]
:volumes [{:name "postgres-config-volume", :configMap {:name "postgres-config"}}]}}}}
(cut/generate-postgres-deployment {:postgres-user "psqluser" :postgres-db "keycloak" :postgres-password "test1234"}))))
(cut/generate-postgres-deployment {:postgres-db-user "psqluser" :postgres-db-password "test1234"}))))