From e4b0e26fd5e4b196bef76c2f9e8310cd6f790992 Mon Sep 17 00:00:00 2001 From: Jan Krebs Date: Thu, 27 May 2021 15:02:05 +0200 Subject: [PATCH] Move cast funcktion to yaml namespace --- src/main/clj/dda/k8s_keycloak/yaml.clj | 11 +++++-- src/main/cljc/dda/k8s_keycloak/core.cljc | 41 +----------------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/src/main/clj/dda/k8s_keycloak/yaml.clj b/src/main/clj/dda/k8s_keycloak/yaml.clj index 06c1bc7..15a879e 100644 --- a/src/main/clj/dda/k8s_keycloak/yaml.clj +++ b/src/main/clj/dda/k8s_keycloak/yaml.clj @@ -1,13 +1,20 @@ (ns dda.k8s-keycloak.yaml (:require [clojure.java.io :as io] - [clj-yaml.core :as yaml])) + [clj-yaml.core :as yaml] + [clojure.walk])) + +(defn cast-lazy-seq-to-vec + [lazy-seq] + (clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %) + (into [] %) + %) lazy-seq)) (defn load-resource [resource-name] (slurp (io/resource resource-name))) (defn from-string [input] - (yaml/parse-string input)) + (cast-lazy-seq-to-vec (yaml/parse-string input))) (defn to-string [edn] (yaml/generate-string edn :dumper-options {:flow-style :block})) \ No newline at end of file diff --git a/src/main/cljc/dda/k8s_keycloak/core.cljc b/src/main/cljc/dda/k8s_keycloak/core.cljc index 6051fb4..9824c70 100644 --- a/src/main/cljc/dda/k8s_keycloak/core.cljc +++ b/src/main/cljc/dda/k8s_keycloak/core.cljc @@ -27,14 +27,6 @@ (def auth? (s/keys :req-un [::user-name ::user-password])) -; This needs to be checked: -; Are LazySeq only lists on our case? -(defn cast-lazy-seq-to-vec - [lazy-seq] - (clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %) - (do (into [] %)) - %) lazy-seq)) - (defn replace-all-matching-values-by-new-value [coll value-to-match value-to-replace] (clojure.walk/postwalk #(if (and (= (type value-to-match) (type %)) @@ -42,32 +34,6 @@ value-to-replace %) coll)) -(declare assoc-in-nested) -(declare assoc-in-nested-seq) -(declare assoc-in-nested-map) - -(defn assoc-in-nested-seq [s path n] - (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] (-> (yaml/from-string (yaml/load-resource "config.yaml")) @@ -78,7 +44,6 @@ (let [{:keys [user-name user-password]} my-auth] (-> (yaml/from-string (yaml/load-resource "deployment.yaml")) - (cast-lazy-seq-to-vec) (assoc-in [:spec :template :spec :containers 0 :env 0 :value] user-name) (assoc-in [:spec :template :spec :containers 0 :env 1 :value] user-password)))) @@ -101,8 +66,6 @@ (assoc-in [:metadata :annotations :cert-manager.io/cluster-issuer] letsencrypt-issuer) (replace-all-matching-values-by-new-value "fqdn" fqdn)))) - - (defn generate-service [] (yaml/from-string (yaml/load-resource "service.yaml"))) @@ -118,6 +81,4 @@ "---" (yaml/to-string (generate-service)) "---" - (yaml/to-string (generate-deployment my-auth))])) - - + (yaml/to-string (generate-deployment my-auth))])) \ No newline at end of file