diff --git a/public/index.html b/public/index.html index 748c57b..ea81702 100644 --- a/public/index.html +++ b/public/index.html @@ -12,12 +12,13 @@
- + +

- + -
+


diff --git a/src/main/cljc/dda/c4k_keycloak/core.cljc b/src/main/cljc/dda/c4k_keycloak/core.cljc index ad8ffdc..bf25e01 100644 --- a/src/main/cljc/dda/c4k_keycloak/core.cljc +++ b/src/main/cljc/dda/c4k_keycloak/core.cljc @@ -8,6 +8,8 @@ [dda.c4k-keycloak.keycloak :as kc] [dda.c4k-keycloak.postgres :as pg])) +(def config-defaults {:issuer :staging}) + (def config? (s/keys :req-un [::kc/fqdn] :opt-un [::kc/issuer])) @@ -17,21 +19,22 @@ (defn-spec generate any? [my-config config? my-auth auth?] - (cs/join "\n" - [(yaml/to-string (pg/generate-config)) - "---" - (yaml/to-string (pg/generate-secret my-auth)) - "---" - (yaml/to-string (pg/generate-service)) - "---" - (yaml/to-string (pg/generate-deployment)) - "---" - (yaml/to-string (kc/generate-secret my-auth)) - "---" - (yaml/to-string (kc/generate-certificate my-config)) - "---" - (yaml/to-string (kc/generate-ingress my-config)) - "---" - (yaml/to-string (kc/generate-service)) - "---" - (yaml/to-string (kc/generate-deployment))])) + (let [resulting-config (merge config-defaults my-config)] + (cs/join "\n" + [(yaml/to-string (pg/generate-config)) + "---" + (yaml/to-string (pg/generate-secret my-auth)) + "---" + (yaml/to-string (pg/generate-service)) + "---" + (yaml/to-string (pg/generate-deployment)) + "---" + (yaml/to-string (kc/generate-secret my-auth)) + "---" + (yaml/to-string (kc/generate-certificate resulting-config)) + "---" + (yaml/to-string (kc/generate-ingress resulting-config)) + "---" + (yaml/to-string (kc/generate-service)) + "---" + (yaml/to-string (kc/generate-deployment))]))) diff --git a/src/main/cljs/dda/c4k_keycloak/browser.cljs b/src/main/cljs/dda/c4k_keycloak/browser.cljs index 57c5249..9c57796 100644 --- a/src/main/cljs/dda/c4k_keycloak/browser.cljs +++ b/src/main/cljs/dda/c4k_keycloak/browser.cljs @@ -1,9 +1,11 @@ (ns dda.c4k-keycloak.browser (:require + [clojure.string :as st] [clojure.spec.alpha :as s] [clojure.tools.reader.edn :as edn] [expound.alpha :as expound] - [dda.c4k-keycloak.core :as core])) + [dda.c4k-keycloak.core :as core] + [dda.c4k-keycloak.keycloak :as kc])) (defn print-debug [sth] (print "debug " sth) @@ -20,10 +22,13 @@ (defn issuer-from-document [] (let [issuer-str (-> (issuer) (.-value))] - (if (= issuer-str "") - :staging + (when-not (st/blank? issuer-str) (keyword issuer-str)))) +(defn fqdn-from-document [] + (-> (fqdn) + (.-value))) + (defn auth [] (-> js/document (.getElementById "auth"))) @@ -33,13 +38,14 @@ (.getElementById "form"))) (defn config-from-document [] - {:fqdn (-> (fqdn) - (.-value)) - :issuer (issuer-from-document)}) + (merge + {:fqdn (fqdn-from-document)} + (when-not (st/blank? (issuer-from-document)) + {:issuer (issuer-from-document)}))) -(defn auth-from-document [] - (edn/read-string (-> (auth) - (.-value)))) + (defn auth-from-document [] + (edn/read-string (-> (auth) + (.-value)))) (defn set-output! [input] @@ -48,24 +54,41 @@ (.-value) (set! input))) -(defn set-config-validation-result! +(defn set-fqdn-validation-result! [validation-result] (-> js/document - (.getElementById "config-validation") + (.getElementById "fqdn-validation") (.-innerHTML) (set! validation-result)) (-> (fqdn) (.setCustomValidity validation-result)) + validation-result) + +(defn set-issuer-validation-result! + [validation-result] + (-> js/document + (.getElementById "issuer-validation") + (.-innerHTML) + (set! validation-result)) (-> (issuer) (.setCustomValidity validation-result)) validation-result) -(defn validate-config! [] - (let [config-map (config-from-document)] - (if (s/valid? core/config? config-map) - (set-config-validation-result! "") - (set-config-validation-result! - (expound/expound-str core/config? config-map {:print-specs? false}))))) +(defn validate-fqdn! [] + (let [fqdn (fqdn-from-document)] + (if (s/valid? ::kc/fqdn fqdn) + (set-fqdn-validation-result! "") + (set-fqdn-validation-result! + (expound/expound-str ::kc/fqdn fqdn {:print-specs? false}))))) + +(defn validate-issuer! [] + (let [issuer (issuer-from-document)] + (print-debug (js->clj issuer)) + (print-debug (st/blank? issuer)) + (if (or (st/blank? issuer) (s/valid? ::kc/issuer issuer)) + (set-issuer-validation-result! "") + (set-issuer-validation-result! + (expound/expound-str ::kc/issuer issuer {:print-specs? false}))))) (defn set-validated! [] (-> (form) @@ -89,27 +112,27 @@ (set-auth-validation-result! (expound/expound-str core/auth? auth-map {:print-specs? false}))))) +(defn validate-all! [] + (validate-fqdn!) + (validate-issuer!) + (validate-auth!) + (set-validated!)) + + (defn init [] (-> js/document (.getElementById "generate-button") (.addEventListener "click" - #(do (validate-config!) - (validate-auth!) - (set-validated!) + #(do (validate-all!) (-> (core/generate (config-from-document) (auth-from-document)) (set-output!))))) (-> (fqdn) (.addEventListener "blur" - #(do (validate-config!) - (validate-auth!) - (set-validated!)))) - (-> (auth) - (.addEventListener "blur" - #(do (validate-config!) - (validate-auth!) - (set-validated!)))) + #(do (validate-all!)))) (-> (issuer) (.addEventListener "blur" - #(do (validate-config!) - (validate-auth!) - (set-validated!))))) \ No newline at end of file + #(do (validate-all!)))) + (-> (auth) + (.addEventListener "blur" + #(do (validate-all!)))) + ) \ No newline at end of file