warp icon indicating copy to clipboard operation
warp copied to clipboard

feat: add AWS profile context chip

Open rafet opened this issue 7 months ago • 10 comments

Closes #4461 (now labeled ready-to-implement — re-opening per the maintainer comment on the issue).

Replaces #9428, which was auto-closed by Oz before the issue was labeled. Code is unchanged from that PR's final state (commits 4c2e57e, e1b7eec, 9e9342e).

Summary

Adds an AWS Profile prompt context chip, mirroring the existing Kubernetes / git-branch chip pattern.

When the user types an AWS-related command (aws, aws-vault, awslocal, sam, eksctl, terraform, tofu, cdk, serverless/sls, chalice, copilot, amplify), the chip appears showing the active profile. Clicking it opens a searchable picker of profiles parsed from ~/.aws/config and ~/.aws/credentials. Selecting one emits a shell-appropriate command to switch profile.

Behavior

  • Active profile resolution (matches what AWS SDKs honor): AWS_VAULT → AWS_PROFILE → AWS_DEFAULT_PROFILE → default.
  • Tracked through precmd hooks, same path used by virtualenv / conda / node_version / kube_config. Updates automatically after export AWS_PROFILE=... runs in the user's interactive shell.
  • Switch command is shell-aware:
    • bash / zsh: unset AWS_VAULT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN; export AWS_PROFILE='...'
    • fish: set -e VAR…; set -gx AWS_PROFILE '...' (fish has no standard unset/export)
    • PowerShell: Remove-Item Env:VAR,… -ErrorAction SilentlyContinue; $env:AWS_PROFILE = '...'
  • The switch clears AWS_VAULT and the temporary credential triplet (AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN) so that inside an aws-vault exec session the chip's display matches what the AWS SDK actually uses.
  • Single-quote escaping for both POSIX and PowerShell so profile names with metacharacters can't break out of the quoted context.
  • The PowerShell profile-list parses ~/.aws/config and ~/.aws/credentials separately, matching POSIX/fish behavior: in config only [profile X] and [default] are profiles; in credentials every [X] is.
  • sed invocations on env-controlled paths use the -- option delimiter to prevent paths beginning with - from being parsed as a sed program.

Files changed

  • app/src/context_chips/ — new AwsProfile chip kind, menu, click handler, render function.
  • app/src/terminal/model/ — adds aws_profile field to PrecmdValue, Block, and Environment.
  • app/assets/bundled/bootstrap/{bash,zsh,fish}_body.sh — emit aws_profile in precmd JSON.
  • app/src/themes/theme.rs — adds input_prompt_aws color (defaults to terminal yellow).

Test plan

  • [x] cargo check -p warp
  • [x] cargo fmt --check -p warp
  • [x] cargo clippy -p warp --no-deps
  • [x] cargo test -p warp --lib context_chips:: (66/66 pass)
  • [x] 8 unit tests for format_aws_profile_command covering POSIX / fish / PowerShell / unknown-shell paths, single-quote escaping, metacharacter injection, vault-credentials clearing, and a negative assertion that fish never emits unset/export
  • [ ] Manual: run ./script/run, type aws s3 ls, verify chip appears with current profile
  • [ ] Manual: click chip, select different profile, verify chip updates after export runs
  • [ ] Manual: test in zsh, bash, and fish sessions

rafet avatar Apr 30 '26 10:04 rafet

@rafet

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I reviewed this pull request and requested human review from: @moirahuang.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

warp-for-oss[bot] avatar Apr 30 '26 10:04 warp-for-oss[bot]

@vkodithala thanks for the careful pass! All three points addressed in b8828bd:

  1. Empty picker before AWS_PROFILE is set — root-caused this to the chip's fingerprint being stable across early-bootstrap precmd cycles. If the on-click shell command failed during the first fetch (session not fully ready yet), the empty cached result stuck around until env-driven fingerprint change. Added ExternalCommandsState (flips once at bootstrap completion) to force a re-fetch after bootstrap, plus InvalidatingCommandCount with with_invalidate_on_commands(["aws", "aws-vault", "aws-profile", "aws2"]) so new profiles added via aws configure show up too.

  2. Re-running export on current profile — went with the "omit current from picklist" alternative you mentioned. Picker now shows only profiles the user can switch to; selecting feels intentional.

  3. Search bar with single profile — hidden when the AWS picker has ≤1 items. (After omitting the current profile, "1 item" is exactly when search becomes useless.)

Also addressed both inline nits — comment on Environment::new explaining the test-only narrow signature, and collapsed the identical GitBranch | AwsProfile arms in try_focus_open_menu.

