Skip to content

Commit

Permalink
Configuration update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaspazza committed Jan 5, 2024
1 parent ccb0f36 commit 28c9eb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/clj/automaton_core/storage/component.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
21 changes: 13 additions & 8 deletions src/cljc/automaton_core/configuration/simple_files.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)))

0 comments on commit 28c9eb7

Please sign in to comment.