feat!: Implement multi-backend support, including split-files and environment#71
Conversation
|
Might be of interest to you @VPanteleev-S7 |
vpanteleev-sym
left a comment
There was a problem hiding this comment.
Looks good!
One security concern when reading stuff from the environment is to not do so automatically / implicitly, as the environment can sometimes be affected by outside parties, but looks like this is taken care of by requiring the prefix anyway.
source/configy/backend/environment.d
Outdated
| foreach (kv; this.environ.byKeyValue()) { | ||
| if (!kv.key.startsWith(this.prefix)) continue; | ||
| const kname = getKeyName(kv.key, this.prefix); | ||
| scope kn = new EnvScalar(kname[0].toLower()); |
There was a problem hiding this comment.
Normally snakeCase is converted to TITLE_CASE, but then the _ does become ambiguous. The gain in simplicity is much greater than the loss of readability though, so I think this is the right decision. Schema authors can group things in structs to improve readability as well.
ebe680f to
797ac20
Compare
The environment backend is used to read values from the environment variable, using a simple scheme (underscore-separated fields) for nesting. Likewise the 'argument' backend use command-line provided arguments. Both of those use a similar method relying on a key-parsing, hence there is a lot of common code. This will allow greater configurability for applications that wish to have modern configuration override options.
This special backend allows to combine multiple sources. It can be used to either combine multiple configuration files (with an order of priority) or multiple source (e.g. a file, the environment, and the command line).
|
New iteration is working. I think it could use an expression parser to make it possible to override elaborate nested member, but the scope of this PR is already quite large. @VPanteleev-S7 would you like to give it another look ? I haven't settled on a top-level API yet, I would like to expose something convenient instead of having to do the dance shown in the example, but that can be done in a later PR. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v3.x.x #71 +/- ##
======================================
Coverage ? 0
======================================
Files ? 0
Lines ? 0
Branches ? 0
======================================
Hits ? 0
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This is a massive change that I've been wanting to do for a while. It will allow to cover all the missing use cases we have (read from env & CLI override).
Not ready for merge yet. Need