Skip to content
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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

olehbozhok
Copy link
Contributor

Prepare


Description

Implemented load BootstrapConfig from environment variables

Target issue

link

closes #10648

Implementation Details

  • Implemented load BootstrapConfig from environment variables
  • updated python bindings
  • updated flask-sidecar

Test and Document the changes

  • Static code analysis has been run locally and issues have been fixed
  • Relevant unit and integration tests have been added/updated
  • Relevant documentation has been updated if any (i.e. user guides, installation and configuration guides, technical design docs etc)

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.

  • I confirm that there is no impact on the docs due to the code changes in this PR.

@olehbozhok olehbozhok self-assigned this Jan 18, 2025
@mo-auto mo-auto added area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs comp-jans-cedarling Touching folder /jans-cedarling kind-feature Issue or PR is a new feature request labels Jan 18, 2025
@olehbozhok olehbozhok removed area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs labels Jan 18, 2025
@olehbozhok olehbozhok changed the title feat(jans-cedarling): Load bootsrap properties from enviroment variables feat(jans-cedarling): Load bootstrap properties from environment variables Jan 18, 2025
@mo-auto mo-auto added area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs labels Jan 18, 2025
@olehbozhok olehbozhok force-pushed the jans-cedaling-issue-10648 branch from c046d85 to b2df993 Compare January 18, 2025 00:33
Copy link
Contributor

@rmarinn rmarinn left a 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

Comment on lines +133 to +136
// OR from environment variables
let config =
BootstrapConfig::from_raw_config_and_env(None).unwrap();

Copy link
Contributor

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?

Suggested change
// 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();

Comment on lines +468 to +471
/// 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.
Copy link
Contributor

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> {
Copy link
Contributor

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

Comment on lines +25 to +27
/// 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>
Copy link
Contributor

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

Suggested change
/// 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>

Comment on lines +9 to +10
/// Helper function to convert Python-style list strings to JSON format
fn to_json(s: &str) -> Option<Value> {
Copy link
Contributor

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

Suggested change
/// 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> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-documentation Documentation needs to change as part of issue or PR comp-docs Touching folder /docs comp-jans-cedarling Touching folder /jans-cedarling kind-feature Issue or PR is a new feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(jans-cedarling): Load bootsrap properties from enviroment variables
3 participants