diff --git a/src/clj/automaton_core/storage/component.clj b/src/clj/automaton_core/storage/component.clj index f6eb0e7c..fd799cfc 100644 --- a/src/clj/automaton_core/storage/component.clj +++ b/src/clj/automaton_core/storage/component.clj @@ -11,7 +11,7 @@ [] (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)] diff --git a/src/cljc/automaton_core/configuration/simple_files.cljc b/src/cljc/automaton_core/configuration/simple_files.cljc index aaca6e63..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 @@ -91,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)))