-
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>
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 |
|
I am not sure this resolves JSON Schema constraints/editing errors, does it? |
@JerryNixon It doesn't but I've just pushed change to the schema that would. If thats an acceptable approach I can apply to other booleans. Interestinlythere does seem to be a mix of json schema validation jsonconverter validation. The jsonconverter stuff looks overly complicated. for some simple serialisation. |
|
Added tests to validate the schema approach. for key enabled flags. |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
forgot formatting, try again |
Co-authored-by: Jerry Nixon <1749983+JerryNixon@users.noreply.github.com>
Co-authored-by: Jerry Nixon <1749983+JerryNixon@users.noreply.github.com>
Co-authored-by: Jerry Nixon <1749983+JerryNixon@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
| { | ||
| "type": [ "boolean", "string" ], | ||
| "pattern": "^(true|false|1|0|@env\\('.*'\\)|@akv\\('.*'\\))$" | ||
| "pattern": "^(?:true|false|1|0|@.{3}\\('.*'\\))$" |
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.
wouldnt doing .{3} allow any pattern other than env or akv?
If yes, I think we should retain the previous pattern.
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.
This was @JerryNixon 's suggestion. Assume it was a bit of forward planning.
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.
Looks good, except for the pattern match for @env/@akv.
Can you discuss this with @JerryNixon and decide |
|
Integration tests aren't passing, is that an issue? |
that's not. rerunning should fix it. |
checked with Jerry. your previous pattern is what we both recommend. |
… 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?