-
Notifications
You must be signed in to change notification settings - Fork 0
fix: honor secret create file positional id #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
290ec63
efc4752
e7d3330
f8dfd92
7ac9d5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,23 @@ func actionRun(opts *Options) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| if opts.ID != "" { | ||
| id := strings.TrimSpace(opts.ID) | ||
| if id == "" { | ||
| return fmt.Errorf("secret provider id is required; use a positional arg or --id") | ||
| } | ||
| payload["id"] = id | ||
| } else { | ||
| id, ok := payload["id"] | ||
| if !ok || id == nil { | ||
| return fmt.Errorf("secret provider id is required; use a positional arg or --id") | ||
| } | ||
| trimmedID := strings.TrimSpace(fmt.Sprint(id)) | ||
| if trimmedID == "" { | ||
| return fmt.Errorf("secret provider id is required; use a positional arg or --id") | ||
| } | ||
| payload["id"] = trimmedID | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Comment on lines
+89
to
+98
|
||
|
|
||
| httpClient, err := opts.Client() | ||
| if err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -65,9 +65,7 @@ func TestSecret_CRUD(t *testing.T) { | |||||||||||||
|
|
||||||||||||||
| // Create | ||||||||||||||
| stdout, stderr, err := runA7WithEnv(env, "secret", "create", secretID, "-f", tmpFile, "-g", gatewayGroup) | ||||||||||||||
| if err != nil { | ||||||||||||||
| t.Skip("secret create failed (vault may not be configured)") | ||||||||||||||
| } | ||||||||||||||
| require.NoError(t, err, "secret create failed: stdout=%s stderr=%s", stdout, stderr) | ||||||||||||||
|
|
||||||||||||||
| // Get | ||||||||||||||
| stdout, stderr, err = runA7WithEnv(env, "secret", "get", secretID, "-g", gatewayGroup) | ||||||||||||||
|
|
@@ -77,7 +75,9 @@ func TestSecret_CRUD(t *testing.T) { | |||||||||||||
| // Get JSON | ||||||||||||||
| var secret map[string]interface{} | ||||||||||||||
| runA7JSON(t, env, &secret, "secret", "get", secretID, "-g", gatewayGroup, "-o", "json") | ||||||||||||||
| assert.Equal(t, secretID, secret["id"]) | ||||||||||||||
| // The runtime secret provider API returns the provider-local ID; the CLI | ||||||||||||||
| // still uses the compound ID for addressing resources. | ||||||||||||||
| assert.Equal(t, "e2e-secret-crud", secret["id"]) | ||||||||||||||
|
||||||||||||||
| assert.Equal(t, "e2e-secret-crud", secret["id"]) | |
| assert.Equal(t, secretID, secret["id"]) |
Copilot
AI
Apr 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion hard-codes the provider-local ID ("e2e-secret-crud") while the test defines secretID as the compound manager/id. To avoid the test becoming inconsistent if secretID changes, derive the expected provider-local ID from secretID (e.g., split on the first '/').
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expect the full secret id here, or normalize it in the command first.
pkg/cmd/secret/get/get.go returns item.ID as the API sent it, and pkg/api/types_secret.go unmarshals id unchanged. Without a separate normalization layer, this assertion should expect vault/e2e-secret-crud, not just e2e-secret-crud.
Suggested fix
- assert.Equal(t, "e2e-secret-crud", secret["id"])
+ assert.Equal(t, "vault/e2e-secret-crud", secret["id"])📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| assert.Equal(t, "e2e-secret-crud", secret["id"]) | |
| assert.Equal(t, "https://vault.example.com", secret["uri"]) | |
| assert.Equal(t, "kv/apisix", secret["prefix"]) | |
| assert.Equal(t, "vault/e2e-secret-crud", secret["id"]) | |
| assert.Equal(t, "https://vault.example.com", secret["uri"]) | |
| assert.Equal(t, "kv/apisix", secret["prefix"]) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@test/e2e/secret_test.go` around lines 78 - 80, The test asserts the short
secret id but the command returns the raw API id (prefixed); update the
expectation in test/e2e/secret_test.go to assert the full id
"vault/e2e-secret-crud" (or alternatively add normalization in
pkg/cmd/secret/get/get.go to strip the "vault/" prefix before printing),
referencing the code path that uses item.ID and the unmarshaling in
pkg/api/types_secret.go so the test matches the actual output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In file mode you now trim/validate
opts.ID, but in the non-file path the only check isopts.ID == "". That meansa7 secret create " " --uri ...(or--id " ") will pass local validation and fail later at the API, which is inconsistent with the stricter behavior added for file-based create. Consider normalizing/validating the ID (trim + non-empty) once and reusing it for both file and non-file modes (and ideally rejecting non-stringpayload["id"]rather thanfmt.Sprint-coercing it).