feat(cli): add bucket command group for object-store buckets#122
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds `prisma-cli bucket` with six commands for managing Tigris-backed
object-store buckets through the Management API:
bucket list – lists buckets for the resolved project
bucket create – creates a bucket, optional --name and --branch
bucket delete <id> – deletes a bucket and all its access keys
bucket key list <id> – lists access keys for a bucket
bucket key create <id> – creates an access key; prints an S3 env block to
stdout (S3_ENDPOINT, S3_ACCESS_KEY_ID,
S3_SECRET_ACCESS_KEY, S3_BUCKET) and a
"shown once" warning to stderr; --json includes
the one-time secret in the JSON envelope
bucket key delete <id> <keyId> – revokes and removes an access key
Implementation follows the four-layer pattern of the database command group:
types → provider (Management API pagination + normalization) → controllers
(project resolution + fixture/real mode dispatch) → presenters (human/JSON)
→ Commander wiring.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Summary by CodeRabbit
WalkthroughAdds object-store bucket and bucket-key support to the CLI. The change introduces shared bucket types, fixture-backed mock operations, Management API providers, controller handlers, command registration, presenters, command metadata, and bucket-specific errors. It supports listing, creating, and deleting buckets and keys, including one-time credential output. Integration tests cover command help, JSON and human output, CRUD operations, quiet mode, credential rendering, and validation failures. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/src/adapters/mock-api.ts`:
- Around line 570-595: Update createBucket to validate branchGitName when
provided: if no branch for input.projectId has the requested name, surface the
fixture API’s existing branch-not-found error instead of assigning branchId
null; only create an unscoped bucket when branchGitName is omitted, preserving
successful bucket creation for valid branches.
In `@packages/cli/src/commands/bucket/index.ts`:
- Around line 202-215: Update the Commander Option for --role in the bucket
command to apply choices validation for the supported values read and
read_write. Keep resolveKeyRole as the existing role-resolution path while
ensuring invalid roles are rejected during argument parsing and the valid
choices appear in generated help.
In `@packages/cli/src/controllers/bucket.ts`:
- Around line 387-403: Update resolveKeyRole so an omitted role defaults to
least-privilege "read" access, while preserving explicit "read" and "read_write"
handling and existing invalid-role errors.
- Around line 253-325: Extract the duplicated provider-selection branch from
requireBucketContext and requireBucketProviderOnly into a shared
resolveBucketProvider(context) helper, preserving authentication and
authRequiredError handling for real mode and fixture-provider creation
otherwise. Update both existing functions to call the helper, while keeping
requireBucketContext’s project-resolution logic unchanged.
In `@packages/cli/src/presenters/bucket.ts`:
- Around line 72-90: Update the items mapping in serializeBucketList so each
item’s status uses the corresponding bucket.status value instead of hardcoded
null, preserving the bucket status in the canonical serialized list.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 9bec4542-9372-4402-a716-4de7224cc53d
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (12)
packages/cli/fixtures/mock-api.jsonpackages/cli/package.jsonpackages/cli/src/adapters/mock-api.tspackages/cli/src/cli.tspackages/cli/src/commands/bucket/index.tspackages/cli/src/controllers/bucket.tspackages/cli/src/lib/bucket/provider.tspackages/cli/src/presenters/bucket.tspackages/cli/src/shell/command-meta.tspackages/cli/src/shell/errors.tspackages/cli/src/types/bucket.tspackages/cli/tests/bucket.test.ts
- MockApi.createBucket returns undefined when branchGitName is supplied but no matching branch exists; the fixture provider throws BRANCH_NOT_FOUND instead of silently creating an unscoped bucket - --role on bucket key create uses Option.choices(["read", "read_write"]) for parse-time validation and self-documenting --help output; resolveKeyRole simplified to a single ternary now that Commander handles the invalid-choice rejection - resolveBucketProvider helper extracted from requireBucketContext / requireBucketProviderOnly; requireBucketProviderOnly delegates to it - serializeBucketList passes bucket.status through in items instead of hardcoding null; builds the items mapping directly instead of going through serializeList whose ListItem.status is restricted to the AnnotationStatus union Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
All actionable findings fixed in eb827e8; the role-default suggestion answered as a cross-surface product decision.
Covers all six shipped commands (bucket list, bucket create, bucket delete, bucket key list, bucket key create, bucket key delete) across the docs that enumerate commands or resources. - command-spec.md: add bucket to scope, add per-command sections matching the database connection group format; includes flag tables, JSON envelope shapes (derived from the serialize* functions), error codes, and the reveal-once S3 env-block stdout behavior of bucket key create - resource-model.md: add Bucket / Object Store section; update the North Star Hierarchy and Relationships diagram to include bucket and bucket_key; update the long-term resource description - error-conventions.md: add BUCKET_NOT_FOUND, BUCKET_KEY_NOT_FOUND, BUCKET_KEY_SECRET_MISSING, BRANCH_NOT_FOUND to the MVP error code list and recommended meanings; add bucket to the error.domain enumeration - output-conventions.md: add bucket commands to the pattern mapping table - command-principles.md: add bucket to the preview implementation list and stable nouns - glossary.md: add Bucket, Bucket key entries; fix the Database entry (it was still marked out of scope for the beta) - README.md (root): add database and bucket to the command model list - packages/cli/README.md: add database and bucket rows to the commands table Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/product/command-spec.md`:
- Around line 1351-1358: Update the delete-bucket behavior documentation in
docs/product/command-spec.md at lines 1351-1358 to state that deleting a
non-empty bucket currently fails with HTTP 500, while retaining the documented
successful cascade for deletable buckets and adding the limitation to the error
notes. In docs/product/resource-model.md at lines 181-182, clarify that
access-key revocation occurs only after successful bucket deletion and document
the same non-empty-bucket limitation.
In `@packages/cli/README.md`:
- Around line 79-80: Update the README’s bucket command description to use the
CLI’s actual verbs: replace “inspect” with “list” and “remove” with “delete,”
matching the commands exposed by the bucket functionality.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c1fd642d-af21-461c-8e45-bd9722d650f7
📒 Files selected for processing (8)
README.mddocs/product/command-principles.mddocs/product/command-spec.mddocs/product/error-conventions.mddocs/product/output-conventions.mddocs/product/resource-model.mddocs/reference/glossary.mdpackages/cli/README.md
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Both docs findings fixed in 95b8e93.
Purpose of change
Adds a
bucketcommand group so object-store buckets (shipped in Console + Management API via prisma/pdp-control-plane#4562 / #4594) can be managed from the CLI.What's changed and why
New command group mirroring the
databasegroup's four-layer architecture (commands → controllers → presenters → lib provider onManagementApiClient):bucket list— buckets for the resolved project (supports--branch,--json)bucket create [--name] [--branch]— name auto-generated when omittedbucket delete <bucketId>bucket key list <bucketId>bucket key create <bucketId> [--role read|read_write] [--name]— prints the one-time credential as a ready-to-paste env block (S3_ENDPOINT/S3_ACCESS_KEY_ID/S3_SECRET_ACCESS_KEY/S3_BUCKET, the exact shape Bun's S3 client reads and the Console shows); env block goes to stdout for piping (same pattern asdatabase connection create), everything else to stderrbucket key delete <bucketId> <keyId>Also: SDK bump to
@prisma/management-api-sdk@^1.50.0(first version with the typed bucket endpoints), MockApi fixtures for bucket/key CRUD, 16 new tests.Testing notes / Before-after
pnpm --recursive exec tsc --noEmit, biome, andpnpm --filter @prisma/cli testall green (665 tests, 48 files).api.prisma.io) with a workspace service token: create bucket → key create (env block printed, secret revealed once) → key list → key delete → bucket delete → empty list. The minted credentials were previously verified to work againstt3.storage.devwithBun.s3.🤖 Generated with Claude Code