From 40030c3ce2d771641feec3b4f0dd339dc61b7fd3 Mon Sep 17 00:00:00 2001 From: Clemens Date: Thu, 18 Jul 2024 10:25:44 +0200 Subject: [PATCH 1/5] fix: split config and auth --- project.clj | 4 +- shadow-cljs.edn | 2 +- src/main/cljc/dda/c4k_shynet/core.cljc | 39 +++++++++++-------- src/main/cljc/dda/c4k_shynet/shynet.cljc | 5 ++- src/test/cljc/dda/c4k_shynet/shynet_test.cljc | 3 +- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/project.clj b/project.clj index 3a64af9..e4d1a7a 100644 --- a/project.clj +++ b/project.clj @@ -3,9 +3,9 @@ :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0" :url "https://www.apache.org/licenses/LICENSE-2.0.html"} - :dependencies [[org.clojure/clojure "1.11.1"] + :dependencies [[org.clojure/clojure "1.11.3"] [org.clojure/tools.reader "1.4.2"] - [org.domaindrivenarchitecture/c4k-common-clj "6.4.0"] + [org.domaindrivenarchitecture/c4k-common-clj "6.4.2-SNAPSHOT"] ; TODO: Release c4k-common version with refactorings and update here [hickory "0.7.1" :exclusions [viebel/codox-klipse-theme]]] :target-path "target/%s/" :source-paths ["src/main/cljc" diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 9d2b369..58fcb61 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -4,7 +4,7 @@ "src/test/cljc" "src/test/cljs" "src/test/resources"] - :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.4.0"] + :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.4.0"] ; TODO: Release c4k-common version with refactorings and update here [hickory "0.7.1"]] :builds {:frontend {:target :browser :modules {:main {:init-fn dda.c4k-shynet.browser/init}} diff --git a/src/main/cljc/dda/c4k_shynet/core.cljc b/src/main/cljc/dda/c4k_shynet/core.cljc index 100fd33..124b06c 100644 --- a/src/main/cljc/dda/c4k_shynet/core.cljc +++ b/src/main/cljc/dda/c4k_shynet/core.cljc @@ -1,14 +1,14 @@ (ns dda.c4k-shynet.core - (:require - [clojure.string :as cs] - [clojure.spec.alpha :as s] - #?(:clj [orchestra.core :refer [defn-spec]] - :cljs [orchestra.core :refer-macros [defn-spec]]) - [dda.c4k-common.common :as cm] - [dda.c4k-common.yaml :as yaml] - [dda.c4k-common.postgres :as postgres] - [dda.c4k-common.monitoring :as mon] - [dda.c4k-shynet.shynet :as shynet])) + (:require + [clojure.string :as cs] + [clojure.spec.alpha :as s] + #?(:clj [orchestra.core :refer [defn-spec]] + :cljs [orchestra.core :refer-macros [defn-spec]]) + [dda.c4k-common.common :as cm] + [dda.c4k-common.yaml :as yaml] + [dda.c4k-common.postgres :as postgres] + [dda.c4k-common.monitoring :as mon] + [dda.c4k-shynet.shynet :as shynet])) (def config-defaults {:issuer :staging}) @@ -21,8 +21,8 @@ ::mon-cfg])) (def auth? (s/keys :req-un [::shynet/django-secret-key - ::postgres/postgres-db-user ::postgres/postgres-db-password - ::mon-auth])) + ::postgres/postgres-db-user ::postgres/postgres-db-password] + :opt-un [::mon-auth])) (defn config-objects [config] (let [storage-class (if (contains? config :postgres-data-volume-path) :manual :local-path)] @@ -44,10 +44,15 @@ (shynet/generate-service-webserver) (shynet/generate-statefulset)] (shynet/generate-ingress-and-cert config) - (when (:contains? config :mon-cfg) - (mon/generate (:mon-cfg config) (:mon-auth config)))))))) + (when (contains? config :mon-cfg) + (mon/generate-config))))))) -(defn auth-objects [config] +(defn auth-objects [config auth] (map yaml/to-string - [(postgres/generate-secret config) - (shynet/generate-secret config)])) \ No newline at end of file + (filter + #(not (nil? %)) + (cm/concat-vec + [(postgres/generate-secret config auth) + (shynet/generate-secret config auth)] + (when (contains? config :mon-cfg) + (mon/generate-auth (:mon-cfg config) (:mon-auth auth))))))) \ No newline at end of file diff --git a/src/main/cljc/dda/c4k_shynet/shynet.cljc b/src/main/cljc/dda/c4k_shynet/shynet.cljc index e0aa74f..e5edb21 100644 --- a/src/main/cljc/dda/c4k_shynet/shynet.cljc +++ b/src/main/cljc/dda/c4k_shynet/shynet.cljc @@ -15,8 +15,9 @@ (defmethod yaml/load-resource :shynet [resource-name] (get (inline-resources "shynet") resource-name))) -(defn generate-secret [config] - (let [{:keys [fqdn django-secret-key postgres-db-user postgres-db-password]} config] +(defn generate-secret [config auth] + (let [{:keys [fqdn]} config + {:keys [django-secret-key postgres-db-user postgres-db-password]} auth] (-> (yaml/load-as-edn "shynet/secret.yaml") ; TODO: See comment in secret.yaml diff --git a/src/test/cljc/dda/c4k_shynet/shynet_test.cljc b/src/test/cljc/dda/c4k_shynet/shynet_test.cljc index f4c38ea..665b289 100644 --- a/src/test/cljc/dda/c4k_shynet/shynet_test.cljc +++ b/src/test/cljc/dda/c4k_shynet/shynet_test.cljc @@ -100,5 +100,6 @@ :EMAIL_HOST_PASSWORD "" :EMAIL_HOST "" :SERVER_EMAIL "Shynet "}} - (cut/generate-secret {:fqdn "test.com" :django-secret-key "django-pw" + (cut/generate-secret {:fqdn "test.com"} + {:django-secret-key "django-pw" :postgres-db-user "postgres-user" :postgres-db-password "postgres-pw"})))) \ No newline at end of file From 73c19303db80a42489c7fd897eb75fde839574e4 Mon Sep 17 00:00:00 2001 From: Clemens Date: Thu, 18 Jul 2024 10:46:05 +0200 Subject: [PATCH 2/5] adjust build.py --- build.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.py b/build.py index 8a68495..9a6d885 100644 --- a/build.py +++ b/build.py @@ -12,13 +12,14 @@ PROJECT_ROOT_PATH = "." @init def initialize(project): + project.build_depends_on("ddadevops>=4.7.0") + input = { "name": name, "module": MODULE, "stage": "notused", "project_root_path": PROJECT_ROOT_PATH, "build_types": [], - "release_artifacts": ["target/uberjar/c4k-shynet-standalone.jar"], "mixin_types": ["RELEASE"], "release_primary_build_file": "project.clj", "release_secondary_build_files": [ @@ -61,8 +62,8 @@ def test_schema(project): run( "java -jar target/uberjar/c4k-shynet-standalone.jar " + "src/test/resources/shynet-test/valid-config.yaml " - + "src/test/resources/shynet-test/valid-auth.yaml | " - + "kubeconform --kubernetes-version 1.23.0 --strict --skip Certificate -", + + "src/test/resources/shynet-test/valid-auth.yaml ",#| " + #+ """kubeconform --kubernetes-version 1.23.0 --strict --skip "Certificate,Middleware" -""", shell=True, check=True, ) From 091caf193dcc2d54a8e721ad355e3ffe7cd979e6 Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 19 Jul 2024 10:59:43 +0200 Subject: [PATCH 3/5] adjust postgres function call --- src/main/cljc/dda/c4k_shynet/core.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/cljc/dda/c4k_shynet/core.cljc b/src/main/cljc/dda/c4k_shynet/core.cljc index 124b06c..95e6e11 100644 --- a/src/main/cljc/dda/c4k_shynet/core.cljc +++ b/src/main/cljc/dda/c4k_shynet/core.cljc @@ -30,7 +30,7 @@ (filter #(not (nil? %)) (cm/concat-vec - [(postgres/generate-config {:postgres-size :2gb :db-name "shynet"}) + [(postgres/generate-configmap {:postgres-size :2gb :db-name "shynet"}) (when (contains? config :postgres-data-volume-path) (postgres/generate-persistent-volume (select-keys config [:postgres-data-volume-path :pv-storage-size-gb]))) (postgres/generate-pvc {:pv-storage-size-gb 20 From 28cb4efa64c662d393a0936b30112afc9497e64d Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 19 Jul 2024 11:16:47 +0200 Subject: [PATCH 4/5] updated c4k-common dependency --- project.clj | 2 +- shadow-cljs.edn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index e4d1a7a..58c35b7 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,7 @@ :url "https://www.apache.org/licenses/LICENSE-2.0.html"} :dependencies [[org.clojure/clojure "1.11.3"] [org.clojure/tools.reader "1.4.2"] - [org.domaindrivenarchitecture/c4k-common-clj "6.4.2-SNAPSHOT"] ; TODO: Release c4k-common version with refactorings and update here + [org.domaindrivenarchitecture/c4k-common-clj "7.0.0"] [hickory "0.7.1" :exclusions [viebel/codox-klipse-theme]]] :target-path "target/%s/" :source-paths ["src/main/cljc" diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 58fcb61..cbf4db4 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -4,7 +4,7 @@ "src/test/cljc" "src/test/cljs" "src/test/resources"] - :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "6.4.0"] ; TODO: Release c4k-common version with refactorings and update here + :dependencies [[org.domaindrivenarchitecture/c4k-common-cljs "7.0.0"] [hickory "0.7.1"]] :builds {:frontend {:target :browser :modules {:main {:init-fn dda.c4k-shynet.browser/init}} From f21315d4c74af60721137298124e0e3f62fe16aa Mon Sep 17 00:00:00 2001 From: Clemens Date: Fri, 19 Jul 2024 11:17:38 +0200 Subject: [PATCH 5/5] revert commenting out --- build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.py b/build.py index 9a6d885..c244f73 100644 --- a/build.py +++ b/build.py @@ -62,8 +62,8 @@ def test_schema(project): run( "java -jar target/uberjar/c4k-shynet-standalone.jar " + "src/test/resources/shynet-test/valid-config.yaml " - + "src/test/resources/shynet-test/valid-auth.yaml ",#| " - #+ """kubeconform --kubernetes-version 1.23.0 --strict --skip "Certificate,Middleware" -""", + + "src/test/resources/shynet-test/valid-auth.yaml | " + + """kubeconform --kubernetes-version 1.23.0 --strict --skip "Certificate,Middleware" -""", shell=True, check=True, )