-
Notifications
You must be signed in to change notification settings - Fork 77
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(jans-cedarling): Load bootstrap properties from environment variables #10692
base: main
Are you sure you want to change the base?
Conversation
…alize` that allows to deserialize struct from string Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
…prove tests Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
Signed-off-by: Oleh Bohzok <[email protected]>
c046d85
to
b2df993
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add tests that load environment variables
// OR from environment variables | ||
let config = | ||
BootstrapConfig::from_raw_config_and_env(None).unwrap(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if None
is passed, it will just used defaults... should we also provide a function where the behavior is like passing in None
?
// OR from environment variables | |
let config = | |
BootstrapConfig::from_raw_config_and_env(None).unwrap(); | |
// Load the bootstrap config from the environment variables. Properties that are not defined will be assigned a default value. | |
let config = BootstrapConfig::from_env().unwrap(); | |
// Load the bootstrap config from the environment variables and a given config. | |
let config = BootstrapConfig::from_raw_config_and_env(None).unwrap(); |
/// Construct `BootstrapConfig` from environment variables and `BootstrapConfigRaw` config | ||
// | ||
// Simple implementation that map input structure to JSON map | ||
// and map environment variables with prefix `CEDARLING_` to JSON map. And merge it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also document which config source has a higher priority here.
@@ -428,7 +453,41 @@ pub struct ParseFeatureToggleError { | |||
value: String, | |||
} | |||
|
|||
/// Get environment variables related to `Cedarling` | |||
#[cfg(not(target_arch = "wasm32"))] | |||
fn cedarling_env_vars() -> HashMap<String, serde_json::Value> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_cedarling_env_vars
or get_cedarling_env_vars
might be a better name here
/// Attempts to deserialize a value, falling back to JSON parsing if the value is a string. | ||
/// Returns the deserialized value or the original error if both attempts fail. | ||
pub fn fallback_deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a better name might be deserialize_or_parse_string_as_json
/// Attempts to deserialize a value, falling back to JSON parsing if the value is a string. | |
/// Returns the deserialized value or the original error if both attempts fail. | |
pub fn fallback_deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error> | |
/// Attempts to deserialize a value, falling back to JSON parsing if the value is a string. | |
/// Returns the deserialized value or the original error if both attempts fail. | |
pub fn deserialize_or_parse_string_as_json<'de, D, T>(deserializer: D) -> Result<T, D::Error> |
/// Helper function to convert Python-style list strings to JSON format | ||
fn to_json(s: &str) -> Option<Value> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a better name might be parse_python_list_to_json
/// Helper function to convert Python-style list strings to JSON format | |
fn to_json(s: &str) -> Option<Value> { | |
/// Helper function to convert Python-style list strings to JSON format | |
fn parse_python_list_to_json(s: &str) -> Option<Value> { |
Prepare
Description
Implemented load
BootstrapConfig
from environment variablesTarget issue
link
closes #10648
Implementation Details
BootstrapConfig
from environment variablesTest and Document the changes
Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with
docs:
to indicate documentation changes or if the below checklist is not selected.