updated main function

This commit is contained in:
Clemens 2024-07-19 10:47:06 +02:00
parent b62fa7b9ec
commit 1bcbca58c8
5 changed files with 58 additions and 21 deletions

View file

@ -101,11 +101,12 @@
(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
"c4k-common"
core/config? core/config?
core/auth? core/auth?
core/config-defaults core/config-defaults
core/k8s-objects core/config-objects
core/auth-objects
cmd-args)) cmd-args))

View file

@ -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)))))))

View 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)))

View file

@ -0,0 +1,3 @@
mon-auth:
grafana-cloud-user: "user"
grafana-cloud-password: "password"

View file

@ -0,0 +1,4 @@
mon-cfg:
grafana-cloud-url: "url-for-your-prom-remote-write-endpoint"
cluster-name: "forgejo"
cluster-stage: "test"