validation based on value
This commit is contained in:
parent
2466dbc85f
commit
3c4be8b8ff
3 changed files with 79 additions and 52 deletions
|
@ -12,12 +12,13 @@
|
|||
<body>
|
||||
<div class="container jumbotron">
|
||||
<form class="needs-validation" id="form">
|
||||
<label for="config" class="form-label">Your fqdn:</label>
|
||||
<label for="fqdn" class="form-label">Your fqdn:</label>
|
||||
<input class="form-control" type="text" name="fqdn" id="fqdn" value="your.domain.com">
|
||||
<div class="invalid-feedback"><pre id="fqdn-validation"></pre></div>
|
||||
<br>
|
||||
<label for="config" class="form-label">(Optional) Your issuer prod/staging:</label>
|
||||
<label for="issuer" class="form-label">(Optional) Your issuer prod/staging:</label>
|
||||
<input class="form-control" type="text" name="issuer" id="issuer" value="">
|
||||
<div class="invalid-feedback"><pre id="config-validation"></pre></div>
|
||||
<div class="invalid-feedback"><pre id="issuer-validation"></pre></div>
|
||||
<br><br>
|
||||
|
||||
<label for="auth" class="form-label">Your auth.edn:</label>
|
||||
|
|
|
@ -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,6 +19,7 @@
|
|||
(defn-spec generate any?
|
||||
[my-config config?
|
||||
my-auth auth?]
|
||||
(let [resulting-config (merge config-defaults my-config)]
|
||||
(cs/join "\n"
|
||||
[(yaml/to-string (pg/generate-config))
|
||||
"---"
|
||||
|
@ -28,10 +31,10 @@
|
|||
"---"
|
||||
(yaml/to-string (kc/generate-secret my-auth))
|
||||
"---"
|
||||
(yaml/to-string (kc/generate-certificate my-config))
|
||||
(yaml/to-string (kc/generate-certificate resulting-config))
|
||||
"---"
|
||||
(yaml/to-string (kc/generate-ingress my-config))
|
||||
(yaml/to-string (kc/generate-ingress resulting-config))
|
||||
"---"
|
||||
(yaml/to-string (kc/generate-service))
|
||||
"---"
|
||||
(yaml/to-string (kc/generate-deployment))]))
|
||||
(yaml/to-string (kc/generate-deployment))])))
|
||||
|
|
|
@ -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,11 +38,12 @@
|
|||
(.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 []
|
||||
(defn auth-from-document []
|
||||
(edn/read-string (-> (auth)
|
||||
(.-value))))
|
||||
|
||||
|
@ -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!))))
|
||||
)
|
Loading…
Reference in a new issue