PTAL.

rafet avatar May 04 '26 14:05 rafet

Friendly bump @vkodithala — rebased on master to resolve the conflict (test file rename + new git-branch refactor). All three review points and both nits are addressed in 10db707; tests still pass. Ready for another look when you have a moment 🙏

rafet avatar May 08 '26 13:05 rafet

Hey @rafet, thanks for the bump here! Apologies for the late re-review, was out-of-office last week and missed this. Taking a look!

vkodithala avatar May 11 '26 16:05 vkodithala

Thanks @vkodithala! Moved the ShellType import to the top of the file in 2115b49. Ready for re-review 🙏

rafet avatar May 13 '26 08:05 rafet

Rebased on master to resolve the conflicts that built up while waiting (test file renames + new CreateGitBranch struct). The 5 commits are unchanged in content, just replayed on top of latest master. Tests still pass (8/8 for the AWS-specific suite).

@vkodithala — could you take another look + approve when you have a moment? 🙏

rafet avatar May 31 '26 22:05 rafet

Hi @rafet — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 30 days of inactivity.

github-actions[bot] avatar Jun 08 '26 13:06 github-actions[bot]

Hi @rafet — final reminder: a reviewer requested changes on this PR and it has been inactive for 10 days. It will be automatically closed in about 4 day(s) unless you push updates or reply. Maintainers can apply the no-autoclose label to keep it open.

github-actions[bot] avatar Jun 11 '26 13:06 github-actions[bot]

Thanks @vkodithala, addressed all 3 in 6c146567:

1. Fish regression (the error): root-caused this to fish's set -e VAR1 VAR2 … returning exit 4 when any of the listed variables aren't set. For users who aren't inside an aws-vault session, the AWS credential triplet isn't set on the first click, so set -e exits non-zero and the chained set -gx (which actually does the work) succeeded but the overall command status was 4. Warp rendered that as a failed command. Fix: chain ; or true; after the erase so the overall exit reflects the subsequent set -gx. Verified locally:

$ fish -c "set -e AWS_VAULT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN; or true; set -gx AWS_PROFILE 'prod'; echo profile=\$AWS_PROFILE"
profile=prod
exit: 0

2. terraform / tofu / cdk / serverless etc.: Agree — trimmed AWS_COMMANDS to AWS-only CLIs (aws, aws-vault, awslocal, sam, eksctl, copilot). GCP/Azure users running terraform plan will no longer see the chip.

3. Wildcard in format_aws_profile_command: replaced _ => with explicit Some(ShellType::Bash | ShellType::Zsh) | None => so the POSIX-branch shells are declared, and future variants won't silently fall in.

On the "new pane doesn't reflect the set": This is the same architectural property as the existing node_version / virtualenv / kube_config chips — set -gx / export mutates the current shell's env, not Warp's parent process or new sessions. A new pane spawns a fresh shell that re-reads $AWS_PROFILE from system/user-shell-rc, not from the previous session. Making selections persist across panes would require Warp to track and inject the env at session-spawn time, which feels like a separate, larger change than this PR. Happy to file a follow-up issue for it if useful.

Screen recordings for fish/bash/zsh coming separately — wanted to push the fix first so you can see the regression is gone. Will reply with them shortly.

rafet avatar Jun 15 '26 07:06 rafet

Hi @rafet — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 14 days of inactivity.

github-actions[bot] avatar Jun 26 '26 12:06 github-actions[bot]

Hi @rafet — final reminder: a reviewer requested changes on this PR and it has been inactive for 10 days. It will be automatically closed in about 4 day(s) unless you push updates or reply. Maintainers can apply the no-autoclose label to keep it open.

github-actions[bot] avatar Jun 29 '26 13:06 github-actions[bot]

@vkodithala

rafet avatar Jul 01 '26 13:07 rafet

Hey @rafet, thanks for the ping and sorry for the delay here. Reviewing your PR now.

vkodithala avatar Jul 02 '26 14:07 vkodithala

/oz-review

vkodithala avatar Jul 02 '26 14:07 vkodithala

@vkodithala

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

warp-for-oss[bot] avatar Jul 02 '26 14:07 warp-for-oss[bot]

Hi @rafet — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 14 days of inactivity.

github-actions[bot] avatar Jul 10 '26 12:07 github-actions[bot]

Hi @rafet — final reminder: a reviewer requested changes on this PR and it has been inactive for 10 days. It will be automatically closed in about 4 day(s) unless you push updates or reply. Maintainers can apply the no-autoclose label to keep it open.

github-actions[bot] avatar Jul 13 '26 13:07 github-actions[bot]