merge-requests/1/merge
bom 3 years ago
parent d270dfcbd0
commit 86b6e890cf

@ -4,20 +4,22 @@
[clj-yaml.core :as yaml]
[clojure.walk]
[orchestra.core :refer [defn-spec]]
[orchestra.spec.test :as st]))
[dda.c4k-common.predicate :as cp]))
(defn-spec cast-lazy-seq-to-vec vector?
[lazy-seq map?]
(defn-spec resolve-lazy-sequences cp/map-or-seq?
[lazy-seq cp/map-or-seq?]
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
(into [] %)
%) lazy-seq))
(defn-spec from-string map? [input string?]
(cast-lazy-seq-to-vec (yaml/parse-string input)))
(defn-spec from-string cp/map-or-seq?
[input string?]
(resolve-lazy-sequences (yaml/parse-string input)))
(defn-spec to-string string? [edn map?]
(defn-spec to-string string?
[edn cp/map-or-seq?]
(yaml/generate-string edn :dumper-options {:flow-style :block}))
(defn dispatch-by-resource-name
@ -27,6 +29,4 @@
(defmulti load-resource dispatch-by-resource-name)
(defmethod load-resource :clj [resource-name]
(slurp (io/resource resource-name)))
(st/instrument)
(slurp (io/resource resource-name)))

@ -2,7 +2,7 @@
(:require
[clojure.walk]))
;; deprecated functions were moved to dda.c4k-common.prefixes
;; deprecated functions were moved to dda.c4k-common.predicate
(defn ^{:deprecated "0.1"} bash-env-string?
[input]
(and (string? input)

@ -4,7 +4,7 @@
#?(:cljs [shadow.resource :as rc])
[dda.c4k-common.yaml :as yaml]
[dda.c4k-common.base64 :as b64]
[dda.c4k-common.prefixes :as cp]
[dda.c4k-common.predicate :as cp]
[dda.c4k-common.common :as cm]))
(defn postgres-size?

@ -1,4 +1,4 @@
(ns dda.c4k-common.prefixes)
(ns dda.c4k-common.predicate)
(defn bash-env-string?
[input]
@ -12,4 +12,8 @@
(defn letsencrypt-issuer?
[input]
(contains? #{:prod :staging} input))
(contains? #{:prod :staging} input))
(defn map-or-seq?
[input]
(or (map? input) (seq? input)))

@ -1,17 +1,21 @@
(ns dda.c4k-common.yaml
(:require
["js-yaml" :as yaml]
[clojure.string :as st]))
[clojure.string :as st]
[orchestra.core :refer-macros [defn-spec]]
[dda.c4k-common.predicate :as cp]))
(defn from-string [input]
(defn-spec from-string cp/map-or-seq?
[input string?]
(js->clj (yaml/load input)
:keywordize-keys true))
(defn to-string [edn]
(defn-spec to-string string?
[edn cp/map-or-seq?]
(yaml/dump (clj->js edn)))
(defn dispatch-by-resource-name
[resource]
(defn-spec dispatch-by-resource-name keyword?
[resource string?]
(keyword (first (st/split resource #"/"))))
(defmulti load-resource dispatch-by-resource-name)

@ -1,7 +1,8 @@
(ns dda.c4k-common.yaml-test
(:require
[clojure.test :refer [deftest is are testing run-tests]]
[dda.c4k-common.yaml :as cut]))
[dda.c4k-common.yaml :as cut]
[orchestra.spec.test :as st]))
(deftest should-dispatch-by-resource-name
(is (= :clj
@ -46,3 +47,5 @@
{:serviceName "another_keycloak"
:servicePort 8081}}]}}]}}
(cut/from-string (cut/load-resource "test/ingress_test.yaml")))))
(st/instrument)

Loading…
Cancel
Save