From 88a077e776bb7fb82f39f4c7d8de91d3adfba8c4 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 2 Feb 2023 13:40:56 +0100 Subject: [PATCH] Use standardized uberjar --- src/main/clj/dda/c4k_nextcloud/uberjar.clj | 60 ++++--------------- src/main/cljc/dda/c4k_nextcloud/core.cljc | 30 +++------- .../cljc/dda/c4k_nextcloud/nextcloud.cljc | 12 ++++ 3 files changed, 30 insertions(+), 72 deletions(-) diff --git a/src/main/clj/dda/c4k_nextcloud/uberjar.clj b/src/main/clj/dda/c4k_nextcloud/uberjar.clj index 865b92c..73c4c40 100644 --- a/src/main/clj/dda/c4k_nextcloud/uberjar.clj +++ b/src/main/clj/dda/c4k_nextcloud/uberjar.clj @@ -1,55 +1,15 @@ (ns dda.c4k-nextcloud.uberjar (:gen-class) (:require - [clojure.spec.alpha :as s] - [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])) - -(def usage - "usage: - - c4k-nextcloud {your configuraton file} {your authorization file}") - -(s/def ::options (s/* #{"-h"})) -(s/def ::filename (s/and string? - #(not (cs/starts-with? % "-")))) -(s/def ::cmd-args (s/cat :options ::options - :args (s/? - (s/cat :config ::filename - :auth ::filename)))) -(defn invalid-args-msg - [spec args] - (s/explain spec args) - (println (str "Bad commandline arguments\n" usage))) + [dda.c4k-common.uberjar :as uberjar] + [dda.c4k-nextcloud.jitsi :as jitsi] + [dda.c4k-nextcloud.core :as core])) (defn -main [& cmd-args] - (let [parsed-args-cmd (s/conform ::cmd-args cmd-args)] - (if (= ::s/invalid parsed-args-cmd) - (invalid-args-msg ::cmd-args cmd-args) - (let [{:keys [options args]} parsed-args-cmd - {:keys [config auth]} args] - (cond - (some #(= "-h" %) options) - (println usage) - :default - (let [config-str (slurp config) - auth-str (slurp auth) - 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? ::core/config parsed-config) - auth-valid? (s/valid? ::core/auth parsed-auth)] - (if (and config-valid? auth-valid?) - (println (core/generate parsed-config parsed-auth)) - (do - (when (not config-valid?) - (println - (expound/expound-str ::core/config parsed-config {:print-specs? false}))) - (when (not auth-valid?) - (println - (expound/expound-str ::core/auth parsed-auth {:print-specs? false}))))))))))) + (uberjar/main-common + "c4k-nextcloud" + jitsi/config? + jitsi/auth? + core/config-defaults + core/generate + cmd-args)) diff --git a/src/main/cljc/dda/c4k_nextcloud/core.cljc b/src/main/cljc/dda/c4k_nextcloud/core.cljc index 8cd5205..a04bd42 100644 --- a/src/main/cljc/dda/c4k_nextcloud/core.cljc +++ b/src/main/cljc/dda/c4k_nextcloud/core.cljc @@ -1,9 +1,9 @@ (ns dda.c4k-nextcloud.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-nextcloud.nextcloud :as nextcloud] @@ -13,22 +13,8 @@ (def config-defaults {:issuer "staging"}) -(def config? (s/keys :req-un [::nextcloud/fqdn] - :opt-un [::nextcloud/issuer - ::nextcloud/restic-repository - ::nextcloud/pv-storage-size-gb - ::nextcloud/pvc-storage-class-name])) - -(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password - ::nextcloud/nextcloud-admin-user ::nextcloud/nextcloud-admin-password - ::aws-access-key-id ::aws-secret-access-key - ::restic-password])) - -(s/def ::config config?) -(s/def ::auth auth?) - (defn-spec k8s-objects any? - [config (s/merge config? auth?)] + [config (s/merge nextcloud/config? nextcloud/auth?)] (let [nextcloud-default-storage-config {:pvc-storage-class-name default-storage-class :pv-storage-size-gb 200}] (into @@ -52,9 +38,9 @@ (yaml/to-string (backup/generate-backup-restore-deployment config))]))))) (defn-spec generate any? - [my-config config? - my-auth auth?] - (let [resulting-config (merge config-defaults my-config my-auth)] - (cs/join - "\n---\n" - (k8s-objects resulting-config)))) + [my-config nextcloud/config? + my-auth nextcloud/auth?] + (cm/concat-vec + (map yaml/to-string + (filter #(not (nil? %)) + (merge config-defaults my-config my-auth))))) diff --git a/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc b/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc index 95b73d0..9566430 100644 --- a/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc +++ b/src/main/cljc/dda/c4k_nextcloud/nextcloud.cljc @@ -7,6 +7,7 @@ [dda.c4k-common.yaml :as yaml] [dda.c4k-common.base64 :as b64] [dda.c4k-common.predicate :as cp] + [dda.c4k-common.postgres :as postgres] [dda.c4k-common.common :as cm])) (s/def ::fqdn cp/fqdn-string?) @@ -21,6 +22,17 @@ ::pvc-storage-class-name] :opt-un [::restic-repository])) +(def config? (s/keys :req-un [::fqdn] + :opt-un [::issuer + ::restic-repository + ::pv-storage-size-gb + ::pvc-storage-class-name])) + +(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password + ::nextcloud-admin-user ::nextcloud-admin-password + ::aws-access-key-id ::aws-secret-access-key + ::restic-password])) + #?(:cljs (defmethod yaml/load-resource :nextcloud [resource-name] (case resource-name