2021-06-18 14:18:46 +00:00
|
|
|
(ns dda.c4k-common.common
|
2021-06-18 13:49:43 +00:00
|
|
|
(:require
|
|
|
|
[clojure.walk]))
|
|
|
|
|
2021-08-05 15:55:17 +00:00
|
|
|
;; deprecated functions were moved to dda.c4k-common.prefixes
|
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))
|
|
|
|
|
|
|
|
(defn replace-named-value
|
|
|
|
[coll name value]
|
|
|
|
(clojure.walk/postwalk #(if (and (map? %)
|
|
|
|
(= name (:name %)))
|
|
|
|
{:name name :value value}
|
|
|
|
%)
|
|
|
|
coll))
|
|
|
|
|
|
|
|
(defn replace-key-value
|
|
|
|
[coll key value]
|
|
|
|
(clojure.walk/postwalk #(if (and (map? %)
|
|
|
|
(contains? % key))
|
|
|
|
(assoc % key value)
|
|
|
|
%)
|
|
|
|
coll))
|
|
|
|
|
|
|
|
(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 %))
|
|
|
|
(= value-to-match %))
|
|
|
|
value-to-replace
|
|
|
|
%)
|
|
|
|
coll))
|