-
Notifications
You must be signed in to change notification settings - Fork 299
#3053 Fix by using custom bool parsing that if a string is found then… #3054
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
base: main
Are you sure you want to change the base?
Conversation
… then it uses the environment replacement and looks for a true false 1 or 0.
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.
Pull request overview
This pull request fixes issue #3053 by enabling boolean configuration values to be set using environment variables. Previously, boolean values could not use environment variable substitution like string values could.
Changes:
- Added a custom
BoolJsonConverterthat handles boolean deserialization from both native JSON boolean tokens and string tokens (which enables environment variable substitution) - Registered the new converter in the JSON serialization pipeline
- Added unit tests to validate boolean values can be set through environment variables
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| src/Config/Converters/BooleanJsonConverterFactory.cs | New custom JSON converter that deserializes boolean values from both JSON booleans and strings, enabling environment variable substitution |
| src/Config/RuntimeConfigLoader.cs | Registers the BoolJsonConverter in the serialization options |
| src/Service.Tests/UnitTests/RuntimeConfigLoaderJsonDeserializerTests.cs | Adds test coverage for boolean environment variable replacement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Service.Tests/UnitTests/RuntimeConfigLoaderJsonDeserializerTests.cs
Outdated
Show resolved
Hide resolved
src/Service.Tests/UnitTests/RuntimeConfigLoaderJsonDeserializerTests.cs
Outdated
Show resolved
Hide resolved
src/Service.Tests/UnitTests/RuntimeConfigLoaderJsonDeserializerTests.cs
Outdated
Show resolved
Hide resolved
src/Service.Tests/UnitTests/RuntimeConfigLoaderJsonDeserializerTests.cs
Outdated
Show resolved
Hide resolved
…rTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| ""runtime"": { | ||
| ""telemetry"": { | ||
| ""application-insights"": { | ||
| ""enabled"": " + configValue + @", |
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.
Should there be a test for the configValue itself be in double quotes? So,
"enabled" : "true" or
"enabled" : "@env('application_insights_enabled')"
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.
Without this, the current test is not testing the scenario when configValue is hardcoded to true because this code will translate to "enabled": true,
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.
putting a load more tests
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 whole set of extra tests to handle string and non string booleans
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.
test now check for true, false, 0, 1 natively, hardcoded within a string, or from an environment replacement.
Assuming keyvault replacements would "just work"
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.
Additional testing for double quoted value boolean value to test the string deserialization.
I think this is now catered for it you mean where the json is the following. and also |
… it uses the environment replacement and looks for a true false 1 or 0.
Why make this change?
Fixes #3053
Boolean values can't be set using environment variables. This allows that
What is this change?
Using custom JsonConverter for bools that if a string is detected it uses the string serialiser that uses the environment replacement rules.
How was this tested?