diff --git a/src/main/cljc/dda/c4k_keycloak/core.cljc b/src/main/cljc/dda/c4k_keycloak/core.cljc index 1390fb8..e07ca03 100644 --- a/src/main/cljc/dda/c4k_keycloak/core.cljc +++ b/src/main/cljc/dda/c4k_keycloak/core.cljc @@ -15,8 +15,7 @@ (def config? (s/keys :req-un [::kc/fqdn] :opt-un [::kc/issuer])) -(def auth? (s/keys :req-un [::kc/keycloak-admin-user ::kc/keycloak-admin-password - ::postgres/postgres-db-user ::postgres/postgres-db-password])) +(def auth? (s/keys :req-un [::kc/keycloak-admin-user ::kc/keycloak-admin-password])) (defn-spec k8s-objects any? [config (s/merge config? auth?)] diff --git a/src/main/cljs/dda/c4k_keycloak/browser.cljs b/src/main/cljs/dda/c4k_keycloak/browser.cljs index 317e2b2..d90bfab 100644 --- a/src/main/cljs/dda/c4k_keycloak/browser.cljs +++ b/src/main/cljs/dda/c4k_keycloak/browser.cljs @@ -1,12 +1,39 @@ (ns dda.c4k-keycloak.browser (:require [clojure.tools.reader.edn :as edn] + [dda.c4k-common.common :as cm] + [dda.c4k-common.browser :as br] [dda.c4k-keycloak.core :as core] - [dda.c4k-keycloak.keycloak :as kc] - [dda.c4k-common.browser :as br])) + [dda.c4k-keycloak.keycloak :as kc])) + +(defn generate-content [] + (cm/concat-vec + [(assoc + (br/generate-needs-validation) :content + (cm/concat-vec + (br/generate-group + "domain" + (cm/concat-vec + (br/generate-input-field "fqdn" "Your fqdn:" "keycloak.prod.meissa.de") + (br/generate-input-field "issuer" "(Optional) Your issuer prod/staging:" ""))) + (br/generate-group + "credentials" + (br/generate-text-area "auth" "Your auth.edn:" ":keycloak-admin-user \"keycloak\" + :keycloak-admin-password \"adminpassword\"" + "5")) + [(br/generate-br)] + (br/generate-button "generate-button" "Generate c4k yaml")))] + (br/generate-output "c4k-keycloak-output" "Your c4k deployment.yaml:" "25"))) + +(defn generate-content-div + [] + {:type :element + :tag :div + :content + (generate-content)}) (defn config-from-document [] - (let [issuer (br/get-content-from-element "issuer" :optional true :deserializer keyword)] + (let [issuer (br/get-content-from-element "issuer" :optional true)] (merge {:fqdn (br/get-content-from-element "fqdn")} (when (some? issuer) @@ -14,26 +41,26 @@ (defn validate-all! [] (br/validate! "fqdn" ::kc/fqdn) - (br/validate! "issuer" ::kc/issuer :optional true :deserializer keyword) + (br/validate! "issuer" ::kc/issuer :optional true) (br/validate! "auth" core/auth? :deserializer edn/read-string) (br/set-validated!)) +(defn add-validate-listener [name] + (-> (br/get-element-by-id name) + (.addEventListener "blur" #(do (validate-all!))))) + (defn init [] + (br/append-hickory (generate-content-div)) (-> js/document (.getElementById "generate-button") (.addEventListener "click" #(do (validate-all!) - (-> (core/generate + (-> (cm/generate-common (config-from-document) - (br/get-content-from-element "auth" :deserializer edn/read-string)) + (br/get-content-from-element "auth" :deserializer edn/read-string) + {} + core/k8s-objects) (br/set-output!))))) - (-> (br/get-element-by-id "fqdn") - (.addEventListener "blur" - #(do (validate-all!)))) - (-> (br/get-element-by-id "issuer") - (.addEventListener "blur" - #(do (validate-all!)))) - (-> (br/get-element-by-id "auth") - (.addEventListener "blur" - #(do (validate-all!)))) - ) \ No newline at end of file + (add-validate-listener "fqdn") + (add-validate-listener "issuer") + (add-validate-listener "auth")) \ No newline at end of file