From 203fe5603e8f34d935af614281ffcb4b2df776ff Mon Sep 17 00:00:00 2001 From: kaspazza Date: Fri, 5 Jan 2024 19:38:54 +0100 Subject: [PATCH] Align clean-hard with rest of the codebase --- bb.edn | 2 +- build_config.edn | 1 + deps.edn | 4 +-- src/clj/automaton_core/storage/component.clj | 6 ++-- .../configuration/simple_files.cljc | 29 ++++++++++--------- version.edn | 4 +-- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/bb.edn b/bb.edn index b5a647b9..1c636c44 100644 --- a/bb.edn +++ b/bb.edn @@ -1,4 +1,4 @@ -{:deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}} +{:deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.72"}} :paths [] :tasks {:requires [[automaton-build-app.tasks.launcher.bb-entrypoint :as build-task-bb-entrypoint] [babashka.process :as babahska-process]] heph-task {:doc "Launch an Hephaistox task" diff --git a/build_config.edn b/build_config.edn index aee17a92..b83b860c 100644 --- a/build_config.edn +++ b/build_config.edn @@ -3,6 +3,7 @@ :mermaid-dir "docs/code/" :publication {:as-lib org.clojars.hephaistox/automaton-core :branch "main" + :deploy-to :clojars :jar-path "target/prod/automaton-core.jar" :major-version "0.0.%d" :pom-path "target/prod/class/META-INF/maven/org.clojars.hephaistox/automaton-core/pom.xml" diff --git a/deps.edn b/deps.edn index 1fce99b6..141ccf91 100644 --- a/deps.edn +++ b/deps.edn @@ -1,5 +1,5 @@ -{:aliases {:bb-deps {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}}} - :build {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}}} +{:aliases {:bb-deps {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.72"}}} + :build {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.72"}}} :cljs-deps {:extra-deps {binaryage/devtools {:mvn/version "1.0.7"} cider/cider-nrepl {:mvn/version "0.30.0"} thheller/shadow-cljs {:mvn/version "2.26.2"}} diff --git a/src/clj/automaton_core/storage/component.clj b/src/clj/automaton_core/storage/component.clj index 4cba45e6..fd799cfc 100644 --- a/src/clj/automaton_core/storage/component.clj +++ b/src/clj/automaton_core/storage/component.clj @@ -9,9 +9,9 @@ (defn start-storage [] - (try (core-log/info "Starting storage component") + (try (core-log/info "Start storage component") (let [dc (datomic/make-datomic-client datomic-schema/all-schema) - db-uri (or (conf/read-param [:storage :datomic :url]) (conf/read-param [:storage-datomic-url])) + db-uri (conf/read-param [:storage :datomic :url]) _db-uri-valid? (when-not db-uri (throw (ex-info "Database uri was not found." {}))) conn (storage/connection dc db-uri) access (datomic/make-datomic-access)] @@ -20,7 +20,7 @@ :access access}) (catch Throwable e (core-log/fatal (ex-info "Storage component failed." {:error e}))))) -(defstate storage-state :start (start-storage) :stop (.release storage-state)) +(defstate storage-state :start (start-storage) :stop (.release (:connection @storage-state))) (defn upsert [storage update-fn] (core-log/trace "Executed: " update-fn) (storage/upsert (:access storage) (:connection storage) update-fn)) diff --git a/src/cljc/automaton_core/configuration/simple_files.cljc b/src/cljc/automaton_core/configuration/simple_files.cljc index 120dab74..95cc375a 100644 --- a/src/cljc/automaton_core/configuration/simple_files.cljc +++ b/src/cljc/automaton_core/configuration/simple_files.cljc @@ -3,9 +3,10 @@ Just like in core configuration, we are not using log nor outside dependencies to comply with the configuration requirements." (:require #?@(:clj [[clojure.edn :as edn] [clojure.java.io :as io] [automaton-core.adapters.java-properties :as java-properties]] :cljs [[cljs.reader :as edn] [goog.object :as obj]]) - [automaton-core.utils.map :as utils-map] [automaton-core.configuration.protocol :as core-conf-prot] - [automaton-core.utils.keyword :as utils-keyword])) + [automaton-core.utils.keyword :as utils-keyword] + [automaton-core.utils.map :as utils-map] + [clojure.string :as str])) #?(:cljs (def ^:private nodejs? (exists? js/require))) @@ -23,10 +24,8 @@ _ v))) -(defn str->value - "ENV vars and system properties are strings. str->value will convert: - the numbers to longs, the alphanumeric values to strings, and will use Clojure reader for the rest - in case reader can't read OR it reads a symbol, the value will be returned as is (a string)" +(defn parse-system-env + "Turns string type into number. In case of failure in parsing it's returned in a format sa it was (a string)." [v] (cond (re-matches #"[0-9]+" v) (parse-number v) (re-matches #"^(true|false)$" v) #?(:clj (Boolean/parseBoolean v) @@ -39,10 +38,11 @@ v)))) (defn read-system-env + "Reads system env properties and converts to appropriate type." [] (->> #?(:clj (System/getenv) :cljs (zipmap (obj/getKeys (.-env process)) (obj/getValues (.-env process)))) - (map (fn [[k v]] [(utils-keyword/keywordize k) (str->value v)])) + (map (fn [[k v]] [(utils-keyword/keywordize k) (parse-system-env v)])) (into {}))) (defn slurp-file @@ -71,12 +71,8 @@ (defn- warn-on-overwrite [ms] - (doseq [[k kvs] (group-by key (apply concat ms)) - :let [vs (map val kvs)] - :when (and (next kvs) (not= (first vs) (last vs)))] - (println "WARNING: configuration keys are duplicated" - {:k k - :vs vs}))) + (let [kseq (reduce (fn [acc m] (concat acc (keys m))) [] ms)] + (for [[id freq] (frequencies kseq) :when (> freq 1)] (println "WARNING: configuration keys are duplicated for:" id)))) (defn merge-configs [& m] (warn-on-overwrite m) (apply utils-map/deep-merge m)) @@ -95,7 +91,12 @@ (def ^{:doc "A map of configuration variables."} conf (memoize read-config)) +(defn env-key-path + "Turns key-path into environment type key." + [key-path] + (let [path-str (str/join "-" (map name key-path))] (when-not (str/blank? path-str) (keyword path-str)))) + (defrecord SimpleConf [] core-conf-prot/Conf - (read-conf-param [_this key-path] (get-in (conf) key-path)) + (read-conf-param [_this key-path] (or (get-in (conf) key-path) (get (conf) (env-key-path key-path)))) (config [_this] (conf))) diff --git a/version.edn b/version.edn index 17048c31..f959289c 100644 --- a/version.edn +++ b/version.edn @@ -1,4 +1,4 @@ ;;Last generated version, note a failed push consume a number {:major-version "0.0.-1" - :minor-version 26 - :version "0.0.26"} \ No newline at end of file + :minor-version 55 + :version "0.0.55"} \ No newline at end of file