iggy
iggy copied to clipboard
Improve `config_provider.rs` by adding parsing of arrays
Currently, we can't overwrite array config entries from env, eg.:
The aim of this issue is to implement some kind of parser in config_provider.rs, so that user can call
IGGY_HTTP_CORS_ALLOWED_METHODS=GET,POST cargo run --bin iggy-server
and http.cors.allowed_methods
should be overwritten with above value (from env).
Hey @hubcio ,
I read the requirements above and checked the config_provider.rs
. The challenge with the current implementation (Especially function try_parse_value
is, that we do not have any context information about the data type of the environment variable.
Example:
- Desired behavior
- Env variable
IGGY_HTTP_CORS_ALLOWED_METHODS=GET,POST
will overwrite the environment variableallowed_methods
with the value"allowed_methods": Array(Tag::Default, [String(Tag::Default, "GET"), String(Tag::Default, "POST")])
- Env variable
- Wrong behaviour
- Env variable
IGGY_HTTP_JWT_ENCODING_SECRET=Super%&!Secret__>>>,<<<___Pa55word
(With a comma in the password string) leads to the value"encoding_secret": Array(Tag::Default, [String(Tag::Default, "Super%&!Secret__>>>"), String(Tag::Default, "<<<___Pa55word")])
- This will lead to the following error:
- Env variable
Error: CannotLoadConfiguration("Failed to load configuration: invalid type: found sequence, expected a string for key \"default.http.jwt.encoding_secret\" in iggy-server config")
The challenge is, to connect the environment variable with the target data type of the ServerConfig
struct and parse the value as either string or string Vec according to the related data type.
Do you have any hint, how to achieve this with the current env implementation?
@PierreBartholomae forgive me, but you already got answer on discord regarding this, right?