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 core: support #file option in YamlConfig #561

Closed

Conversation

goyambokkaboy
Copy link

@goyambokkaboy goyambokkaboy commented May 2, 2024

Fixes: #548

Copy link

github-actions bot commented May 2, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@@ -128,6 +153,12 @@ YamlConfig YamlConfig::operator[](std::string_view key) const {
// Strip substitutions off to disallow nested substitutions
return YamlConfig{std::move(*env_value), {}, Mode::kSecure};
}

auto file_value = GetFromFileByKey(key, yaml_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Please also update the docs and examples at

/// If YAML has value that starts with an `$`, then such value is treated as
/// a variable from `config_vars`. For example if `config_vars` contains
/// `variable: 42` and the YAML is following:
/// @snippet universal/src/yaml_config/yaml_config_test.cpp sample vars
/// Then the result of `yaml["some_element"]["some"].As<int>()` is `42`.
///
/// If YAML key ends on '#env' and the mode is YamlConfig::Mode::kEnvAllowed,
/// then the value of the key is searched in
/// environment variables of the process and returned as a value. For example:
/// @snippet universal/src/yaml_config/yaml_config_test.cpp sample env
///
/// If YAML key ends on '#fallback', then the value of the key is used as a
/// fallback for environment and `$` variables. For example for the following
/// YAML with YamlConfig::Mode::kEnvAllowed:
/// @snippet universal/src/yaml_config/yaml_config_test.cpp sample multiple
/// The result of `yaml["some_element"]["some"].As<int>()` is the value of
/// `variable` from `config_vars` if it exists; otherwise the value is the
/// contents of the environment variable `SOME_ENV_VARIABLE` if it exists;
/// otherwise the value if `100500`, from the fallback.
///
/// Another example:
/// @snippet universal/src/yaml_config/yaml_config_test.cpp sample env fallback
/// With YamlConfig::Mode::kEnvAllowed the result of
/// `yaml["some_element"]["value"].As<int>()` is the value of `ENV_NAME`
/// environment variable if it exists; otherwise it is `5`.
///
/// @warning YamlConfig::Mode::kEnvAllowed should be used only on configs that
/// come from trusted environments. Otherwise, an attacker could create a
/// config with `#env` and read any of your environment variables, including
/// variables that contain passwords and other sensitive data.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for a review!
I have added a bit of documentation, could you please look one more time?

@goyambokkaboy
Copy link
Author

Apologies, closing the pull request, apparently I'm legally not allowed to contribute to the open source project owned/backed by Yandex.

@github-actions github-actions bot locked and limited conversation to collaborators May 6, 2024
@apolukhin
Copy link
Member

Ok

I'll implement the issue #548 by myself from scratch, to make sure that the code from this PR is not taken by any contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support #file in YamlConfig to read values from file
2 participants