Skip to content

Commit 5e26276

Browse files
committed
[TW-4803] fix: add missing rotate_secret.go and gitignore exception
rotate_secret.go was excluded by the *secret* gitignore pattern. Add an exception for the legitimate source file so CI can find the newRotateSecretCmd definition.
1 parent 391cc57 commit 5e26276

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ secrets.yml
114114
*secrets*
115115
*secret*
116116
!internal/ports/secrets.go
117+
!internal/cli/webhook/rotate_secret.go
118+
!internal/cli/webhook/verify_rotate_test.go
117119

118120
# OAuth tokens
119121
oauth_token*
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package webhook
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/nylas/cli/internal/cli/common"
8+
"github.com/nylas/cli/internal/ports"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func newRotateSecretCmd() *cobra.Command {
13+
var yes bool
14+
15+
cmd := &cobra.Command{
16+
Use: "rotate-secret <webhook-id>",
17+
Short: "Rotate a webhook secret",
18+
Long: `Rotate a webhook secret and print the new value.
19+
20+
Rotating a secret changes the signing key used for future webhook deliveries, so
21+
you should update your receiving service before reactivating traffic.`,
22+
Args: cobra.ExactArgs(1),
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
if !yes {
25+
return common.NewUserError(
26+
"secret rotation requires confirmation",
27+
"Re-run with --yes to rotate the webhook secret",
28+
)
29+
}
30+
31+
_, err := common.WithClientNoGrant(func(ctx context.Context, client ports.NylasClient) (struct{}, error) {
32+
rotated, err := client.RotateWebhookSecret(ctx, args[0])
33+
if err != nil {
34+
return struct{}{}, common.WrapUpdateError("webhook secret", err)
35+
}
36+
37+
fmt.Printf("%s Webhook secret rotated successfully.\n", common.Green.Sprint("✓"))
38+
fmt.Println()
39+
fmt.Printf(" Webhook ID: %s\n", rotated.ID)
40+
fmt.Printf(" Secret: %s\n", rotated.WebhookSecret)
41+
fmt.Println()
42+
fmt.Println("Update your webhook receiver to use this new secret before processing future events.")
43+
return struct{}{}, nil
44+
})
45+
return err
46+
},
47+
}
48+
49+
common.AddYesFlag(cmd, &yes)
50+
return cmd
51+
}

0 commit comments

Comments
 (0)