diff --git a/src/main/clj/dda/c4k_common/uberjar.clj b/src/main/clj/dda/c4k_common/uberjar.clj index 3cf55cc..6d716c2 100644 --- a/src/main/clj/dda/c4k_common/uberjar.clj +++ b/src/main/clj/dda/c4k_common/uberjar.clj @@ -23,7 +23,7 @@ " name " {your configuraton file} {your authorization file}")) -(s/def ::options (s/* #{"-h" +(s/def ::options (s/* #{"-h" "-v" "--version" "-c" "--config" "-a" "--auth"})) @@ -91,21 +91,22 @@ auth-edn (auth-parse-fn 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 (cm/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}))))))))))) + (if (and config-valid? auth-valid?) + (println (cm/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}))))))))))) -; REVIEW gec: should this also be changed to main-cm? This would mean a breaking change. (defn -main [& cmd-args] - (main-common "c4k-common" - core/config? - core/auth? - core/config-defaults - core/k8s-objects - cmd-args)) \ No newline at end of file + (main-cm + "c4k-common" + core/config? + core/auth? + core/config-defaults + core/config-objects + core/auth-objects + cmd-args)) \ No newline at end of file diff --git a/src/main/cljc/dda/c4k_common/core.cljc b/src/main/cljc/dda/c4k_common/core.cljc index 98e78eb..c8675a2 100644 --- a/src/main/cljc/dda/c4k_common/core.cljc +++ b/src/main/cljc/dda/c4k_common/core.cljc @@ -7,15 +7,22 @@ (def config-defaults {}) -(def config? (s/keys :req-un [] +(def config? (s/keys :req-un [::monitoring/mon-cfg] :opt-un [])) -(def auth? (s/keys :req-un [] +(def auth? (s/keys :req-un [::monitoring/mon-auth] :opt-un [])) -(defn k8s-objects [config auth] +(defn config-objects [config] (let [] (map yaml/to-string (filter #(not (nil? %)) (cm/concat-vec - (monitoring/generate config auth)))))) \ No newline at end of file + (monitoring/generate-config)))))) + +(defn auth-objects [config auth] + (let [] + (map yaml/to-string + (filter #(not (nil? %)) + (cm/concat-vec + (monitoring/generate-auth (:mon-cfg config) (:mon-auth auth))))))) \ No newline at end of file diff --git a/src/test/cljc/dda/c4k_common/core_test.cljc b/src/test/cljc/dda/c4k_common/core_test.cljc new file mode 100644 index 0000000..a73e79c --- /dev/null +++ b/src/test/cljc/dda/c4k_common/core_test.cljc @@ -0,0 +1,22 @@ +(ns dda.c4k-common.core-test + (:require + #?(:cljs [shadow.resource :as rc]) + #?(:clj [clojure.test :refer [deftest is are testing run-tests]] + :cljs [cljs.test :refer-macros [deftest is are testing run-tests]]) + [clojure.spec.alpha :as s] + [dda.c4k-common.yaml :as yaml] + [dda.c4k-common.core :as cut])) + +#?(:cljs + (defmethod yaml/load-resource :common-test [resource-name] + (case resource-name + "common-test/valid-auth.yaml" (rc/inline "common-test/valid-auth.yaml") + "common-test/valid-config.yaml" (rc/inline "common-test/valid-config.yaml") + (throw (js/Error. "Undefined Resource!"))))) + +(def conf (yaml/load-as-edn "common-test/valid-config.yaml")) +(def auth (yaml/load-as-edn "common-test/valid-auth.yaml")) + +(deftest validate-valid-resources + (is (s/valid? cut/config? conf)) + (is (s/valid? cut/auth? auth))) diff --git a/src/test/resources/common-test/valid-auth.yaml b/src/test/resources/common-test/valid-auth.yaml new file mode 100644 index 0000000..2103b03 --- /dev/null +++ b/src/test/resources/common-test/valid-auth.yaml @@ -0,0 +1,3 @@ +mon-auth: + grafana-cloud-user: "user" + grafana-cloud-password: "password" diff --git a/src/test/resources/common-test/valid-config.yaml b/src/test/resources/common-test/valid-config.yaml new file mode 100644 index 0000000..08da11f --- /dev/null +++ b/src/test/resources/common-test/valid-config.yaml @@ -0,0 +1,4 @@ +mon-cfg: + grafana-cloud-url: "url-for-your-prom-remote-write-endpoint" + cluster-name: "forgejo" + cluster-stage: "test" \ No newline at end of file