From 775689b348218d5b3379ddf6739538d4851e1a9e Mon Sep 17 00:00:00 2001 From: Clemens Geibel Date: Wed, 13 Apr 2022 13:56:49 +0200 Subject: [PATCH 1/5] Added yaml config reader --- project.clj | 2 +- src/main/clj/dda/c4k_nextcloud/uberjar.clj | 17 ++++++++++------- valid-auth.yaml | 7 +++++++ valid-config.yaml | 5 +++++ 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 valid-auth.yaml create mode 100644 valid-config.yaml diff --git a/project.clj b/project.clj index 3586d30..f03099a 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.10.3"] [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "1.1.0"]] + [org.domaindrivenarchitecture/c4k-common-clj "1.1.1-SNAPSHOT"]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] diff --git a/src/main/clj/dda/c4k_nextcloud/uberjar.clj b/src/main/clj/dda/c4k_nextcloud/uberjar.clj index 16e6a3b..97b9321 100644 --- a/src/main/clj/dda/c4k_nextcloud/uberjar.clj +++ b/src/main/clj/dda/c4k_nextcloud/uberjar.clj @@ -5,6 +5,7 @@ [clojure.string :as cs] [clojure.tools.reader.edn :as edn] [expound.alpha :as expound] + [dda.c4k-common.yaml :as yaml] [dda.c4k-nextcloud.core :as core] [dda.c4k-nextcloud.nextcloud :as nextcloud])) @@ -42,16 +43,18 @@ :default (let [config-str (slurp config) auth-str (slurp auth) - config-edn (edn/read-string config-str) - auth-edn (edn/read-string auth-str) - config-valid? (s/valid? nextcloud/config? config-edn) - auth-valid? (s/valid? core/auth? auth-edn)] + config-parse-fn (if (yaml/is-yaml? config) yaml/from-string edn/read-string) + auth-parse-fn (if (yaml/is-yaml? auth) yaml/from-string edn/read-string) + parsed-config (config-parse-fn config-str) + parsed-auth (auth-parse-fn auth-str) + config-valid? (s/valid? nextcloud/config? parsed-config) + auth-valid? (s/valid? core/auth? parsed-auth)] (if (and config-valid? auth-valid?) - (println (core/generate config-edn auth-edn)) + (println (core/generate parsed-config parsed-auth)) (do (when (not config-valid?) (println - (expound/expound-str nextcloud/config? config-edn {:print-specs? false}))) + (expound/expound-str nextcloud/config? parsed-config {:print-specs? false}))) (when (not auth-valid?) (println - (expound/expound-str core/auth? auth-edn {:print-specs? false}))))))))))) + (expound/expound-str core/auth? parsed-auth {:print-specs? false}))))))))))) diff --git a/valid-auth.yaml b/valid-auth.yaml new file mode 100644 index 0000000..247409a --- /dev/null +++ b/valid-auth.yaml @@ -0,0 +1,7 @@ +postgres-db-user: "nextcloud" +postgres-db-password: "nextcloud-db-password" +nextcloud-admin-user: "cloudadmin" +nextcloud-admin-password: "cloudpassword" +aws-access-key-id: "aws-id" +aws-secret-access-key: "aws-secret" +restic-password: "restic-password" \ No newline at end of file diff --git a/valid-config.yaml b/valid-config.yaml new file mode 100644 index 0000000..dff692c --- /dev/null +++ b/valid-config.yaml @@ -0,0 +1,5 @@ +fqdn: "cloud.test.meissa-gmbh.de" +issuer: :staging +nextcloud-data-volume-path: "/var/cloud" +postgres-data-volume-path: "/var/postgres" +restic-repository: "s3:s3.amazonaws.com/your-bucket/your-folder" \ No newline at end of file From 5b4e68ae2a738b83dd3f185606087d036e36be5a Mon Sep 17 00:00:00 2001 From: Clemens Geibel Date: Wed, 20 Apr 2022 16:51:57 +0200 Subject: [PATCH 2/5] Changed issuer keywords to strings --- src/main/cljc/dda/c4k_nextcloud/core.cljc | 2 +- src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc | 10 ++++++++-- src/test/cljc/dda/c4k_nextcloud/core_test.cljc | 10 +++++----- src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc | 2 +- valid-config.edn | 2 +- valid-config.yaml | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/cljc/dda/c4k_nextcloud/core.cljc b/src/main/cljc/dda/c4k_nextcloud/core.cljc index 20b57e2..928c879 100644 --- a/src/main/cljc/dda/c4k_nextcloud/core.cljc +++ b/src/main/cljc/dda/c4k_nextcloud/core.cljc @@ -9,7 +9,7 @@ [dda.c4k-nextcloud.nextcloud :as nextcloud] [dda.c4k-nextcloud.backup :as backup])) -(def config-defaults {:issuer :staging}) +(def config-defaults {:issuer "staging"}) (def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password ::nextcloud/nextcloud-admin-user ::nextcloud/nextcloud-admin-password diff --git a/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc b/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc index ac3db50..df5c85f 100644 --- a/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc +++ b/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc @@ -10,8 +10,14 @@ [dda.c4k-common.common :as cm] [dda.c4k-common.postgres :as postgres])) +; TODO: Replace method in c4k-common.predicate and update all c4k modules. +(defn letsencrypt-issuer? + [input] + (contains? #{"prod" "staging"} input)) +; TODO: Remove (name ...) function calls, when issuer is no longer a keyword (also in c4k-common) + (s/def ::fqdn cp/fqdn-string?) -(s/def ::issuer cp/letsencrypt-issuer?) +(s/def ::issuer letsencrypt-issuer?) ;cp/letsencrypt-issuer? (s/def ::restic-repository string?) (s/def ::nextcloud-data-volume-path string?) (s/def ::nextcloud-admin-user cp/bash-env-string?) @@ -52,7 +58,7 @@ (defn generate-ingress [config] (let [{:keys [fqdn issuer] - :or {issuer :staging}} config + :or {issuer "staging"}} config letsencrypt-issuer (name issuer)] (-> (yaml/from-string (yaml/load-resource "nextcloud/ingress.yaml")) diff --git a/src/test/cljc/dda/c4k_nextcloud/core_test.cljc b/src/test/cljc/dda/c4k_nextcloud/core_test.cljc index f46cfe6..82cfcf5 100644 --- a/src/test/cljc/dda/c4k_nextcloud/core_test.cljc +++ b/src/test/cljc/dda/c4k_nextcloud/core_test.cljc @@ -13,7 +13,7 @@ :postgres-db-password "nextcloud-db-password" :nextcloud-admin-user "cloudadmin" :nextcloud-admin-password "cloudpassword" - :issuer :prod + :issuer "prod" :nextcloud-data-volume-path "/var/nextcloud" :postgres-data-volume-path "/var/postgres" :aws-access-key-id "aws-id" @@ -26,7 +26,7 @@ :postgres-db-password "nextcloud-db-password" :nextcloud-admin-user "cloudadmin" :nextcloud-admin-password "cloudpassword" - :issuer :prod + :issuer "prod" :aws-access-key-id "aws-id" :aws-secret-access-key "aws-secret" :restic-password "restic-pw" @@ -37,7 +37,7 @@ :postgres-db-password "nextcloud-db-password" :nextcloud-admin-user "cloudadmin" :nextcloud-admin-password "cloudpassword" - :issuer :prod + :issuer "prod" :aws-access-key-id "aws-id" :aws-secret-access-key "aws-secret" :restic-password "restic-pw"})))) @@ -47,7 +47,7 @@ :postgres-db-password "nextcloud-db-password" :nextcloud-admin-user "cloudadmin" :nextcloud-admin-password "cloudpassword" - :issuer :prod + :issuer "prod" :aws-access-key-id "aws-id" :aws-secret-access-key "aws-secret" :restic-password "restic-pw"}) @@ -59,7 +59,7 @@ :postgres-db-password "nextcloud-db-password" :nextcloud-admin-user "cloudadmin" :nextcloud-admin-password "cloudpassword" - :issuer :prod + :issuer "prod" :aws-access-key-id "aws-id" :aws-secret-access-key "aws-secret" :restic-password "restic-pw"}) diff --git a/src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc b/src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc index 024a0c6..3a2b6b6 100644 --- a/src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc +++ b/src/test/cljc/dda/c4k_nextcloud/nextcloud_test.cljc @@ -25,7 +25,7 @@ :dnsNames ["xx"] :issuerRef {:name "prod", :kind "ClusterIssuer"}}} - (cut/generate-certificate {:fqdn "xx" :issuer :prod})))) + (cut/generate-certificate {:fqdn "xx" :issuer "prod"})))) (deftest should-generate-ingress (is (= {:apiVersion "networking.k8s.io/v1" diff --git a/valid-config.edn b/valid-config.edn index 87ebb80..b50ced9 100644 --- a/valid-config.edn +++ b/valid-config.edn @@ -1,5 +1,5 @@ {:fqdn "cloud.test.meissa-gmbh.de" - :issuer :staging + :issuer "staging" :nextcloud-data-volume-path "/var/cloud" :postgres-data-volume-path "/var/postgres" :restic-repository "s3:s3.amazonaws.com/your-bucket/your-folder"} \ No newline at end of file diff --git a/valid-config.yaml b/valid-config.yaml index dff692c..c716cf2 100644 --- a/valid-config.yaml +++ b/valid-config.yaml @@ -1,5 +1,5 @@ fqdn: "cloud.test.meissa-gmbh.de" -issuer: :staging +issuer: "staging" nextcloud-data-volume-path: "/var/cloud" postgres-data-volume-path: "/var/postgres" restic-repository: "s3:s3.amazonaws.com/your-bucket/your-folder" \ No newline at end of file From 9f941167772832806018c1739b5c6777cc37e5f8 Mon Sep 17 00:00:00 2001 From: Clemens Geibel Date: Wed, 11 May 2022 14:20:43 +0200 Subject: [PATCH 3/5] Moved letsencrypt-issuer? back to c4k-common --- project.clj | 2 +- src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/project.clj b/project.clj index f03099a..2eee50e 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.10.3"] [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "1.1.1-SNAPSHOT"]] + [org.domaindrivenarchitecture/c4k-common-clj "2.0.0-SNAPSHOT"]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] diff --git a/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc b/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc index df5c85f..651ef23 100644 --- a/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc +++ b/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc @@ -10,14 +10,8 @@ [dda.c4k-common.common :as cm] [dda.c4k-common.postgres :as postgres])) -; TODO: Replace method in c4k-common.predicate and update all c4k modules. -(defn letsencrypt-issuer? - [input] - (contains? #{"prod" "staging"} input)) -; TODO: Remove (name ...) function calls, when issuer is no longer a keyword (also in c4k-common) - (s/def ::fqdn cp/fqdn-string?) -(s/def ::issuer letsencrypt-issuer?) ;cp/letsencrypt-issuer? +(s/def ::issuer cp/letsencrypt-issuer?) (s/def ::restic-repository string?) (s/def ::nextcloud-data-volume-path string?) (s/def ::nextcloud-admin-user cp/bash-env-string?) @@ -44,7 +38,7 @@ (defn generate-certificate [config] (let [{:keys [fqdn issuer]} config - letsencrypt-issuer (name issuer)] + letsencrypt-issuer issuer] (-> (yaml/from-string (yaml/load-resource "nextcloud/certificate.yaml")) (assoc-in [:spec :commonName] fqdn) @@ -59,7 +53,7 @@ (defn generate-ingress [config] (let [{:keys [fqdn issuer] :or {issuer "staging"}} config - letsencrypt-issuer (name issuer)] + letsencrypt-issuer issuer] (-> (yaml/from-string (yaml/load-resource "nextcloud/ingress.yaml")) (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) From 2dbc40fb0c72a5ed20b96514e9ba8c4ea7ff62dc Mon Sep 17 00:00:00 2001 From: Clemens Geibel Date: Wed, 11 May 2022 14:28:32 +0200 Subject: [PATCH 4/5] Use c4k-common-clj v2.0.0 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 2eee50e..e8c4619 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.10.3"] [org.clojure/tools.reader "1.3.6"] - [org.domaindrivenarchitecture/c4k-common-clj "2.0.0-SNAPSHOT"]] + [org.domaindrivenarchitecture/c4k-common-clj "2.0.0"]] :target-path "target/%s/" :source-paths ["src/main/cljc" "src/main/clj"] From ed609470876f3be26f610f3c3cd8596e7bf992a3 Mon Sep 17 00:00:00 2001 From: Clemens Geibel Date: Wed, 11 May 2022 14:39:28 +0200 Subject: [PATCH 5/5] New major version in development --- package.json | 2 +- project.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 243ace4..2c294e4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "c4k-nextcloud", "description": "Generate c4k yaml for a nextcloud deployment.", "author": "meissa GmbH", - "version": "3.4.2-SNAPSHOT", + "version": "4.0.0-SNAPSHOT", "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-nextcloud#readme", "repository": "https://www.npmjs.com/package/c4k-nextcloud", "license": "APACHE2", diff --git a/project.clj b/project.clj index e8c4619..7e0c5f8 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.domaindrivenarchitecture/c4k-nextcloud "3.4.2-SNAPSHOT" +(defproject org.domaindrivenarchitecture/c4k-nextcloud "4.0.0-SNAPSHOT" :description "nextcloud c4k-installation package" :url "https://domaindrivenarchitecture.org" :license {:name "Apache License, Version 2.0"