standardized uberjar

This commit is contained in:
jerger 2022-12-23 18:09:30 +01:00
parent 5bd198b80f
commit b852a74dc5
3 changed files with 23 additions and 62 deletions

View file

@ -1,56 +1,15 @@
(ns dda.c4k-jitsi.uberjar (ns dda.c4k-jitsi.uberjar
(:gen-class) (:gen-class)
(:require (:require
[clojure.spec.alpha :as s] [dda.c4k-common.uberjar :as uberjar]
[clojure.string :as cs] [dda.c4k-jitsi.core :as core]
[clojure.tools.reader.edn :as edn] [dda.c4k-jitsi.jitsi :as jitsi]))
[expound.alpha :as expound]
[dda.c4k-jitsi.core :as core]))
(def usage
"usage:
c4k-jitsi {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-jitsi"
(invalid-args-msg ::cmd-args cmd-args) jitsi/config?
(let [{:keys [options args]} parsed-args-cmd jitsi/auth?
{:keys [config auth]} args] core/config-defaults
(cond core/generate
(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})))))))))))

View file

@ -9,11 +9,6 @@
(def config-defaults {:issuer :staging}) (def config-defaults {:issuer :staging})
(def config? (s/keys :req-un [::jitsi/fqdn]
:opt-un [::jitsi/issuer ::jitsi/ingress-type]))
(def auth? (s/keys :req-un [::jitsi/jvb-auth-password ::jitsi/jicofo-auth-password ::jitsi/jicofo-component-secret]))
(defn k8s-objects [config] (defn k8s-objects [config]
(map yaml/to-string (map yaml/to-string
[(jitsi/generate-secret-jitsi config) [(jitsi/generate-secret-jitsi config)
@ -27,9 +22,9 @@
(jitsi/generate-deployment config)])) (jitsi/generate-deployment config)]))
(defn-spec generate any? (defn-spec generate any?
[my-config config? [my-config jitsi/config?
my-auth auth?] my-auth jitsi/auth?]
(let [resulting-config (merge config-defaults my-config my-auth)] (cm/concat-vec
(cs/join (map yaml/to-string
"\n---\n" (filter #(not (nil? %))
(k8s-objects resulting-config)))) (merge config-defaults my-config my-auth)))))

View file

@ -13,6 +13,13 @@
(s/def ::jicofo-auth-password pred/bash-env-string?) (s/def ::jicofo-auth-password pred/bash-env-string?)
(s/def ::jicofo-component-secret pred/bash-env-string?) (s/def ::jicofo-component-secret pred/bash-env-string?)
(def config? (s/keys :req-un [::fqdn]
:opt-un [::issuer ::ingress-type]))
(def auth? (s/keys :req-un [::jvb-auth-password
::jicofo-auth-password
::jicofo-component-secret]))
#?(:cljs #?(:cljs
(defmethod yaml/load-resource :jitsi [resource-name] (defmethod yaml/load-resource :jitsi [resource-name]
(case resource-name (case resource-name