Move spec to gitea and instrument generate functions

This commit is contained in:
bom 2022-06-17 10:26:59 +02:00
parent 08ac2ae1c2
commit 810ff3783f
4 changed files with 24 additions and 15 deletions

View file

@ -2,7 +2,8 @@
(:gen-class)
(:require
[dda.c4k-gitea.core :as core]
[dda.c4k-gitea.gitea :as gitea]
[dda.c4k-common.uberjar :as uberjar]))
(defn -main [& cmd-args]
(uberjar/main-common "c4k-gitea" core/config? core/auth? core/config-defaults core/k8s-objects cmd-args))
(uberjar/main-common "c4k-gitea" gitea/config? gitea/auth? gitea/config-defaults core/k8s-objects cmd-args))

View file

@ -1,18 +1,9 @@
(ns dda.c4k-gitea.core
(:require
[clojure.spec.alpha :as s]
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.common :as cm]
[dda.c4k-common.postgres :as postgres]
[dda.c4k-gitea.gitea :as gitea]))
(def config-defaults {:issuer "staging"})
(def config? (s/keys :req-un [::gitea/fqdn]
:opt-un [::gitea/issuer]))
(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password]))
(defn k8s-objects [config]
(let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)]
(cm/concat-vec

View file

@ -2,13 +2,23 @@
(:require
[clojure.spec.alpha :as s]
#?(:cljs [shadow.resource :as rc])
#?(:clj [orchestra.core :refer [defn-spec]]
:cljs [orchestra.core :refer-macros [defn-spec]])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.common :as cm]
[dda.c4k-common.predicate :as pred]))
[dda.c4k-common.predicate :as pred]
[dda.c4k-common.postgres :as postgres]))
(s/def ::fqdn pred/fqdn-string?)
(s/def ::issuer pred/letsencrypt-issuer?)
(def config-defaults {:issuer "staging"})
(def config? (s/keys :req-un [::fqdn]
:opt-un [::issuer]))
(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password]))
#?(:cljs
(defmethod yaml/load-resource :gitea [resource-name]
(case resource-name
@ -24,7 +34,9 @@
(defmethod yaml/load-as-edn :gitea [resource-name]
(yaml/from-string (yaml/load-resource resource-name))))
(defn generate-appini-env [config]
(defn-spec generate-appini-env pred/map-or-seq?
; TODO: fix this to require the merged spec of auth and config instead of any
[config any?]
(let [{:keys [postgres-db-user postgres-db-password fqdn]} config]
(->
(yaml/load-as-edn "gitea/appini-env-configmap.yaml")
@ -33,7 +45,8 @@
(cm/replace-all-matching-values-by-new-value "DBUSER" postgres-db-user)
(cm/replace-all-matching-values-by-new-value "DBPW" postgres-db-password))))
(defn generate-ingress [config]
(defn-spec generate-ingress pred/map-or-seq?
[config config?]
(let [{:keys [fqdn issuer]
:or {issuer "staging"}} config
letsencrypt-issuer (name issuer)]

View file

@ -2,9 +2,13 @@
(:require
#?(:clj [clojure.test :refer [deftest is are testing run-tests]]
:cljs [cljs.test :refer-macros [deftest is are testing run-tests]])
[clojure.spec.test.alpha :as st]
[dda.c4k-common.common-test :as ct]
[dda.c4k-gitea.gitea :as cut]))
(st/instrument `cut/generate-appini-env)
(st/instrument `cut/generate-ingress)
(deftest should-generate-appini-env
(is (= {:GITEA__database__USER-c1 nil,
:GITEA__database__USER-c2 "pg-user",
@ -18,5 +22,5 @@
(cut/generate-appini-env {:fqdn "test.com" :issuer "staging" :postgres-db-user "pg-user" :postgres-db-password "pg-pw"})))))
(deftest should-generate-ingress
(is (= {:hosts-c1 nil, :hosts-c2 "test.com", :host-c1 nil, :host-c2 "test.com"}
(ct/map-diff (cut/generate-ingress {}) (cut/generate-ingress {:fqdn "test.com" :issuer "staging"})))))
(is (= {:hosts-c1 "abc.de", :hosts-c2 "test.com", :host-c1 "abc.de", :host-c2 "test.com"}
(ct/map-diff (cut/generate-ingress {:fqdn "abc.de"}) (cut/generate-ingress {:fqdn "test.com" :issuer "staging"})))))