This commit is contained in:
erik 2022-11-01 15:32:39 +01:00
parent 911f0d5b27
commit 75ef2572e3
2 changed files with 17 additions and 14 deletions

View file

@ -13,23 +13,26 @@
(def merged-config-and-auth? (s/and website/config? website/auth?)) (def merged-config-and-auth? (s/and website/config? website/auth?))
(defn-spec flatten-and-reduce-config pred/map-or-seq? (defn-spec sort-config pred/map-or-seq?
[unsorted-config merged-config-and-auth?] [unsorted-config merged-config-and-auth?]
(let [sorted-websites (into [] (sort-by :unique-name (unsorted-config :websites))) (let [sorted-websites (into [] (sort-by :unique-name (unsorted-config :websites)))
sorted-auth (into [] (sort-by :unique-name (unsorted-config :auth))) sorted-auth (into [] (sort-by :unique-name (unsorted-config :auth)))]
config (-> unsorted-config (-> unsorted-config
(assoc-in [:websites] sorted-websites) (assoc-in [:websites] sorted-websites)
(assoc-in [:auth] sorted-auth))] (assoc-in [:auth] sorted-auth))))
(merge (-> config :websites first)
(-> config :auth first) (defn-spec flatten-and-reduce-config pred/map-or-seq?
(when (contains? config :issuer) [config merged-config-and-auth?]
{:issuer (config :issuer)}) (merge (-> config :websites first)
(when (contains? config :volume-size) (-> config :auth first)
{:volume-size (config :volume-size)})))) (when (contains? config :issuer)
{:issuer (config :issuer)})
(when (contains? config :volume-size)
{:volume-size (config :volume-size)})))
; TODO: Find a better readable expression. ; TODO: Find a better readable expression.
(defn generate-configs [config] (defn generate-configs [config]
(loop [config config (loop [config (sort-config config)
result []] result []]
(if (and (empty? (config :auth)) (empty? (config :websites))) (if (and (empty? (config :auth)) (empty? (config :websites)))

View file

@ -50,8 +50,8 @@
(deftest test-flatten-and-reduce-config (deftest test-flatten-and-reduce-config
(is (= (is (=
(cut/flatten-and-reduce-config (merge websites auth1)) (cut/flatten-and-reduce-config (cut/sort-config (merge websites auth1)))
flattened-and-reduced-config)) flattened-and-reduced-config))
(is (= (is (=
(cut/flatten-and-reduce-config (merge websites auth2)) (cut/flatten-and-reduce-config (cut/sort-config (merge websites auth2)))
flattened-and-reduced-config))) flattened-and-reduced-config)))