Use common load-as-edn

To avoid common code duplication
This commit is contained in:
bom 2023-02-02 13:29:10 +01:00
parent 74505dbab7
commit 107b8c3872
2 changed files with 9 additions and 9 deletions

View file

@ -23,14 +23,14 @@
(defn generate-config [my-conf] (defn generate-config [my-conf]
(let [{:keys [restic-repository]} my-conf] (let [{:keys [restic-repository]} my-conf]
(-> (->
(yaml/from-string (yaml/load-resource "backup/config.yaml")) (yaml/load-as-edn "backup/config.yaml")
(cm/replace-key-value :restic-repository restic-repository)))) (cm/replace-key-value :restic-repository restic-repository))))
(defn generate-cron [] (defn generate-cron []
(yaml/from-string (yaml/load-resource "backup/cron.yaml"))) (yaml/from-string (yaml/load-resource "backup/cron.yaml")))
(defn generate-backup-restore-deployment [my-conf] (defn generate-backup-restore-deployment [my-conf]
(let [backup-restore-yaml (yaml/from-string (yaml/load-resource "backup/backup-restore-deployment.yaml"))] (let [backup-restore-yaml (yaml/load-as-edn "backup/backup-restore-deployment.yaml")]
(if (and (contains? my-conf :local-integration-test) (= true (:local-integration-test my-conf))) (if (and (contains? my-conf :local-integration-test) (= true (:local-integration-test my-conf)))
(cm/replace-named-value backup-restore-yaml "CERTIFICATE_FILE" "/var/run/secrets/localstack-secrets/ca.crt") (cm/replace-named-value backup-restore-yaml "CERTIFICATE_FILE" "/var/run/secrets/localstack-secrets/ca.crt")
backup-restore-yaml))) backup-restore-yaml)))
@ -38,7 +38,7 @@
(defn generate-secret [my-auth] (defn generate-secret [my-auth]
(let [{:keys [aws-access-key-id aws-secret-access-key restic-password]} my-auth] (let [{:keys [aws-access-key-id aws-secret-access-key restic-password]} my-auth]
(-> (->
(yaml/from-string (yaml/load-resource "backup/secret.yaml")) (yaml/load-as-edn "backup/secret.yaml")
(cm/replace-key-value :aws-access-key-id (b64/encode aws-access-key-id)) (cm/replace-key-value :aws-access-key-id (b64/encode aws-access-key-id))
(cm/replace-key-value :aws-secret-access-key (b64/encode aws-secret-access-key)) (cm/replace-key-value :aws-secret-access-key (b64/encode aws-secret-access-key))
(cm/replace-key-value :restic-password (b64/encode restic-password))))) (cm/replace-key-value :restic-password (b64/encode restic-password)))))

View file

@ -36,14 +36,14 @@
(let [{:keys [fqdn issuer]} config (let [{:keys [fqdn issuer]} config
letsencrypt-issuer issuer] letsencrypt-issuer issuer]
(-> (->
(yaml/from-string (yaml/load-resource "nextcloud/certificate.yaml")) (yaml/load-as-edn "nextcloud/certificate.yaml")
(assoc-in [:spec :commonName] fqdn) (assoc-in [:spec :commonName] fqdn)
(assoc-in [:spec :dnsNames] [fqdn]) (assoc-in [:spec :dnsNames] [fqdn])
(assoc-in [:spec :issuerRef :name] letsencrypt-issuer)))) (assoc-in [:spec :issuerRef :name] letsencrypt-issuer))))
(defn generate-deployment [config] (defn generate-deployment [config]
(let [{:keys [fqdn]} config] (let [{:keys [fqdn]} config]
(-> (yaml/from-string (yaml/load-resource "nextcloud/deployment.yaml")) (-> (yaml/load-as-edn "nextcloud/deployment.yaml")
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn)))) (cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
(defn generate-ingress [config] (defn generate-ingress [config]
@ -51,7 +51,7 @@
:or {issuer "staging"}} config :or {issuer "staging"}} config
letsencrypt-issuer issuer] letsencrypt-issuer issuer]
(-> (->
(yaml/from-string (yaml/load-resource "nextcloud/ingress.yaml")) (yaml/load-as-edn "nextcloud/ingress.yaml")
(assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer)
(cm/replace-all-matching-values-by-new-value "fqdn" fqdn)))) (cm/replace-all-matching-values-by-new-value "fqdn" fqdn))))
@ -59,16 +59,16 @@
[config (s/keys :req-un [::pv-storage-size-gb ::pvc-storage-class-name])] [config (s/keys :req-un [::pv-storage-size-gb ::pvc-storage-class-name])]
(let [{:keys [pv-storage-size-gb pvc-storage-class-name]} config] (let [{:keys [pv-storage-size-gb pvc-storage-class-name]} config]
(-> (->
(yaml/from-string (yaml/load-resource "nextcloud/pvc.yaml")) (yaml/load-as-edn "nextcloud/pvc.yaml")
(assoc-in [:spec :resources :requests :storage] (str pv-storage-size-gb "Gi")) (assoc-in [:spec :resources :requests :storage] (str pv-storage-size-gb "Gi"))
(assoc-in [:spec :storageClassName] (name pvc-storage-class-name))))) (assoc-in [:spec :storageClassName] (name pvc-storage-class-name)))))
(defn generate-service [] (defn generate-service []
(yaml/from-string (yaml/load-resource "nextcloud/service.yaml"))) (yaml/load-as-edn "nextcloud/service.yaml"))
(defn generate-secret [config] (defn generate-secret [config]
(let [{:keys [nextcloud-admin-user nextcloud-admin-password]} config] (let [{:keys [nextcloud-admin-user nextcloud-admin-password]} config]
(-> (->
(yaml/from-string (yaml/load-resource "nextcloud/secret.yaml")) (yaml/load-as-edn "nextcloud/secret.yaml")
(cm/replace-key-value :nextcloud-admin-user (b64/encode nextcloud-admin-user)) (cm/replace-key-value :nextcloud-admin-user (b64/encode nextcloud-admin-user))
(cm/replace-key-value :nextcloud-admin-password (b64/encode nextcloud-admin-password))))) (cm/replace-key-value :nextcloud-admin-password (b64/encode nextcloud-admin-password)))))