Skip to content

Make env/--env set environment variables for the Dev Proxy process - #1995

Open
waldekmastykarz wants to merge 1 commit into
dotnet:mainfrom
waldekmastykarz:fix-1953-env-option
Open

waldekmastykarz wants to merge 1 commit into
dotnet:mainfrom
waldekmastykarz:fix-1953-env-option

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Closes #1953

--env and the config file's env were 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

  • Both the config file's env object and --env name=value values are now set as process environment variables in BuildApplication, right after the config file loads and before logging, services, and plugins are created. Plugins that read env vars, like RewritePlugin, ApiCenter, and the DEV_PROXY_CERT_PATH cert loading, see them. --env values take precedence over config values.
  • {var} substitution in the MinimalPermissions plugins is unchanged.
  • Added env to schemas/v4.0.0/rc.schema.json as an object with string values.
  • --env help updated. The validator now rejects entries with an empty name, like =value.

Testing

  • New EnvOptionTests cover CLI parsing and config/CLI precedence.
  • Checked by hand: a detached proxy started with --env CI=1 no longer logs the API token, because ApiSecurity reads CI. Without the flag, it does log the token.

…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
Copilot AI balanced review requested due to automatic review settings October 21, 2026 14:03
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 21, 2026 14:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment thread DevProxy/Program.cs
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);

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Environment overrides are not restored when entries are removed during hot reload.

2 open issues

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env / --env doesn't set environment variables

2 participants