From 775689b348218d5b3379ddf6739538d4851e1a9e Mon Sep 17 00:00:00 2001 From: Clemens Geibel Date: Wed, 13 Apr 2022 13:56:49 +0200 Subject: [PATCH] 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