Skip to content

feat: add JSON output to coder provisioner keys create - #30152

Merged
nickvigilante merged 7 commits into
mainfrom
vigilante/cli-36-coder-provisioner-keys-create-add-o-output-with-json
Nov 12, 2026
Merged

nickvigilante merged 7 commits into
mainfrom
vigilante/cli-36-coder-provisioner-keys-create-add-o-output-with-json

Conversation

@nickvigilante

@nickvigilante nickvigilante commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Uses the cliui output helpers from #30508.

coder provisioner keys create printed the new key's secret as prose, so scripts provisioning external provisioners had to scrape it and look up the key's ID and tags separately.

It now accepts -o text|json.
JSON is the key as provisioner keys list shows it (ID, name, organization, tags, created at) plus the one-time key.

Behavior change: Additive.
Default text output is unchanged.
The command now fetches the new key's metadata with the returned secret (GET /api/v2/provisionerkeys/{key}). If that fails, it prints a warning to stderr, falls back to the name, organization and tags it sent (leaving id and created_at unset), and still outputs the secret.

Decisions
  • CreateProvisionerKey only returns the secret, so the key's metadata comes from GetProvisionerKey(secret), the same lookup coder provisioner start uses. This replaced an earlier list-and-match-by-name approach, per review.
  • A failed lookup never fails the command, because the key already exists and the secret can't be shown again.

Closes CLI-36

This PR was generated by Coder Agents on behalf of @nickvigilante.

@linear-code

linear-code Bot commented Sep 30, 2026

Copy link
Copy Markdown

CLI-36

@nickvigilante
nickvigilante marked this pull request as ready for review September 30, 2026 00:43

Copy link
Copy Markdown
Contributor

I think its fine most secrets print only text like coder sceret create as it can then be piped to otehr programs coder secret create | or diected to files coder secret create > secret.txt

@nickvigilante

Copy link
Copy Markdown
Collaborator Author

@matifali Thanks for the review. Do you have any suggested changes for the PR, or are we good to merge?

@nickvigilante nickvigilante added the cli Area: CLI label Oct 5, 2026
@jeremyruppel

Copy link
Copy Markdown
Collaborator

I noticed a bunch of duplication in these PRs, particularly the json/table formatting

DRYing this up would probably go a long way for making these PRs smaller, and would set a pattern for future json/table output. I suggest asking the agent to create a new, first PR that sets up and tests some formatting helpers, then each of these callsites can be stacked on top of it

@nickvigilante

Copy link
Copy Markdown
Collaborator Author

