From 2244778187ccf71b8029eeda3afc0b4af46767e5 Mon Sep 17 00:00:00 2001 From: Jan Krebs Date: Thu, 27 May 2021 12:35:32 +0200 Subject: [PATCH 1/2] Add some postwalk experiments --- src/main/cljc/dda/k8s_keycloak/core.cljc | 16 +++++++++++++++- src/test/cljc/dda/k8s_keycloak/core_test.cljc | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/cljc/dda/k8s_keycloak/core.cljc b/src/main/cljc/dda/k8s_keycloak/core.cljc index 6a44b38..9c93df6 100644 --- a/src/main/cljc/dda/k8s_keycloak/core.cljc +++ b/src/main/cljc/dda/k8s_keycloak/core.cljc @@ -4,7 +4,8 @@ [clojure.spec.alpha :as s] #?(:clj [orchestra.core :refer [defn-spec]] :cljs [orchestra.core :refer-macros [defn-spec]]) - [dda.k8s-keycloak.yaml :as yaml])) + [dda.k8s-keycloak.yaml :as yaml] + [clojure.walk])) (defn bash-env-string? [input] @@ -26,6 +27,19 @@ (def auth? (s/keys :req-un [::user-name ::user-password])) +(defn cast-lazy-seq-to-vec + [lazy-seq] + (clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %) + (do (println %) (into [] %)) + %) lazy-seq)) + +(defn replace-all-matching-values-by-new-value + [value-to-match value-to-replace coll] + (clojure.walk/postwalk #(if (and (= (type value-to-match) (type %)) + (= value-to-match %)) + value-to-replace + %) coll)) + (declare assoc-in-nested) (declare assoc-in-nested-seq) (declare assoc-in-nested-map) diff --git a/src/test/cljc/dda/k8s_keycloak/core_test.cljc b/src/test/cljc/dda/k8s_keycloak/core_test.cljc index 0e26041..2509cc8 100644 --- a/src/test/cljc/dda/k8s_keycloak/core_test.cljc +++ b/src/test/cljc/dda/k8s_keycloak/core_test.cljc @@ -95,7 +95,8 @@ :http {:paths [{:backend {:serviceName "another_keycloak" :servicePort 8081}}]}} ]))] - (is (= desired-result (cut/assoc-in-nested ingress-yaml [:spec :rules :host] fqdn)))) + (is (= desired-result + (cut/assoc-in-nested (cut/cast-lazy-seq-to-vec ingress-yaml) [:spec :rules :host] fqdn)))) ) From 0379ad882851993440561c5c09c9f813e4357ab1 Mon Sep 17 00:00:00 2001 From: Jan Krebs Date: Thu, 27 May 2021 12:36:44 +0200 Subject: [PATCH 2/2] Add TODO --- src/main/cljc/dda/k8s_keycloak/core.cljc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/cljc/dda/k8s_keycloak/core.cljc b/src/main/cljc/dda/k8s_keycloak/core.cljc index 9c93df6..270a16a 100644 --- a/src/main/cljc/dda/k8s_keycloak/core.cljc +++ b/src/main/cljc/dda/k8s_keycloak/core.cljc @@ -27,6 +27,8 @@ (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 %)