Merge branch 'yaml-config-reader' into 'master'

Configuration files can now be of type EDN and YAML.

See merge request domaindrivenarchitecture/c4k-nextcloud!4
merge-requests/5/merge
Clemens Geibel 2 years ago
commit 0d3a4c334a

@ -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",

@ -1,11 +1,11 @@
(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"
: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 "2.0.0"]]
:target-path "target/%s/"
:source-paths ["src/main/cljc"
"src/main/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})))))))))))

@ -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

@ -38,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)
@ -52,8 +52,8 @@
(defn generate-ingress [config]
(let [{:keys [fqdn issuer]
:or {issuer :staging}} config
letsencrypt-issuer (name issuer)]
:or {issuer "staging"}} config
letsencrypt-issuer issuer]
(->
(yaml/from-string (yaml/load-resource "nextcloud/ingress.yaml"))
(assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer)

@ -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"})

@ -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"

@ -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"

@ -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"}

@ -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"
Loading…
Cancel
Save