updated main function
This commit is contained in:
parent
b62fa7b9ec
commit
1bcbca58c8
5 changed files with 58 additions and 21 deletions
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
" name " {your configuraton file} {your authorization file}"))
|
" name " {your configuraton file} {your authorization file}"))
|
||||||
|
|
||||||
(s/def ::options (s/* #{"-h"
|
(s/def ::options (s/* #{"-h"
|
||||||
"-v" "--version"
|
"-v" "--version"
|
||||||
"-c" "--config"
|
"-c" "--config"
|
||||||
"-a" "--auth"}))
|
"-a" "--auth"}))
|
||||||
|
@ -91,21 +91,22 @@
|
||||||
auth-edn (auth-parse-fn auth-str)
|
auth-edn (auth-parse-fn auth-str)
|
||||||
config-valid? (s/valid? config-spec? config-edn)
|
config-valid? (s/valid? config-spec? config-edn)
|
||||||
auth-valid? (s/valid? auth-spec? auth-edn)]
|
auth-valid? (s/valid? auth-spec? auth-edn)]
|
||||||
(if (and config-valid? auth-valid?)
|
(if (and config-valid? auth-valid?)
|
||||||
(println (cm/generate-common config-edn auth-edn config-defaults k8s-objects))
|
(println (cm/generate-common config-edn auth-edn config-defaults k8s-objects))
|
||||||
(do
|
(do
|
||||||
(when (not config-valid?)
|
(when (not config-valid?)
|
||||||
(println
|
(println
|
||||||
(expound/expound-str config-spec? config-edn {:print-specs? false})))
|
(expound/expound-str config-spec? config-edn {:print-specs? false})))
|
||||||
(when (not auth-valid?)
|
(when (not auth-valid?)
|
||||||
(println
|
(println
|
||||||
(expound/expound-str auth-spec? auth-edn {:print-specs? false})))))))))))
|
(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]
|
(defn -main [& cmd-args]
|
||||||
(main-common "c4k-common"
|
(main-cm
|
||||||
core/config?
|
"c4k-common"
|
||||||
core/auth?
|
core/config?
|
||||||
core/config-defaults
|
core/auth?
|
||||||
core/k8s-objects
|
core/config-defaults
|
||||||
cmd-args))
|
core/config-objects
|
||||||
|
core/auth-objects
|
||||||
|
cmd-args))
|
|
@ -7,15 +7,22 @@
|
||||||
|
|
||||||
(def config-defaults {})
|
(def config-defaults {})
|
||||||
|
|
||||||
(def config? (s/keys :req-un []
|
(def config? (s/keys :req-un [::monitoring/mon-cfg]
|
||||||
:opt-un []))
|
:opt-un []))
|
||||||
|
|
||||||
(def auth? (s/keys :req-un []
|
(def auth? (s/keys :req-un [::monitoring/mon-auth]
|
||||||
:opt-un []))
|
:opt-un []))
|
||||||
|
|
||||||
(defn k8s-objects [config auth]
|
(defn config-objects [config]
|
||||||
(let []
|
(let []
|
||||||
(map yaml/to-string
|
(map yaml/to-string
|
||||||
(filter #(not (nil? %))
|
(filter #(not (nil? %))
|
||||||
(cm/concat-vec
|
(cm/concat-vec
|
||||||
(monitoring/generate config auth))))))
|
(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)))))))
|
22
src/test/cljc/dda/c4k_common/core_test.cljc
Normal file
22
src/test/cljc/dda/c4k_common/core_test.cljc
Normal file
|
@ -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)))
|
3
src/test/resources/common-test/valid-auth.yaml
Normal file
3
src/test/resources/common-test/valid-auth.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
mon-auth:
|
||||||
|
grafana-cloud-user: "user"
|
||||||
|
grafana-cloud-password: "password"
|
4
src/test/resources/common-test/valid-config.yaml
Normal file
4
src/test/resources/common-test/valid-config.yaml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
mon-cfg:
|
||||||
|
grafana-cloud-url: "url-for-your-prom-remote-write-endpoint"
|
||||||
|
cluster-name: "forgejo"
|
||||||
|
cluster-stage: "test"
|
Loading…
Reference in a new issue