Skip to content

Add environment variable interpolation in alias definitions with security controls#6131

Merged
swissspidy merged 19 commits intomainfrom
copilot/add-env-vars-to-aliases
Mar 13, 2026
Merged

Add environment variable interpolation in alias definitions with security controls#6131
swissspidy merged 19 commits intomainfrom
copilot/add-env-vars-to-aliases

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 29, 2025

  • Explore repository structure and understand how aliases work
  • Implement environment variable interpolation in alias values
  • Add tests for environment variable interpolation
  • Manually verify the implementation
  • Add documentation for the feature
  • Run code review and address feedback
  • Run security checks
  • Fix PHPStan type return issue
  • Fix test to use existing admin user
  • Add security documentation about env vars in output
  • Add --raw flag to prevent env var interpolation
  • Refactor to reduce code duplication in alias methods
  • Refactor to eliminate @all alias addition duplication
Original prompt

This section details on the original issue you should resolve

<issue_title>Add usage of environment variables in aliases</issue_title>
<issue_description>

Since Drush 9, we can use environment variables in aliases definitions, which is a great feature to centralize datas in .env file.

In short, ${env.PROJECT_SSH_USER} is replaced by PROJECT_SSH_USER environment value, as described in https://www.drush.org/latest/site-aliases/#environment-variables

There are other related features (eg. env-vars), but I think this interpolation could be a nice addition to wp-cli aliases in a first place.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber Sounds great! Would love to see a pull request for this. We can follow Drush's implementation. @danielbachhuber Related https://github.com//issues/5566

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits October 29, 2025 20:27
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add usage of environment variables in aliases Add environment variable interpolation in alias definitions Oct 29, 2025
Copilot AI requested a review from swissspidy October 29, 2025 20:34
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 37.03704% with 34 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Configurator.php 24.39% 31 Missing ⚠️
php/WP_CLI/Runner.php 62.50% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy

This comment was marked as resolved.

- Ensure interpolate_env_vars always returns string type
- Change test to use admin instead of non-existent testuser

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review October 30, 2025 14:20
@swissspidy swissspidy requested a review from a team as a code owner October 30, 2025 14:20
@swissspidy swissspidy added scope:framework command:cli-alias Related to 'cli alias' command labels Nov 2, 2025
@swissspidy

This comment was marked as resolved.

- Add --raw flag to list and get commands to display aliases without env interpolation
- Store both raw and interpolated versions of aliases
- Add security section documenting that env vars appear in output
- Add tests for --raw flag functionality

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copilot AI changed the title Add environment variable interpolation in alias definitions Add environment variable interpolation in alias definitions with security controls Dec 12, 2025

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

- Create private get_runtime_aliases() helper method
- Both get_aliases() and get_raw_aliases() now use the helper
- Helper accepts boolean parameter to control interpolation
- Reduces code duplication and improves maintainability

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Create private add_at_all_alias() helper method
- Both aliases and raw_aliases now use the same helper
- Eliminates duplicated code blocks
- Improves maintainability

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy swissspidy added this to the 3.0.0 milestone Mar 13, 2026
@swissspidy swissspidy merged commit 9272c11 into main Mar 13, 2026
69 checks passed
@swissspidy swissspidy deleted the copilot/add-env-vars-to-aliases branch March 13, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:cli-alias Related to 'cli alias' command scope:framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add usage of environment variables in aliases

3 participants