diff --git a/src/main/clj/dda/c4k_gitea/uberjar.clj b/src/main/clj/dda/c4k_gitea/uberjar.clj index 84aa75e..f23b20a 100644 --- a/src/main/clj/dda/c4k_gitea/uberjar.clj +++ b/src/main/clj/dda/c4k_gitea/uberjar.clj @@ -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)) diff --git a/src/main/cljc/dda/c4k_gitea/core.cljc b/src/main/cljc/dda/c4k_gitea/core.cljc index b87a663..568e1f5 100644 --- a/src/main/cljc/dda/c4k_gitea/core.cljc +++ b/src/main/cljc/dda/c4k_gitea/core.cljc @@ -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 diff --git a/src/main/cljc/dda/c4k_gitea/gitea.cljc b/src/main/cljc/dda/c4k_gitea/gitea.cljc index c1b0b07..6cbaf70 100644 --- a/src/main/cljc/dda/c4k_gitea/gitea.cljc +++ b/src/main/cljc/dda/c4k_gitea/gitea.cljc @@ -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)] diff --git a/src/test/cljc/dda/c4k_gitea/gitea_test.cljc b/src/test/cljc/dda/c4k_gitea/gitea_test.cljc index d3b5897..3fe95fb 100644 --- a/src/test/cljc/dda/c4k_gitea/gitea_test.cljc +++ b/src/test/cljc/dda/c4k_gitea/gitea_test.cljc @@ -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"})))))