Skip to content

IDE-4857: Add PathRewriteConnector for environment based API path rewriting to make commands work with MEO.#1977

Open
vishalkhode1 wants to merge 3 commits intomainfrom
IDE-4857
Open

IDE-4857: Add PathRewriteConnector for environment based API path rewriting to make commands work with MEO.#1977
vishalkhode1 wants to merge 3 commits intomainfrom
IDE-4857

Conversation

@vishalkhode1
Copy link
Copy Markdown
Contributor

@vishalkhode1 vishalkhode1 commented Apr 1, 2026

Motivation
The Cloud API endpoints differ for MEO subscriptions, requiring path rewriting for certain endpoints (e.g., /applications/{uuid}/permissions/translation/codebases/{codeBaseUuid}/permissions). This PR introduces a transparent, environment-driven path rewriting mechanism to ensure compatibility and reduce code duplication.

Proposed changes

  • Added PathRewriteConnector, a decorator for ConnectorInterface that rewrites API paths based on regex rules and the AH_CODEBASE_UUID environment variable.
  • Update ConnectorFactory to wrap connectors with PathRewriteConnector when the environment variable is set.
  • Update interface and factory return types for consistency.
  • Added PHPUnit tests for both the connector and factory logic.

Alternatives considered

  • Replacing all usages of Connector with a custom connector (rejected: too invasive and hard to maintain).
  • Service aliasing (rejected: harder to test, and not as flexible as a code-based decorator).
  • Rewrite paths at all locations and add condition check (rejected: Because that would require al lot of changes to find all paths and replace them).

Testing steps

  • Run vendor/bin/phpunit to verify all tests pass and coverage is 100% for new logic.
  • Set and unset AH_CODEBASE_UUID in your environment and verify that API calls are rewritten only when expected.
  • Manually test ssh-key upload command (e.g., ide:wizards:ssh-key:create-upload) for both MEO and non-MEO subscriptions to confirm correct endpoint usage and output.
  1. Follow the contribution guide to set up your development environment or download a pre-built acli.phar for this PR.
  2. If running from source, clear the kernel cache to pick up new and changed commands: ./bin/acli ckc
  3. Check for regressions: (add specific steps for this pr)
  4. Check new functionality: (add specific steps for this pr)

Copilot AI review requested due to automatic review settings April 1, 2026 19:06
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.37%. Comparing base (37e99ec) to head (d9897dc).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1977      +/-   ##
============================================
+ Coverage     92.34%   92.37%   +0.03%     
- Complexity     1940     1953      +13     
============================================
  Files           122      123       +1     
  Lines          7051     7082      +31     
============================================
+ Hits           6511     6542      +31     
  Misses          540      540              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Try the dev build for this PR: https://acquia-cli.s3.amazonaws.com/build/pr/1977/acli.phar

curl -OL https://acquia-cli.s3.amazonaws.com/build/pr/1977/acli.phar
chmod +x acli.phar

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a connector decorator to transparently rewrite specific Acquia Cloud API request paths when running in an MEO context (detected via AH_CODEBASE_UUID), and updates connector factory typing accordingly.

Changes:

  • Added PathRewriteConnector to rewrite /applications/{uuid}/environments and /applications/{uuid}/permissions requests to codebase-based /translation/codebases/{codebaseUuid}/... endpoints.
  • Updated ConnectorFactoryInterface (and implementations) to return ConnectorInterface.
  • Added PHPUnit coverage for the new connector and the factory behavior when AH_CODEBASE_UUID is set/unset.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/phpunit/src/CloudApi/PathRewriteConnectorTest.php Adds unit tests validating rewrite behavior, passthrough behavior, and missing-env behavior.
tests/phpunit/src/CloudApi/ConnectorFactoryTest.php Adds tests ensuring the factory wraps the connector when AH_CODEBASE_UUID is set.
src/ConnectorFactoryInterface.php Simplifies the factory contract to return ConnectorInterface.
src/CloudApi/PathRewriteConnector.php Introduces the connector decorator that performs regex-based path rewrites.
src/CloudApi/ConnectorFactory.php Wraps the created connector with PathRewriteConnector when AH_CODEBASE_UUID is present; refactors connector construction into buildConnector().
src/AcsfApi/AcsfConnectorFactory.php Aligns the ACSF connector factory return type with the updated interface (ConnectorInterface).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vishalkhode1 vishalkhode1 changed the title Fixed the error for some commands that doesn't work in MEO. IDE-4857: Fixed the error for some commands that doesn't work in MEO. Apr 2, 2026
@vishalkhode1 vishalkhode1 changed the title IDE-4857: Fixed the error for some commands that doesn't work in MEO. IDE-4857: IDE-4857: Add PathRewriteConnector for environment based API path rewriting to make commands work with MEO. Apr 2, 2026
@vishalkhode1 vishalkhode1 changed the title IDE-4857: IDE-4857: Add PathRewriteConnector for environment based API path rewriting to make commands work with MEO. IDE-4857: Add PathRewriteConnector for environment based API path rewriting to make commands work with MEO. Apr 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants