From dd96ff821f316a26006bf4d44da72a9a396899b4 Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Sat, 29 Oct 2016 23:58:52 +0200 Subject: [PATCH] agent: switch to env-config --- src/agent/dirac/agent/config.clj | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/agent/dirac/agent/config.clj b/src/agent/dirac/agent/config.clj index 8e33aaea00..08a39f7b13 100644 --- a/src/agent/dirac/agent/config.clj +++ b/src/agent/dirac/agent/config.clj @@ -1,6 +1,12 @@ (ns dirac.agent.config - (:require [dirac.lib.utils :refer [assoc-env-val deep-merge-ignoring-nils]])) + (:require [dirac.lib.utils :refer [deep-merge-ignoring-nils read-env-config]])) +(def env-config-prefix "dirac-agent") + +; you can override individual config keys via ENV variables, for example: +; DIRAC_AGENT/LOG_LEVEL=debug or DIRAC_AGENT/NREPL_SERVER/PORT=7777 +; +; see https://github.com/binaryage/env-config (def default-config {:log-level "WARN" ; OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL :max-boot-trials 10 @@ -12,25 +18,10 @@ :nrepl-tunnel {:host "localhost" :port 8231}}) -; -- environment ------------------------------------------------------------------------------------------------------------ - -(defn get-environ-config [] - (-> {} - (assoc-env-val [:log-level] :dirac-agent-log-level) - (assoc-env-val [:log-out] :dirac-agent-log-out) - (assoc-env-val [:skip-logging-setup] :dirac-agent-skip-logging-setup :bool) - (assoc-env-val [:max-boot-trials] :dirac-agent-max-boot-trials :int) - (assoc-env-val [:initial-boot-delay] :dirac-agent-initial-boot-delay :int) - (assoc-env-val [:delay-between-boot-trials] :dirac-agent-delay-between-boot-trials :int) - (assoc-env-val [:nrepl-server :host] :dirac-nrepl-server-host) - (assoc-env-val [:nrepl-server :port] :dirac-nrepl-server-port :int) - (assoc-env-val [:nrepl-tunnel :host] :dirac-agent-host) - (assoc-env-val [:nrepl-tunnel :port] :dirac-agent-port :int))) - ; -- config evaluation ------------------------------------------------------------------------------------------------------ (defn get-effective-config* [& [config]] - (let [environ-config (get-environ-config)] - (or (deep-merge-ignoring-nils default-config environ-config config) {}))) + (let [env-config (read-env-config env-config-prefix)] + (deep-merge-ignoring-nils default-config env-config config))) -(def ^:dynamic get-effective-config (memoize get-effective-config*)) ; assuming environ-config is constant +(def ^:dynamic get-effective-config (memoize get-effective-config*)) ; assuming env-config is constant