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]
|
2022-02-12 17:28:35 +00:00
|
|
|
[clojure.spec.alpha :as s]
|
2022-04-27 11:19:42 +00:00
|
|
|
[clojure.string :as cs]
|
2021-11-06 16:29:13 +00:00
|
|
|
#?(:clj [orchestra.core :refer [defn-spec]]
|
|
|
|
:cljs [orchestra.core :refer-macros [defn-spec]])
|
2022-05-13 12:19:37 +00:00
|
|
|
[dda.c4k-common.predicate :as cp]))
|
2021-11-05 14:00:32 +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?
|
2022-12-26 17:05:52 +00:00
|
|
|
value cp/str-or-number?]
|
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?
|
2022-12-26 17:05:52 +00:00
|
|
|
value cp/str-or-number?]
|
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?
|
2022-12-23 14:52:43 +00:00
|
|
|
[coll cp/map-or-seq?
|
2021-11-05 14:00:32 +00:00
|
|
|
value-to-match string?
|
2022-12-26 17:05:52 +00:00
|
|
|
value-to-replace cp/str-or-number?]
|
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))
|
2022-02-12 17:28:35 +00:00
|
|
|
|
|
|
|
(defn-spec concat-vec vector?
|
2022-07-29 11:46:53 +00:00
|
|
|
[& vs (s/* cp/string-sequence?)]
|
2022-07-29 10:39:40 +00:00
|
|
|
(into []
|
|
|
|
(apply concat vs)))
|
|
|
|
|
2022-12-26 17:05:52 +00:00
|
|
|
(defn generate-common
|
|
|
|
[my-config
|
|
|
|
my-auth
|
2022-12-27 07:19:22 +00:00
|
|
|
config-defaults
|
|
|
|
k8s-objects]
|
2022-12-23 14:52:43 +00:00
|
|
|
(let [resulting-config (merge config-defaults my-config)]
|
2022-04-27 11:19:42 +00:00
|
|
|
(cs/join
|
|
|
|
"\n---\n"
|
2022-12-23 14:52:43 +00:00
|
|
|
(k8s-objects resulting-config my-auth))))
|