use replace named value function instead of index
* updated gitignore * fixed tests
This commit is contained in:
parent
e56d261d91
commit
7df0ec866b
3 changed files with 26 additions and 12 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -21,5 +21,5 @@ public/js/
|
||||||
*.iml
|
*.iml
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
myauth.edn
|
valid-auth.edn
|
||||||
myconfig.edn
|
valid-config.edn
|
||||||
|
|
|
@ -30,9 +30,16 @@
|
||||||
(def auth? (s/keys :req-un [::keycloak-admin-user ::keycloak-admin-password
|
(def auth? (s/keys :req-un [::keycloak-admin-user ::keycloak-admin-password
|
||||||
::postgres-db-user ::postgres-db-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
|
(defn replace-all-matching-values-by-new-value
|
||||||
[coll value-to-match value-to-replace]
|
[coll value-to-match value-to-replace]
|
||||||
(clojure.walk/postwalk #(if (and (= (type value-to-match) (type %))
|
(clojure.walk/postwalk #(if (and (= (type value-to-match) (type %))
|
||||||
(= value-to-match %))
|
(= value-to-match %))
|
||||||
value-to-replace
|
value-to-replace
|
||||||
%) coll))
|
%) coll))
|
||||||
|
@ -51,17 +58,17 @@
|
||||||
keycloak-admin-user keycloak-admin-password]} my-auth]
|
keycloak-admin-user keycloak-admin-password]} my-auth]
|
||||||
(->
|
(->
|
||||||
(yaml/from-string (yaml/load-resource "deployment.yaml"))
|
(yaml/from-string (yaml/load-resource "deployment.yaml"))
|
||||||
(assoc-in [:spec :template :spec :containers 0 :env 3 :value] postgres-db-user)
|
(replace-named-value "KEYCLOAK_USER" keycloak-admin-user)
|
||||||
(assoc-in [:spec :template :spec :containers 0 :env 5 :value] postgres-db-password)
|
(replace-named-value "DB_USER" postgres-db-user)
|
||||||
(assoc-in [:spec :template :spec :containers 0 :env 6 :value] keycloak-admin-user)
|
(replace-named-value "DB_PASSWORD" postgres-db-password)
|
||||||
(assoc-in [:spec :template :spec :containers 0 :env 7 :value] keycloak-admin-password))))
|
(replace-named-value "KEYCLOAK_PASSWORD" keycloak-admin-password))))
|
||||||
|
|
||||||
(defn generate-postgres-deployment [my-auth]
|
(defn generate-postgres-deployment [my-auth]
|
||||||
(let [{:keys [postgres-db-user postgres-db-password]} my-auth]
|
(let [{:keys [postgres-db-user postgres-db-password]} my-auth]
|
||||||
(->
|
(->
|
||||||
(yaml/from-string (yaml/load-resource "postgres/postgres-deployment.yaml"))
|
(yaml/from-string (yaml/load-resource "postgres/postgres-deployment.yaml"))
|
||||||
(assoc-in [:spec :template :spec :containers 0 :env 0 :value] postgres-db-user)
|
(replace-named-value "POSTGRES_USER" postgres-db-user)
|
||||||
(assoc-in [:spec :template :spec :containers 0 :env 2 :value] postgres-db-password))))
|
(replace-named-value "POSTGRES_PASSWORD" postgres-db-password))))
|
||||||
|
|
||||||
(defn generate-certificate [config]
|
(defn generate-certificate [config]
|
||||||
(let [{:keys [fqdn issuer]
|
(let [{:keys [fqdn issuer]
|
||||||
|
|
|
@ -77,12 +77,19 @@
|
||||||
[{:name "keycloak"
|
[{:name "keycloak"
|
||||||
:image "quay.io/keycloak/keycloak:13.0.0"
|
:image "quay.io/keycloak/keycloak:13.0.0"
|
||||||
:env
|
: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 "KEYCLOAK_PASSWORD", :value "test1234"}
|
||||||
{:name "PROXY_ADDRESS_FORWARDING", :value "true"}]
|
{:name "PROXY_ADDRESS_FORWARDING", :value "true"}]
|
||||||
:ports [{:name "http", :containerPort 8080}]
|
:ports [{:name "http", :containerPort 8080}]
|
||||||
:readinessProbe {:httpGet {:path "/auth/realms/master", :port 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
|
(deftest should-generate-postgres-deployment
|
||||||
(is (= {:apiVersion "apps/v1"
|
(is (= {:apiVersion "apps/v1"
|
||||||
|
@ -109,4 +116,4 @@
|
||||||
:subPath "postgresql.conf"
|
:subPath "postgresql.conf"
|
||||||
:readOnly true}]}]
|
:readOnly true}]}]
|
||||||
:volumes [{:name "postgres-config-volume", :configMap {:name "postgres-config"}}]}}}}
|
: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"}))))
|
||||||
|
|
Loading…
Reference in a new issue