fix(credential): drop misleading [id] positional from create#46
fix(credential): drop misleading [id] positional from create#46shreemaan-abhishek wants to merge 1 commit into
Conversation
The `credential create [id]` positional was ignored on the wire: the CLI POSTed to /apisix/admin/consumers/<u>/credentials with the value placed in `name`, and the server returned a fresh UUID for `id`. The help text promised something the code never did. Rename the positional to `[name]` and reflect that in: - the `Use` string and short description (id is server-generated) - the `Options.ID` -> `Options.Name` field (matches what the value actually maps to in the request body) - the existing positional test, renamed to drop "ID" from the title - the user-guide doc, with a note that the returned `id` differs from the positional `[name]` Behavior on the wire is unchanged. Closes #36.
📝 WalkthroughWalkthroughThis PR addresses the misleading credential create command signature by renaming the positional argument from ChangesCredential create: positional name instead of ID
🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
pkg/cmd/credential/create/create_test.go (1)
1-1:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd Apache 2.0 license header to this Go test file.
This modified
.gotest file is missing the required Apache 2.0 license header.As per coding guidelines, "Use Apache 2.0 license for all source files".
🤖 Prompt for 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. In `@pkg/cmd/credential/create/create_test.go` at line 1, The test file create_test.go is missing the required Apache 2.0 license header; add the standard Apache 2.0 license comment block at the top of the file above the line "package create" so every source file follows the project's licensing guideline; ensure the header matches the project's canonical Apache 2.0 text and formatting used across other Go files in the repo.pkg/cmd/credential/create/create.go (1)
1-1:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd Apache 2.0 license header to this Go source file.
This modified
.gofile is missing the required Apache 2.0 license header.As per coding guidelines, "Use Apache 2.0 license for all source files".
🤖 Prompt for 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. In `@pkg/cmd/credential/create/create.go` at line 1, This file lacks the required Apache 2.0 license header; add the standard Apache 2.0 comment block at the very top of the file (above the package declaration) including the correct year and copyright/owner, so the package create source (create.go) begins with the full Apache 2.0 header comment followed by "package create".
🤖 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/user-guide/credential.md`:
- Around line 59-61: Update the later YAML examples used in the create flows to
remove any manual `id` fields and instead rely on the server-generated id;
specifically edit the examples that show creating credentials (refer to the `a7
credential create [name] --consumer <user> -g <gateway-group>` usage) and any
YAML blocks that currently include `id:` (also referenced near the second create
example around the later block). Ensure the examples only include allowed input
fields such as `name`, `consumer`, `gateway-group` (or equivalent) and add a
brief comment or sentence showing that the `id` will be returned/generated by
the server rather than provided by the user.
---
Outside diff comments:
In `@pkg/cmd/credential/create/create_test.go`:
- Line 1: The test file create_test.go is missing the required Apache 2.0
license header; add the standard Apache 2.0 license comment block at the top of
the file above the line "package create" so every source file follows the
project's licensing guideline; ensure the header matches the project's canonical
Apache 2.0 text and formatting used across other Go files in the repo.
In `@pkg/cmd/credential/create/create.go`:
- Line 1: This file lacks the required Apache 2.0 license header; add the
standard Apache 2.0 comment block at the very top of the file (above the package
declaration) including the correct year and copyright/owner, so the package
create source (create.go) begins with the full Apache 2.0 header comment
followed by "package create".
🪄 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: CHILL
Plan: Pro
Run ID: 29d9978a-731e-491d-8742-6c7caca95f12
📒 Files selected for processing (3)
docs/user-guide/credential.mdpkg/cmd/credential/create/create.gopkg/cmd/credential/create/create_test.go
| Creates a new credential for a consumer. The credential `id` is always server-generated; the optional positional `[name]` (or the `name` field in a file payload) is stored as the credential's display name. | ||
|
|
||
| **Usage:** `a7 credential create [name] --consumer <user> -g <gateway-group>` |
There was a problem hiding this comment.
Align later config examples with the new server-generated id guidance.
This section correctly says id is server-generated, but later YAML examples still show setting id during create flows, which is misleading after this change.
Also applies to: 86-87
🤖 Prompt for 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.
In `@docs/user-guide/credential.md` around lines 59 - 61, Update the later YAML
examples used in the create flows to remove any manual `id` fields and instead
rely on the server-generated id; specifically edit the examples that show
creating credentials (refer to the `a7 credential create [name] --consumer
<user> -g <gateway-group>` usage) and any YAML blocks that currently include
`id:` (also referenced near the second create example around the later block).
Ensure the examples only include allowed input fields such as `name`,
`consumer`, `gateway-group` (or equivalent) and add a brief comment or sentence
showing that the `id` will be returned/generated by the server rather than
provided by the user.
|
Closing in favor of option 1 from the issue. After auditing api7/api7-ee-3 control-plane, PUT /apisix/admin/consumers//credentials/ upserts a credential with the client-supplied id (middleware: interceptor.go:386-400; DAO: consumer.go:352-364 OnConflict UpdateAll; BeforeCreate hook generates UUID only when CredentialID is empty). Reopening as a new PR that forwards the positional as id via PUT and adds a separate --name flag. |
Summary
credential create [id]positional was wired into the request body'snamefield, notid, so the help signature was misleading. Rename the positional to[name]and reflect that in theUsestring,Optionsfield name, the existing positional test, and the user-guide doc./apisix/admin/consumers/<u>/credentialswithnameset, server assigns theid.Test plan
go test ./pkg/cmd/credential/...passes (renamedTestCreateCredential_PositionalSetsNamecovers the positional -> name path).go test ./...passes.go build ./...clean.a7 credential create my-key --consumer alice -g default --plugins-json '{"key-auth":{"key":"k"}}'returns a credential whosenameismy-keyandidis a server-generated UUID;a7 credential create --helpno longer advertises[id].Note:
make lintsurfaces a pre-existingyamltypecheck error inpkg/cmdutilandpkg/cmd/config/configutil— reproducible on plain master, unrelated to this change.Summary by CodeRabbit
Documentation
New Features
[name]argument now represents display name only--plugins-jsonand--labelsflags--descflag for credential descriptions;--fileparameter now optional--outputformat to JSON