Skip to content

feat(cli): add bucket command group for object-store buckets#122

Merged
sorenbs merged 5 commits into
mainfrom
feat/bucket-commands
Jul 20, 2026
Merged

feat(cli): add bucket command group for object-store buckets#122
sorenbs merged 5 commits into
mainfrom
feat/bucket-commands

Conversation

@sorenbs

@sorenbs sorenbs commented Jul 20, 2026

Copy link
Copy Markdown
Member

Purpose of change

Adds a bucket command 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 database group's four-layer architecture (commands → controllers → presenters → lib provider on ManagementApiClient):

  • bucket list — buckets for the resolved project (supports --branch, --json)
  • bucket create [--name] [--branch] — name auto-generated when omitted
  • bucket 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 as database connection create), everything else to stderr
  • bucket 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, and pnpm --filter @prisma/cli test all green (665 tests, 48 files).
  • Verified end-to-end against production (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 against t3.storage.dev with Bun.s3.
  • Note for reviewers: deleting a non-empty bucket currently surfaces a 500 from the API (bug tracked control-plane-side; fix maps it to a 409 "bucket is not empty").

🤖 Generated with Claude Code

sorenbs and others added 2 commits July 20, 2026 16:31
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>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a1934549-bea2-41ff-8aa0-1da6d462c8b5

📥 Commits

Reviewing files that changed from the base of the PR and between b8549e9 and 95b8e93.

📒 Files selected for processing (3)
  • docs/product/command-spec.md
  • docs/product/resource-model.md
  • packages/cli/README.md

Summary by CodeRabbit

  • New Features

    • Added a new bucket command with bucket list, bucket create, and bucket delete.
    • Added bucket key management with bucket key list, bucket key create, and bucket key delete.
    • bucket key create outputs one-time credentials via human output, --json, or an environment-variable block (supports quiet mode).
  • Bug Fixes

    • Added stronger validation and consistent bucket/bucket-key/branch error reporting, including invalid role handling.
  • Documentation

    • Updated command model, command specs, output/error conventions, and glossary to cover bucket and bucket keys.
  • Tests

    • Added integration-style CLI coverage for commands, output formats, and error cases.

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a bucket command group for object-store buckets.
Description check ✅ Passed The description is directly related to the changeset and accurately summarizes the new bucket command group and supporting updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/bucket-commands
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/bucket-commands

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]
coderabbitai Bot previously requested changes Jul 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1cd0121 and 18e9856.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • packages/cli/fixtures/mock-api.json
  • packages/cli/package.json
  • packages/cli/src/adapters/mock-api.ts
  • packages/cli/src/cli.ts
  • packages/cli/src/commands/bucket/index.ts
  • packages/cli/src/controllers/bucket.ts
  • packages/cli/src/lib/bucket/provider.ts
  • packages/cli/src/presenters/bucket.ts
  • packages/cli/src/shell/command-meta.ts
  • packages/cli/src/shell/errors.ts
  • packages/cli/src/types/bucket.ts
  • packages/cli/tests/bucket.test.ts

Comment thread packages/cli/src/adapters/mock-api.ts
Comment thread packages/cli/src/commands/bucket/index.ts
Comment thread packages/cli/src/controllers/bucket.ts
Comment thread packages/cli/src/controllers/bucket.ts
Comment thread packages/cli/src/presenters/bucket.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>
@sorenbs
sorenbs dismissed coderabbitai[bot]’s stale review July 20, 2026 09:55

All actionable findings fixed in eb827e8; the role-default suggestion answered as a cross-surface product decision.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 20, 2026
@sorenbs
sorenbs requested a review from kristof-siket July 20, 2026 10:02
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>
coderabbitai[bot]
coderabbitai Bot previously requested changes Jul 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between eb827e8 and b8549e9.

📒 Files selected for processing (8)
  • README.md
  • docs/product/command-principles.md
  • docs/product/command-spec.md
  • docs/product/error-conventions.md
  • docs/product/output-conventions.md
  • docs/product/resource-model.md
  • docs/reference/glossary.md
  • packages/cli/README.md

Comment thread docs/product/command-spec.md
Comment thread packages/cli/README.md Outdated
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sorenbs
sorenbs dismissed coderabbitai[bot]’s stale review July 20, 2026 10:52

Both docs findings fixed in 95b8e93.

@kristof-siket kristof-siket 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.

@sorenbs 🥇

@sorenbs
sorenbs merged commit b12c585 into main Jul 20, 2026
10 checks passed
@sorenbs
sorenbs deleted the feat/bucket-commands branch July 20, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants