diff --git a/project.clj b/project.clj index 379522a..d455038 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,7 @@ :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.10.3"] [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "1.1.0"] + [org.domaindrivenarchitecture/c4k-common-clj "1.1.4"] [hickory "0.7.1"]] :target-path "target/%s/" :source-paths ["src/main/cljc" diff --git a/src/main/clj/dda/c4k_shynet/uberjar.clj b/src/main/clj/dda/c4k_shynet/uberjar.clj index 49aed56..ff52279 100644 --- a/src/main/clj/dda/c4k_shynet/uberjar.clj +++ b/src/main/clj/dda/c4k_shynet/uberjar.clj @@ -1,65 +1,8 @@ (ns dda.c4k-shynet.uberjar (:gen-class) (:require - [clojure.spec.alpha :as s] - [clojure.string :as cs] - [clojure.tools.reader.edn :as edn] - [expound.alpha :as expound] - [dda.c4k-shynet.core :as core])) - -(def usage - "usage: - - c4k-shynet {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 generate-common [my-config my-auth config-defaults k8s-objects] - (let [resulting-config (merge config-defaults my-config my-auth)] - (cs/join - "\n---\n" - (k8s-objects resulting-config)))) - -(defn main-common [config-spec? auth-spec? config-defaults k8s-objects cmd-args] - (let [parsed-args-cmd (s/conform ::cmd-args cmd-args)] - (if (= ::s/invalid parsed-args-cmd) - (invalid-args-msg ::cmd-args cmd-args) - (let [{:keys [options args]} parsed-args-cmd - {:keys [config auth]} args] - (cond - (some #(= "-h" %) options) - (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? config-spec? config-edn) - auth-valid? (s/valid? auth-spec? auth-edn)] - (if (and config-valid? auth-valid?) - (println (generate-common config-edn auth-edn config-defaults k8s-objects)) - (do - (when (not config-valid?) - (println - (expound/expound-str config-spec? config-edn {:print-specs? false}))) - (when (not auth-valid?) - (println - (expound/expound-str auth-spec? auth-edn {:print-specs? false}))))))))))) + [dda.c4k-shynet.core :as core] + [dda.c4k-common.common :as common])) (defn -main [& cmd-args] - (main-common core/config? core/auth? core/config-defaults core/k8s-objects cmd-args)) + (common/main-common "c4k-shynet" core/config? core/auth? core/config-defaults core/k8s-objects cmd-args)) diff --git a/src/main/cljc/dda/c4k_shynet/core.cljc b/src/main/cljc/dda/c4k_shynet/core.cljc index 1c0099e..ffaf757 100644 --- a/src/main/cljc/dda/c4k_shynet/core.cljc +++ b/src/main/cljc/dda/c4k_shynet/core.cljc @@ -4,7 +4,6 @@ [clojure.spec.alpha :as s] #?(:clj [orchestra.core :refer [defn-spec]] :cljs [orchestra.core :refer-macros [defn-spec]]) - [dda.c4k-common.common :as cm] [dda.c4k-common.yaml :as yaml] [dda.c4k-common.postgres :as postgres] [dda.c4k-shynet.shynet :as shynet])) @@ -38,6 +37,7 @@ (shynet/generate-service-webserver) (shynet/generate-statefulset)]))) +; TODO: Remove once cljs release of common worked (defn-spec generate any? [my-config config? my-auth auth?]