mob
This commit is contained in:
parent
d270dfcbd0
commit
86b6e890cf
6 changed files with 30 additions and 19 deletions
|
@ -4,20 +4,22 @@
|
||||||
[clj-yaml.core :as yaml]
|
[clj-yaml.core :as yaml]
|
||||||
[clojure.walk]
|
[clojure.walk]
|
||||||
[orchestra.core :refer [defn-spec]]
|
[orchestra.core :refer [defn-spec]]
|
||||||
[orchestra.spec.test :as st]))
|
[dda.c4k-common.predicate :as cp]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn-spec cast-lazy-seq-to-vec vector?
|
(defn-spec resolve-lazy-sequences cp/map-or-seq?
|
||||||
[lazy-seq map?]
|
[lazy-seq cp/map-or-seq?]
|
||||||
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
|
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
|
||||||
(into [] %)
|
(into [] %)
|
||||||
%) lazy-seq))
|
%) lazy-seq))
|
||||||
|
|
||||||
(defn-spec from-string map? [input string?]
|
(defn-spec from-string cp/map-or-seq?
|
||||||
(cast-lazy-seq-to-vec (yaml/parse-string input)))
|
[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}))
|
(yaml/generate-string edn :dumper-options {:flow-style :block}))
|
||||||
|
|
||||||
(defn dispatch-by-resource-name
|
(defn dispatch-by-resource-name
|
||||||
|
@ -28,5 +30,3 @@
|
||||||
|
|
||||||
(defmethod load-resource :clj [resource-name]
|
(defmethod load-resource :clj [resource-name]
|
||||||
(slurp (io/resource resource-name)))
|
(slurp (io/resource resource-name)))
|
||||||
|
|
||||||
(st/instrument)
|
|
|
@ -2,7 +2,7 @@
|
||||||
(:require
|
(:require
|
||||||
[clojure.walk]))
|
[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?
|
(defn ^{:deprecated "0.1"} bash-env-string?
|
||||||
[input]
|
[input]
|
||||||
(and (string? input)
|
(and (string? input)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#?(:cljs [shadow.resource :as rc])
|
#?(:cljs [shadow.resource :as rc])
|
||||||
[dda.c4k-common.yaml :as yaml]
|
[dda.c4k-common.yaml :as yaml]
|
||||||
[dda.c4k-common.base64 :as b64]
|
[dda.c4k-common.base64 :as b64]
|
||||||
[dda.c4k-common.prefixes :as cp]
|
[dda.c4k-common.predicate :as cp]
|
||||||
[dda.c4k-common.common :as cm]))
|
[dda.c4k-common.common :as cm]))
|
||||||
|
|
||||||
(defn postgres-size?
|
(defn postgres-size?
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(ns dda.c4k-common.prefixes)
|
(ns dda.c4k-common.predicate)
|
||||||
|
|
||||||
(defn bash-env-string?
|
(defn bash-env-string?
|
||||||
[input]
|
[input]
|
||||||
|
@ -13,3 +13,7 @@
|
||||||
(defn letsencrypt-issuer?
|
(defn letsencrypt-issuer?
|
||||||
[input]
|
[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
|
(ns dda.c4k-common.yaml
|
||||||
(:require
|
(:require
|
||||||
["js-yaml" :as yaml]
|
["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)
|
(js->clj (yaml/load input)
|
||||||
:keywordize-keys true))
|
:keywordize-keys true))
|
||||||
|
|
||||||
(defn to-string [edn]
|
(defn-spec to-string string?
|
||||||
|
[edn cp/map-or-seq?]
|
||||||
(yaml/dump (clj->js edn)))
|
(yaml/dump (clj->js edn)))
|
||||||
|
|
||||||
(defn dispatch-by-resource-name
|
(defn-spec dispatch-by-resource-name keyword?
|
||||||
[resource]
|
[resource string?]
|
||||||
(keyword (first (st/split resource #"/"))))
|
(keyword (first (st/split resource #"/"))))
|
||||||
|
|
||||||
(defmulti load-resource dispatch-by-resource-name)
|
(defmulti load-resource dispatch-by-resource-name)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
(ns dda.c4k-common.yaml-test
|
(ns dda.c4k-common.yaml-test
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :refer [deftest is are testing run-tests]]
|
[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
|
(deftest should-dispatch-by-resource-name
|
||||||
(is (= :clj
|
(is (= :clj
|
||||||
|
@ -46,3 +47,5 @@
|
||||||
{:serviceName "another_keycloak"
|
{:serviceName "another_keycloak"
|
||||||
:servicePort 8081}}]}}]}}
|
:servicePort 8081}}]}}]}}
|
||||||
(cut/from-string (cut/load-resource "test/ingress_test.yaml")))))
|
(cut/from-string (cut/load-resource "test/ingress_test.yaml")))))
|
||||||
|
|
||||||
|
(st/instrument)
|
||||||
|
|
Loading…
Reference in a new issue