Luccas Code

This commit is contained in:
Jan Krebs 2021-05-27 11:17:16 +02:00
parent ff38e1ca2d
commit 558653d698
2 changed files with 36 additions and 14 deletions

View file

@ -26,16 +26,37 @@
(def auth? (s/keys :req-un [::user-name ::user-password])) (def auth? (s/keys :req-un [::user-name ::user-password]))
(declare assoc-in-nested)
(declare assoc-in-nested-seq)
(declare assoc-in-nested-map)
(defn replace-values-in-map (defn assoc-in-nested-seq [s path n]
[map keys value] (map #(if (sequential? %)
) (assoc-in-nested-seq % path n)
(assoc-in-nested-map % path n)) s))
(defn assoc-in-nested-map [m path n]
(into (empty m)
(let [p1 (first path)]
(for [[k v] m]
(if (= k p1)
[k (assoc-in-nested v (rest path) n)]
[k (assoc-in-nested v path n)])))))
(defn assoc-in-nested [data path n]
(if (empty? path)
n
(if (sequential? data)
(assoc-in-nested-seq data path n)
(if (map? data)
(assoc-in-nested-map data path n)
data))))
(defn generate-config [my-config my-auth] (defn generate-config [my-config my-auth]
(-> (->
(yaml/from-string (yaml/load-resource "config.yaml")) (yaml/from-string (yaml/load-resource "config.yaml"))
(assoc-in [:data :config.edn] (str my-config)) (assoc-in [:data :config.edn] (str my-config))
(assoc-in [ :data :credentials.edn] (str my-auth)))) (assoc-in [:data :credentials.edn] (str my-auth))))
(defn generate-deployment [my-auth] (defn generate-deployment [my-auth]
(let [{:keys [user-name user-password]} my-auth] (let [{:keys [user-name user-password]} my-auth]
@ -55,11 +76,11 @@
(let [{:keys [fqdn issuer] (let [{:keys [fqdn issuer]
:or {issuer :staging}} config :or {issuer :staging}} config
letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")] letsencrypt-issuer (str "letsencrypt-" (name issuer) "-issuer")]
(-> (->
(yaml/from-string (yaml/load-resource "certificate.yaml")) (yaml/from-string (yaml/load-resource "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-ingress [config] (defn generate-ingress [config]
(let [{:keys [fqdn issuer] (let [{:keys [fqdn issuer]

View file

@ -93,8 +93,9 @@
:servicePort 8080}}]}} :servicePort 8080}}]}}
{:host fqdn {:host fqdn
:http {:paths [{:backend {:serviceName "another_keycloak" :http {:paths [{:backend {:serviceName "another_keycloak"
:servicePort 8081}}]}}]))] :servicePort 8081}}]}}
(is (= desired-result (cut/replace-values-in-map ingress-yaml [:spec :rules :host] fqdn)))) ]))]
(is (= desired-result (cut/assoc-in-nested ingress-yaml [:spec :rules :host] fqdn))))
) )