You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(connectors): allow HiddenValue in _env - #1853
This PR is to allow _env values to accept the new HiddenValue so secret env variables can be passed into shell commands and not be exposed in the command logs.
The issue was that _env values were treated as strings when building the export KEY=value command. This meant that HiddenValue values would be converted into their masked representation too early, this subsequently caused the masked value to be used in the actual command instead of only the displayed command
This PR preserves the HiddenValue objects while constructing the env variables. Hence the raw value can be used during execution while keeping the masked value in logs.
Reviewed this. The core fix is correct: swapping QuoteString(f"{key}={value}") for QuoteString(StringCommand(key, value, _separator="=")) keeps the HiddenValue object intact until render time, so get_raw_value unmasks to the real secret while get_masked_value falls back to HiddenValue.__str__ and shows *MASKED*. _env is only consumed in make_unix_command and all connectors route through it, so the change is well contained. Tests cover the raw, masked, and shell-char cases.
Two low severity nits, neither blocking:
arguments_typed.py hardcodes None | Mapping[str, str | HiddenValue] while arguments.py defines and uses the EnvValue = str | HiddenValue alias. The two files are meant to stay in sync. The sync linter only warns on type mismatches so CI still passes, but if EnvValue gains a member later this signature will silently drift. Using EnvValue in both keeps them coupled.
generate_env uses if value: rather than if value is not None:. Functionally harmless since the default is {} and dict.update({}) is a no-op, but it is the truthy-check pattern the repo conventions call out (distinguish unset from empty).
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
APIAPI mode specific issues.connectorsConnector issues - builtin integrations with other tools.new feature
2 participants
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.
Summary
This PR is to allow _env values to accept the new
HiddenValueso secret env variables can be passed into shell commands and not be exposed in the command logs.The issue was that _env values were treated as strings when building the
export KEY=valuecommand. This meant that HiddenValue values would be converted into their masked representation too early, this subsequently caused the masked value to be used in the actual command instead of only the displayed commandThis PR preserves the
HiddenValueobjects while constructing the env variables. Hence the raw value can be used during execution while keeping the masked value in logs.Linked Issue
Fixes #1798
Changes
HiddenValuevalues:_env=Nonefor safer handlingHiddenValueuntil the command is rendered.KEY=valueassignment quoted as one shell token.HiddenValuebeing used as an _env value.Testing
Executed connectors tests:
uv run pytest tests/test_connectors/test_util.py -k "env"Ran a tmp deploy (as shown in issues #1798) with full success:
uv run pyinfra @local ../deploy.py -vv -yChecklist
3.xat this time)scripts/dev-test.sh)scripts/dev-lint.sh)conventional commits format