Use common uberjar
This commit is contained in:
parent
45507aade6
commit
6e02e57a8f
1 changed files with 8 additions and 50 deletions
|
@ -1,56 +1,14 @@
|
||||||
(ns dda.c4k-keycloak.uberjar
|
(ns dda.c4k-keycloak.uberjar
|
||||||
(:gen-class)
|
(:gen-class)
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[dda.c4k-common.uberjar :as uberjar]
|
||||||
[clojure.string :as cs]
|
|
||||||
[clojure.tools.reader.edn :as edn]
|
|
||||||
[expound.alpha :as expound]
|
|
||||||
[dda.c4k-keycloak.core :as core]))
|
[dda.c4k-keycloak.core :as core]))
|
||||||
|
|
||||||
(def usage
|
|
||||||
"usage:
|
|
||||||
|
|
||||||
c4k-keycloak {your configuraton file} {your authorization file}")
|
|
||||||
|
|
||||||
(s/def ::options (s/* #{"-h"}))
|
|
||||||
(s/def ::filename (s/and string?
|
|
||||||
#(not (cs/starts-with? % "-"))))
|
|
||||||
(s/def ::cmd-args (s/cat :options ::options
|
|
||||||
:args (s/?
|
|
||||||
(s/cat :config ::filename
|
|
||||||
:auth ::filename))))
|
|
||||||
|
|
||||||
(defn expound-config
|
|
||||||
[config]
|
|
||||||
(expound/expound ::core/config config))
|
|
||||||
|
|
||||||
(defn invalid-args-msg
|
|
||||||
[spec args]
|
|
||||||
(s/explain spec args)
|
|
||||||
(println (str "Bad commandline arguments\n" usage)))
|
|
||||||
|
|
||||||
(defn -main [& cmd-args]
|
(defn -main [& cmd-args]
|
||||||
(let [parsed-args-cmd (s/conform ::cmd-args cmd-args)]
|
(uberjar/main-common
|
||||||
(if (= ::s/invalid parsed-args-cmd)
|
"c4k-keycloak"
|
||||||
(invalid-args-msg ::cmd-args cmd-args)
|
core/config?
|
||||||
(let [{:keys [options args]} parsed-args-cmd
|
core/auth?
|
||||||
{:keys [config auth]} args]
|
core/config-defaults
|
||||||
(cond
|
core/k8s-objects
|
||||||
(some #(= "-h" %) options)
|
cmd-args))
|
||||||
(println usage)
|
|
||||||
:default
|
|
||||||
(let [config-str (slurp config)
|
|
||||||
auth-str (slurp auth)
|
|
||||||
config-edn (edn/read-string config-str)
|
|
||||||
auth-edn (edn/read-string auth-str)
|
|
||||||
config-valid? (s/valid? core/config? config-edn)
|
|
||||||
auth-valid? (s/valid? core/auth? auth-edn)]
|
|
||||||
(if (and config-valid? auth-valid?)
|
|
||||||
(println (core/generate config-edn auth-edn))
|
|
||||||
(do
|
|
||||||
(when (not config-valid?)
|
|
||||||
(println
|
|
||||||
(expound/expound-str core/config? config-edn {:print-specs? false})))
|
|
||||||
(when (not auth-valid?)
|
|
||||||
(println
|
|
||||||
(expound/expound-str core/auth? auth-edn {:print-specs? false})))))))))))
|
|
||||||
|
|
Loading…
Reference in a new issue