2021-06-18 14:18:46 +00:00
|
|
|
(ns dda.c4k-common.common
|
2021-06-18 13:49:43 +00:00
|
|
|
(:require
|
2021-11-05 14:00:32 +00:00
|
|
|
[clojure.walk]
|
2021-11-06 16:29:13 +00:00
|
|
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
|
|
|
:cljs [orchestra.core :refer-macros [defn-spec]])
|
2021-11-05 14:00:32 +00:00
|
|
|
[dda.c4k-common.predicate :as cp]))
|
|
|
|
|
2021-06-18 13:49:43 +00:00
|
|
|
|
2021-11-05 13:11:20 +00:00
|
|
|
;; deprecated functions were moved to dda.c4k-common.predicate
|
2021-07-09 14:21:17 +00:00
|
|
|
(defn ^{:deprecated "0.1"} bash-env-string?
|
2021-06-18 13:49:43 +00:00
|
|
|
[input]
|
|
|
|
(and (string? input)
|
|
|
|
(not (re-matches #".*['\"\$]+.*" input))))
|
|
|
|
|
2021-07-09 14:21:17 +00:00
|
|
|
(defn ^{:deprecated "0.1"} fqdn-string?
|
2021-06-18 13:49:43 +00:00
|
|
|
[input]
|
|
|
|
(and (string? input)
|
|
|
|
(some? (re-matches #"(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)" input))))
|
|
|
|
|
2021-07-09 14:21:17 +00:00
|
|
|
(defn ^{:deprecated "0.1"} letsencrypt-issuer?
|
2021-06-18 13:49:43 +00:00
|
|
|
[input]
|
|
|
|
(contains? #{:prod :staging} input))
|
|
|
|
|
2021-11-05 14:00:32 +00:00
|
|
|
(defn-spec replace-named-value cp/map-or-seq?
|
|
|
|
[coll cp/map-or-seq?
|
|
|
|
name string?
|
|
|
|
value string?]
|
2021-06-18 13:49:43 +00:00
|
|
|
(clojure.walk/postwalk #(if (and (map? %)
|
|
|
|
(= name (:name %)))
|
|
|
|
{:name name :value value}
|
|
|
|
%)
|
|
|
|
coll))
|
|
|
|
|
2021-11-05 14:00:32 +00:00
|
|
|
(defn-spec replace-key-value cp/map-or-seq?
|
|
|
|
[coll cp/map-or-seq?
|
|
|
|
key keyword?
|
|
|
|
value string?]
|
2021-06-18 13:49:43 +00:00
|
|
|
(clojure.walk/postwalk #(if (and (map? %)
|
|
|
|
(contains? % key))
|
|
|
|
(assoc % key value)
|
|
|
|
%)
|
|
|
|
coll))
|
|
|
|
|
2021-11-05 14:00:32 +00:00
|
|
|
(defn-spec replace-all-matching-values-by-new-value cp/map-or-seq?
|
|
|
|
[coll string?
|
|
|
|
value-to-match string?
|
|
|
|
value-to-replace string?]
|
2021-06-18 13:49:43 +00:00
|
|
|
(clojure.walk/postwalk #(if (and (= (type value-to-match) (type %))
|
|
|
|
(= value-to-match %))
|
|
|
|
value-to-replace
|
|
|
|
%)
|
|
|
|
coll))
|