Feature add env#425
Conversation
Signed-off-by: alex <alex@alex-tuxedoinfinitybooks1517gen7>
Signed-off-by: Alex <al-git001@none.at>
| use anyhow::bail; | ||
| use std::env; | ||
|
|
||
| pub fn lookup_env_value(conf_string: String) -> anyhow::Result<String> { |
| use std::env; | ||
|
|
||
| pub fn lookup_env_value(conf_string: String) -> anyhow::Result<String> { | ||
| if !conf_string.contains("{env:") { |
There was a problem hiding this comment.
Ferron config files look a lot like caddy config files. How about using the same syntax like the caddyfile "env" placeholders? See https://caddyserver.com/docs/conventions#placeholders .
| } | ||
| } | ||
|
|
||
| #[cfg(test)] |
There was a problem hiding this comment.
There should be a way to escape the placeholder, for example \{env.HOME} should render {env.HOME}.
| for kdl_entry in kdl_node.iter() { | ||
| let value = match kdl_entry.value().to_owned() { | ||
| KdlValue::String(value) => ServerConfigurationValue::String(value), | ||
| KdlValue::String(value) => { |
There was a problem hiding this comment.
It will probably be best to render all placeholders first and then process the config files. Will this config work?
{env.HTTP_ADDRESS} {
proxy "http://localhost:3000/" // Replace "http://localhost:3000" with the backend server URL
}|
Hello @amejia1! Sorry for taking so long to catch up with your comments. I found all of our points very reasonable. Regarding the implementation of them:
@DorianNiemiecSVRJS do you have any position regarding @amejia1 suggestions, specifically the env syntax and the render-order approach? In the meantime, I’m planning to prototype these changes in this PR. |
I think procedural code (like it's in https://github.com/ferronweb/ferron/blob/48eda07699092a268382fcde041b18b7c6897ee0/ferron/src/util/log_placeholders.rs) is enough... |
…placeholders.rs and log_placeholders.rs
|
Hello again @DorianNiemiecSVRJS!
I've adapted the parsing to match the style of log_placeholders.rs, could you review it? Thanks in advance! |
| let value = match kdl_entry.value().to_owned() { | ||
| KdlValue::String(value) => ServerConfigurationValue::String(value), | ||
| KdlValue::String(value) => { | ||
| let resolved_value = replace_placeholders(&value).expect("Failed to resolve environment variable in configuration"); |
There was a problem hiding this comment.
If environment variable wouldn't be found (see https://github.com/ferronweb/ferron/pull/425/changes#diff-63c5becf3cec064da1306878c6a2ffe08a0e70be83a1d6c801b59e2b268339abR8), the web server would crash... Could this be handled more gracefully, like it's in:
ferron/ferron-common/src/util/header_placeholders.rs
Lines 3 to 118 in 9148eb9
|
Apologies for such a late review, I was working on a future major version of Ferron... |
Hi @DorianNiemiecSVRJS!
I've created this PR as a follow up of the discussion on issue #233 and the PR #236 .
I tried to follow the style of the previous PR on lookup_env_var.rs with the addition of:
I appreciate any feedback.
Thanks in advance.