-
Notifications
You must be signed in to change notification settings - Fork 280
Parse runtime config and replace @env('environmentVariableName') with associated environment variable #500
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
Parse runtime config and replace @env('environmentVariableName') with associated environment variable #500
Conversation
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.
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.
Please double check if there is absolutely no alternative in System.Text.Json
- even if it may be inconvenient, we will have to adopt it for better performance..
DataGateway.Service.Tests/Unittests/RuntimeConfigPathUnitTests.cs
Outdated
Show resolved
Hide resolved
DataGateway.Service.Tests/Unittests/RuntimeConfigPathUnitTests.cs
Outdated
Show resolved
Hide resolved
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.
Thanks for using System.Text.Json
!
Summary
This change allows for a user to place the string
@env('<Environment Variable Name>')
into values in the runtime config so that they can avoid exposing those values directly. We then take the<Environment Variable Name>
and retrieve the associated environment variable, which replaces@env('<Environment Variable Name>')
in the config.Changes
When the runtime config file is first read in
RuntimeConfigPath.cs
we parse that string and do replacements as necessary. To facilitate this parsing, we use theNewtonSoft
library, and re-write the same json string as it is read.System.Json.Text
lacks the needed functionality for reading and re-writing the json string in a convenient way. For any string values in the json, we look to replace the pattern we search for with the environment variable found from within that pattern if one exists. If the user has provided the wrong environment variable names, or they otherwise are not found, we throw an exception.The regex used for matches has comments which explain each part. The replacement function we call takes a delegate which will call out replacement helper function, that has another regex with comments that explain each part.
Testing
Integration testing will be added once we have dynamic config generation in our tests. In the meantime we test many cases with the unit tests which validate we can parse an entire config file correctly. Many of these cases attempt to break our regex pattern and may look confusing at first glance.