-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: env vars as vectors #33
Conversation
Nice catch, that's definitely something I didn't thought when doing this hahaha I think since the config component is using aero under the hood, we can simplify your code a little bit using tag literals. I did a small POC to check the idea to help you: (ns codes.clj.docs.backend.config
(:require [aero.core :as aero]
[clojure.string :as string]))
(defn- str-var->vector-var
"Converts a string config variable to a vector of strings, when applicable.
Environment variables are expected to be set as comma-separated values."
[value]
(if (string? value)
(let [split-configs (-> value
(string/split #","))
env-config (->> split-configs
(map string/trim)
(remove empty?))]
env-config)
value))
(defmethod aero/reader 'csv
[opts tag value]
(prn opts tag value)
(str-var->vector-var value))
(aero/read-config "config.edn") Where the {:debug #boolean #or [#env DEBUG "true"]
:webserver {:port #long #or [#env PORT 8080]
:factor #double #or [#env FACTOR "1.2"]
:mode #keyword #or [#env MODE "my-mode"]
:origins #csv #or [#env ORIGINS "my, domain"]}} With this we don't need to wrap the config component in a function just remember to require the We can do this PR here, evaluate and later we can move this to the config component in parenthesin/components WDYT? |
Good suggestion, @rafaeldelboni, I agree this makes things simpler. |
🔝 Thanks! |
This PR enables configurations coming from environment variables that represent multiple values to be stored as a vector in
config.edn
, which is not supported by aero config as of now. An example of such variable:ALLOWED_ORIGINS="https://domain.a.com, https://domain.b.com"
It's expected that env variables are comma-separated strings.
Their configs should have a
#csv
tag literal.Trailing commas and whitespaces are handled.