Repository navigation
Make env/--env set environment variables for the Dev Proxy process - #1995
Open
waldekmastykarz wants to merge 1 commit into
Open
waldekmastykarz wants to merge 1 commit into
waldekmastykarz wants to merge 1 commit into
Conversation
…loses dotnet#1953 Values from the config file's `env` object and `--env` are now set as process environment variables right after the config file is loaded, before plugins are created. `--env` values take precedence. They are still used to replace {name} placeholders in API spec files for the MinimalPermissions plugins. Adds `env` to rc.schema.json and rejects `--env` entries with an empty name. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 846278cd-1ffb-4a4b-a0df-57d766209c4b
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Removed overrides persist after hot reload, and detached startup can print the API token despite the configured suppression policy.
2 open issues
What changed in this PR
Makes config env and CLI --env values available as process environment variables, addressing #1953 while preserving MinimalPermissions placeholder substitution.
Changes:
- Applies config variables before service initialization, with CLI values taking precedence.
- Updates CLI help, empty-name validation, and the configuration schema.
- Adds parsing and precedence tests.
| File | Description |
|---|---|
| schemas/v4.0.0/rc.schema.json | Defines the env configuration object. |
| DevProxy/Proxy/ProxyConfiguration.cs | Applies process environment variables. |
| DevProxy/Program.cs | Initializes environment overrides during startup. |
| DevProxy/Commands/DevProxyConfigOptions.cs | Parses early CLI environment options. |
| DevProxy/Commands/DevProxyCommand.cs | Clarifies help and rejects empty names. |
| DevProxy.Tests/EnvOptionTests.cs | Tests parsing and override precedence. |
Review effort: Balanced
| var builder = WebApplication.CreateBuilder(); | ||
|
|
||
| _ = builder.Configuration.ConfigureDevProxyConfig(options); | ||
| ProxyConfiguration.SetEnvironmentVariables(builder.Configuration, options.Env); |
Comment on lines
+73
to
+75
| foreach (var (name, value) in variables) | ||
| { | ||
| Environment.SetEnvironmentVariable(name, value); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Closes #1953
--envand the config file'senvwere described as "Variables to set for the Dev Proxy process", but they were only used to fill{var}placeholders in API spec files for the MinimalPermissions plugins.Changes
envobject and--env name=valuevalues are now set as process environment variables inBuildApplication, right after the config file loads and before logging, services, and plugins are created. Plugins that read env vars, like RewritePlugin, ApiCenter, and theDEV_PROXY_CERT_PATHcert loading, see them.--envvalues take precedence over config values.{var}substitution in the MinimalPermissions plugins is unchanged.envtoschemas/v4.0.0/rc.schema.jsonas an object with string values.--envhelp updated. The validator now rejects entries with an empty name, like=value.Testing
EnvOptionTestscover CLI parsing and config/CLI precedence.--env CI=1no longer logs the API token, becauseApiSecurityreadsCI. Without the flag, it does log the token.