Split for generation of config and auth objects #4

Merged
gec merged 9 commits from split-config-auth into main 2024-07-19 09:06:52 +00:00
5 changed files with 58 additions and 21 deletions
Showing only changes of commit 1bcbca58c8 - Show all commits

View file

@ -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))
(main-cm
"c4k-common"
core/config?
core/auth?
core/config-defaults
core/config-objects
core/auth-objects
cmd-args))

View file

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