Skip to content
This repository was archived by the owner on Nov 30, 2026. It is now read-only.

Attach bucket keys with environment:update --bucket-keys - #295

Merged
joetannenbaum merged 5 commits into
laravel:mainfrom
edgrosvenor:environment-update-bucket-key
Nov 24, 2026
Merged

joetannenbaum merged 5 commits into
laravel:mainfrom
edgrosvenor:environment-update-bucket-key

Conversation

@edgrosvenor

Copy link
Copy Markdown
Contributor

Adds --bucket-keys to environment:update, so object storage can be attached to an environment from the CLI. Until now that was dashboard-only, which is the gap behind #115.

The API attaches buckets through filesystem_keys on PATCH /environments/{environment}. UpdateEnvironmentRequestData already carried the field; no command set it.

cloud environment:update production --bucket-keys=fk-1:local:default,fk-2:public --json -n
  • Format: comma-separated KEY_ID:DISK entries, with :default on at most one. This matches how --allowed-origins takes a list, and it allows the private default disk plus a public disk that the bundled skill recommends.
  • Replaces the whole list, because the API does. An empty string detaches every bucket.
  • Needs --force to replace buckets that are already attached. The command reads the environment's buckets relationship first. This is the confirmation Bucket deletion blocked by attached keys — no CLI path to detach or cascade delete #115 said was impossible, because GET /environments/{id} didn't return attachments; it now does with include=buckets. The API still doesn't say which key or disk an attached bucket uses, so the command can't merge into the existing list.
  • Interactive runs choose a bucket, then a key, then the disk name and whether it's the default, and can repeat for more buckets.
  • environment:get now reports bucketIds, because buckets joins the default environment includes.
  • Updates the skill (SKILL.md and the new-app checklist) with the command.

Tests: 8 new cases in EnvironmentRelationshipsTest:

  • attaching several keys;
  • refusing to replace without --force, and replacing with it;
  • detaching all;
  • rejecting malformed entries and two default disks;
  • reading bucketIds.

phpstan and pint pass. The full suite has the same 8 failures with or without this change (ContextDetectorTest, RepoConfigTest, UsageCommandTest); they come from agent environment variables in the environment I ran it in.

Not tested against a live Cloud organization.

The API attaches object storage to an environment through filesystem_keys
on PATCH /environments/{environment}, but no command set it, so buckets
could only be attached from the dashboard.

--bucket-keys takes comma-separated KEY_ID:DISK entries, with :default on
at most one. The API replaces the whole list, so the option names every
bucket the environment should end up with, an empty string detaches them
all, and replacing buckets that are already attached needs --force.

Environments now include their buckets, so environment:get reports
bucketIds.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1de2b-3aa5-7684-a19c-87386ad7c591
Co-authored-by: Ed Grosvenor <ed@artisan.build>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 09:51

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

API validation errors for filesystem_keys do not match the registered bucket_keys field, causing prompt-driven updates to resend invalid values and exit instead of reopening the selector.

1 open issue
What changed in this PR

Adds bucket attachment management to environment:update, providing a CLI path to attach or detach buckets and supporting the cleanup workflow described in #115.

Changes:

  • Adds --bucket-keys and an interactive selector, with confirmation before replacing existing attachments.
  • Includes attached bucket IDs in environment responses.
  • Adds tests and updates deployment guidance.
File Description
tests/​Feature/​EnvironmentRelationshipsTest.php Tests attachments, replacement safeguards, detachment, validation, and bucket IDs.
skills/​deploying-to-cloud/​SKILL.md Documents bucket attachment syntax and replacement behavior.
skills/​deploying-to-cloud/​reference/​checklists.md Adds bucket creation and attachment to the setup checklist.
app/​Dto/​Environment.php Exposes bucketIds from the buckets relationship.
app/​Commands/​EnvironmentUpdate.php Adds option parsing, interactive selection, and replacement safeguards.
app/​Client/​Resources/​EnvironmentsResource.php Includes buckets in default environment requests.

Review effort: Balanced

Comment thread app/Commands/EnvironmentUpdate.php Resolved
The form field was named bucket_keys, so a 422 on filesystem_keys.0.disk
matched no field: an interactive update resent the same list and exited
instead of reopening the bucket selector. Name the field after the API
field and keep --bucket-keys as the option.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1de2b-3aa5-7684-a19c-87386ad7c591
Co-authored-by: Ed Grosvenor <ed@artisan.build>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 16:32

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

Disk input is not validated before serialization, allowing commas and colons to alter attachment selections, unexpectedly set a default disk, or abort the command.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Reject serialization delimiters in disk input

app/​Commands/​EnvironmentUpdate.php:647

The disk prompt accepts the delimiters used to serialize the list. For example, entering local:default and answering “No” to the default-disk question still produces a default disk after parsing; entering my,disk instead aborts the command in parseBucketKeys() rather than allowing correction. Validate the disk input before serialization so commas and colons cannot change the meaning of the selected attachments.

1 resolved since last review

Review effort: Balanced

The prompt accepted ':' and ',', the characters bucket entries are joined
with, so a disk named local:default became the default disk even after
answering no, and my,disk aborted the command. Check the name against the
API's own pattern, which excludes both.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1de2b-3aa5-7684-a19c-87386ad7c591
Co-authored-by: Ed Grosvenor <ed@artisan.build>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 16:40
@edgrosvenor

Copy link
Copy Markdown
Contributor Author

Re Copilot's "Reject serialization delimiters in disk input": fixed in 6d54f9d. The interactive disk prompt now validates against the API's own rule for disk names (^[A-Za-z0-9 _-]+$, at most 40 characters), which rules out : and ,. Without it, local:default became the default disk even after answering no, and my,disk aborted the command. A new test types local:default, checks that the prompt refuses it, and checks that the result is local, not the default disk. It failed before the change. The 422 retry test now uses a name that passes local validation, since my.disk is rejected before reaching the API.

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.

🟢 Approval recommended

No active review issues remain for the bucket-key attachment and detachment changes.

No open issues 🎉

Review effort: Balanced

@edgrosvenor

Copy link
Copy Markdown
Contributor Author

Context on #115: #148 added the bucket argument to bucket-key:delete and bucket-key:update, which was the side issue at the end of #115. The main ask, attaching and detaching a bucket key from the CLI, is still open on main, and this PR covers it.

#115's main objection was that GET /environments/{id} didn't show which buckets were attached. That's no longer true: include=buckets now returns them. This PR uses it to require --force before replacing buckets that are already attached, and environment:update --bucket-keys= (empty) detaches them all, so a bucket can be deleted from the CLI.

@joetannenbaum

Copy link
Copy Markdown
Collaborator

Thank you!

@joetannenbaum
joetannenbaum merged commit 4e5767f into laravel:main Nov 24, 2026
3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants