|
|
|
@ -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!)))))
|
|
|
|
|
#(do (validate-all!))))
|
|
|
|
|
(-> (auth)
|
|
|
|
|
(.addEventListener "blur"
|
|
|
|
|
#(do (validate-all!))))
|
|
|
|
|
)
|