Skip to content

Commit 9b86152

Browse files
committed
Address PR review feedback on token commands
- Use requireAuth + requireSDK instead of requireAuthAndAccount: the /my/access_tokens endpoint is on the root SDK client (not account-scoped), so requiring an account blocks valid users who haven't selected one (matches the pattern used by `identity show`). - Gate the "delete" breadcrumb on a non-empty id so we don't render `fizzy token delete ` when the API response has no id. - E2e: register the cleanup hook before the second t.Fatal check so a missing-token-value failure can't strand the created token.
1 parent 7d54448 commit 9b86152

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

e2e/cli_tests/token_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ func TestAccessTokenCRUD(t *testing.T) {
1616
if tokenID == "" {
1717
t.Fatal("no token ID in create response")
1818
}
19-
if create.GetDataString("token") == "" {
20-
t.Fatal("expected raw token value in create response")
21-
}
2219
deleted := false
2320
t.Cleanup(func() {
2421
if !deleted {
2522
newHarness(t).Run("token", "delete", tokenID)
2623
}
2724
})
25+
if create.GetDataString("token") == "" {
26+
t.Fatal("expected raw token value in create response")
27+
}
2828

2929
list := h.Run("token", "list")
3030
assertOK(t, list)

internal/commands/token.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ var tokenListCmd = &cobra.Command{
1818
Short: "List personal access tokens",
1919
Long: "Lists your personal access tokens.",
2020
RunE: func(cmd *cobra.Command, args []string) error {
21-
if err := requireAuthAndAccount(); err != nil {
21+
if err := requireAuth(); err != nil {
22+
return err
23+
}
24+
if err := requireSDK(); err != nil {
2225
return err
2326
}
2427

@@ -53,7 +56,10 @@ var tokenCreateCmd = &cobra.Command{
5356
Short: "Create a personal access token",
5457
Long: "Creates a new personal access token. The token value is shown once at creation and cannot be retrieved later.",
5558
RunE: func(cmd *cobra.Command, args []string) error {
56-
if err := requireAuthAndAccount(); err != nil {
59+
if err := requireAuth(); err != nil {
60+
return err
61+
}
62+
if err := requireSDK(); err != nil {
5763
return err
5864
}
5965

@@ -82,7 +88,9 @@ var tokenCreateCmd = &cobra.Command{
8288

8389
breadcrumbs := []Breadcrumb{
8490
breadcrumb("list", "fizzy token list", "List tokens"),
85-
breadcrumb("delete", fmt.Sprintf("fizzy token delete %s", id), "Delete this token"),
91+
}
92+
if id != "" {
93+
breadcrumbs = append(breadcrumbs, breadcrumb("delete", fmt.Sprintf("fizzy token delete %s", id), "Delete this token"))
8694
}
8795

8896
notice := "Save the token now — it will not be shown again."
@@ -97,7 +105,10 @@ var tokenDeleteCmd = &cobra.Command{
97105
Long: "Deletes a personal access token by ID.",
98106
Args: cobra.ExactArgs(1),
99107
RunE: func(cmd *cobra.Command, args []string) error {
100-
if err := requireAuthAndAccount(); err != nil {
108+
if err := requireAuth(); err != nil {
109+
return err
110+
}
111+
if err := requireSDK(); err != nil {
101112
return err
102113
}
103114

0 commit comments

Comments
 (0)