@jeremyruppel Agree on DRYing it up. I wanted to originally do a global -o flag, but I think coder config-ssh currently uses -o for something not related to output (I think it's for SSH options), so I couldn't do it at the root level without introducing that breaking change. I'll see if there's a compromise though!

@matifali
matifali removed their request for review October 8, 2026 15:22
@nickvigilante
nickvigilante force-pushed the vigilante/cli-36-coder-provisioner-keys-create-add-o-output-with-json branch from d40e3ff to c7b78f3 Compare October 8, 2026 15:45
@nickvigilante
nickvigilante changed the base branch from main to vigilante/cli-56-cliui-add-shared-text-formatter-and-write-helpers-for-o October 8, 2026 15:45
@nickvigilante
nickvigilante requested a review from matifali October 8, 2026 15:45
@nickvigilante
nickvigilante force-pushed the vigilante/cli-36-coder-provisioner-keys-create-add-o-output-with-json branch from c7b78f3 to b3efc89 Compare October 8, 2026 18:23

@jeremyruppel jeremyruppel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Default text output is byte-identical to before, and TestProvisionerKeys passes locally. A few notes inline.

One broader question: did you consider fixing this in the API instead? postProvisionerKey already has the ID, created-at, and tags in params but only returns {key}. Adding those to CreateProvisionerKeyResponse would remove the extra list call, the race between create and list, and the zero-valued fallback below. It touches the SDK, API docs, and generated types, so a follow-up is a reasonable answer, but the CLI workaround exists only because of that gap.

Note

This review was generated by Coder Agents on behalf of @jeremyruppel.

Comment thread enterprise/cli/provisionerkeys.go Resolved
Comment thread enterprise/cli/provisionerkeys.go Resolved
Comment thread enterprise/cli/provisionerkeys.go Resolved
@nickvigilante

Copy link
Copy Markdown
Collaborator Author

@jeremyruppel I hadn't considered updating the API here, but I'll happily do that if it cuts out a race condition. Stay tuned, another PR incoming!

nickvigilante added a commit that referenced this pull request Oct 8, 2026
…pers (#30508)

Adds two small helpers to `cli/cliui/output.go` so commands that add
`-o/--output` don't repeat the same boilerplate, as suggested in
#30152 (comment) by
@jeremyruppel.

- `TextFormatFunc[T]` wraps `ChangeFormatterData(TextFormat(), ...)`
with the type assertion and "expected X, got Y" error, so a command only
supplies its render function.
- `(*OutputFormatter).WriteLine` formats data and writes it to an
`io.Writer` with a trailing newline, replacing the `Format` + `Fprintln`
block.

No existing callers change in this PR. These PRs are stacked on it and
use the helpers:

- #30135 `coder tokens create`
- #30139 `coder ai-gateway keys create`
- #30145 `coder organizations members edit-roles`
- #30152 `coder provisioner keys create`

Migrating the existing callers on `main` (for example
`cli/organization.go`, `enterprise/cli/workspaceproxy.go`) is left for a
follow-up, since some of them print with `Fprint` rather than `Fprintln`
and need care to keep output identical.

Refs CLI-56

<details>
<summary>Decision log</summary>

- A global `-o` flag on the root command was ruled out because `coder
config-ssh` already uses `-o` for `--ssh-option`.
- The "one-time secret plus metadata" response structs in #30135 and
#30152 stay local to each command, since they embed different SDK types
and a shared helper would save little.
- `WriteLine` uses `Fprintln` to match the four stacked PRs and most
existing callers.
It was renamed from `Write` during review so the trailing newline is
visible at call sites and the method is not confused with `io.Writer`.

</details>

> [!NOTE]
> This PR was generated by Coder Agents on behalf of @nickvigilante.
Base automatically changed from vigilante/cli-56-cliui-add-shared-text-formatter-and-write-helpers-for-o to main October 8, 2026 19:41
@nickvigilante
nickvigilante force-pushed the vigilante/cli-36-coder-provisioner-keys-create-add-o-output-with-json branch from 4ebc13b to e17dd34 Compare October 16, 2026 18:36
@nickvigilante
nickvigilante requested a review from untra October 16, 2026 19:36
Comment thread enterprise/cli/provisionerkeys.go Resolved
@nickvigilante
nickvigilante requested a review from untra October 20, 2026 22:56
@github-actions github-actions Bot added the stale This issue is like stale bread. label Nov 7, 2026
@github-actions github-actions Bot closed this Nov 10, 2026
@nickvigilante nickvigilante removed the stale This issue is like stale bread. label Nov 10, 2026
@nickvigilante nickvigilante reopened this Nov 10, 2026
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 16:54 — with GitHub Actions Inactive
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 16:54 — with GitHub Actions Inactive
@nickvigilante

Copy link
Copy Markdown
Collaborator Author

@untra Can I poke you for another review?

@untra

untra commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

poke me again once the light is green plz

nickvigilante and others added 7 commits November 11, 2026 00:08
`coder provisioner keys create` printed the new key's secret as prose,
so scripts provisioning external provisioners had to scrape it and look
up the key's ID and tags separately.

Linear: CLI-36
When the metadata lookup after create fails or finds no matching key,
fall back to the tags this command sent and warn on stderr in both
cases, instead of only when the list call errors.
Use GetProvisionerKey with the returned secret instead of listing all
keys and matching by name.
The CLI docs template now emits a Property/Value header for flag tables, so the new --output flag table needs regenerating to match make gen and pass lint/docs-html.
@nickvigilante
nickvigilante force-pushed the vigilante/cli-36-coder-provisioner-keys-create-add-o-output-with-json branch from 8a8bc83 to 985283f Compare November 11, 2026 00:10
@nickvigilante
nickvigilante temporarily deployed to main November 11, 2026 00:10 — with GitHub Actions Inactive
@nickvigilante

Copy link
Copy Markdown
Collaborator Author

@untra Poking you again now that the light is green.
Today's push only rebases on main and regenerates the CLI reference for the new Property | Value flag-table header, which fixes gen, lint, and offlinedocs.
It has no code changes.

The only red check is the advisory AI doc-check, which isn't required.
It timed out waiting on its review chat, the same way it's timing out on other PRs right now.
Earlier doc-check runs on this PR passed.

This comment was generated by Coder Agents on behalf of @nickvigilante.

@nickvigilante
nickvigilante merged commit 3def3bf into main Nov 12, 2026
32 of 34 checks passed
@nickvigilante
nickvigilante deleted the vigilante/cli-36-coder-provisioner-keys-create-add-o-output-with-json branch November 12, 2026 13:58
@nickvigilante
nickvigilante temporarily deployed to main November 12, 2026 13:58 — with GitHub Actions Inactive
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026

This branch was previously deployed

1 inactive deployment
main — 985283f4 Deployed Nov 12, 2026 by nickvigilante via cla #254952
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cli Area: CLI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants