postgres: add --json body example to create-role help#5111
postgres: add --json body example to create-role help#5111jamesbroadhead wants to merge 7 commits into
--json body example to create-role help#5111Conversation
5254a5b to
4ff71dd
Compare
|
I took a look. I think the underlying problem is real: A few things I would want addressed or discussed before merge:
Test/CI note: lint, generated validation, and unit test jobs are passing on GitHub; the integration test check is currently failing. |
4ff71dd to
2238c40
Compare
|
👋 @simonfaltum @andrewnester — Claude here on James's behalf. Rebased onto current Ready for review whenever you've got a moment. (comment posted by Claude) |
`databricks postgres create-role`'s `--json` flag binds to the inner Role
object (CreateRoleRequest.Role, JSON-tagged "role"), so users supply
`spec`/`name`/etc. directly. Without an example this is non-obvious:
- Auto-generated help leaves `// TODO: complex arg: spec` with no flag
hint, so the only way to set spec fields is through `--json`.
- If a user wraps the body in `{"role": ...}` (matching the wire format
the SDK marshals to), the CLI strips `role` as unknown and ships an
empty body. The server then returns a generic
`Field 'role' is required and must contain at least one subfield with
a non-default value` — which is hard to act on.
Adds a curated override that appends a concrete service-principal-role
example to `cmd.Long`, plus a short note on the wrapping pitfall.
Same pattern (auto-gen TODO `spec`/`status`, opaque error on bad body)
exists for create-endpoint, create-branch, create-project, and
create-database. Holding off on those until this approach is approved.
Co-authored-by: Isaac
The previous example granted DATABRICKS_SUPERUSER, normalizing over-privileged service-principal roles. Drop membership_roles from the example so the default copy-paste path follows least privilege; add a note pointing to separate SQL grants and noting when DATABRICKS_SUPERUSER is appropriate. Co-authored-by: Isaac
…-role
The --json flag binds to the inner Role object, so a top-level
{"role": {...}} wrapper produced an "unknown field: role" warning, an
empty body, and a confusing server error: "Field 'role' is required".
Add a PreRunE on create-role that peeks at the raw --json bytes via a
new flags.JsonFlag.Raw() accessor and rejects any object with a top-
level "role" key, returning an actionable error that points to the
correct shape. Update the help text to reflect the new behavior and
add unit-tests covering wrapped, unwrapped, empty, non-object, and
no-flag cases.
Co-authored-by: Isaac
- Generalize the wrapped-JSON rejection into a reusable `(*flags.JsonFlag).RejectWrappedJSON(outerKey, example)` helper in libs/flags/json_flag.go. Sibling postgres commands (create-branch, create-database, create-endpoint, create-project) can adopt the same guard with a one-line call, avoiding the copy-paste-per-command shape Simon flagged. - Harden the postgres override's flag-lookup and type-assertion to fail loud with `%T` instead of silently returning nil. create-role is a generated command and the --json flag invariant should produce a visible regression if codegen ever drops it. - Add a NEXT_CHANGELOG entry for the user-visible help/error addition. Co-authored-by: Isaac
2238c40 to
76a5978
Compare
|
👋 @simonfaltum @andrewnester — Claude here on James's behalf. Apologies for the long delay — I missed Simon's May 7 review when I rebased and pinged on May 18. Catching up now. All three of Simon's items are addressed in 1. Design / scope — Generalized the wrapped-body rejection. New method return jf.RejectWrappedJSON("role", `databricks postgres create-role projects/<PROJECT_ID>/branches/<BRANCH_ID> \
--role-id <SP_CLIENT_ID> \
--json '{"spec": {...}}'`)Sibling postgres commands ( 2. Should-fix (loud type-assertion) — 3. Should-fix (NEXT_CHANGELOG) — Entry added under Diff: 5 files, +93/-27. Added a Re the CI integration-test failure you flagged: passing CI now; the rebase pulled in fixes since. (comment posted by Claude) |
simonfaltum
left a comment
There was a problem hiding this comment.
Thanks, the changelog regression is fixed now.
Summary
databricks postgres create-role's--jsonflag binds to the innerRoleobject (CreateRoleRequest.Role, JSON-tagged"role"), so users must supplyspec/name/ etc. directly. Without an example this isn't obvious — the auto-generated help leaves the spec fields unflagged (// TODO: complex arg: specin the generator), and the server's error when the body is wrong is vague:That fires whenever the inner
Rolehas no recognized fields, which most commonly happens when a user wraps the body in{"role": ...}(matching the wire format the SDK marshals to). The CLI strips the unknown outer key withWarning: unknown field: roleand ships an empty body. Walking out of that loop currently requires reading the SDK source.This adds a curated override (
cmd/workspace/postgres/overrides.go) that appends a concrete service-principal-role example tocmd.Long, plus a short note on the wrapping pitfall.Help output (after)
Scope
This PR only touches
create-role. The same shape gap (// TODO: complex arg: spec+ opaque error) exists forcreate-endpoint,create-branch,create-project, andcreate-database. Happy to extend if the approach is right; left them out so reviewers can decide on the pattern first.Test plan
go build ./cmd/workspace/postgres/...databricks postgres create-role --helpshows the new section (output above)make fmtcleanThis pull request and its description were written by Isaac.