Skip to content

Commit 802e26a

Browse files
committed
Fix telemetry authentication issues
- Add skipAuth annotation to all telemetry subcommands (telemetry, enable, disable, status) to allow managing telemetry without API key - Fix auth command to preserve existing telemetry preference instead of overwriting it with nil
1 parent 538c30f commit 802e26a

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎cmd/auth/auth.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ func runAuth(cmd *cobra.Command, _ []string) error {
4040
return fmt.Errorf("no API key provided")
4141
}
4242

43-
if err := authconfig.Save(&authconfig.Config{APIKey: key}); err != nil {
43+
cfg, err := authconfig.Load()
44+
if err != nil {
45+
return fmt.Errorf("loading config: %w", err)
46+
}
47+
if cfg == nil {
48+
cfg = &authconfig.Config{}
49+
}
50+
cfg.APIKey = key
51+
if err := authconfig.Save(cfg); err != nil {
4452
return fmt.Errorf("saving config: %w", err)
4553
}
4654

‎cmd/config/telemetry.go‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010

1111
func newTelemetryCmd() *cobra.Command {
1212
cmd := &cobra.Command{
13-
Use: "telemetry",
14-
Short: "Manage anonymous usage telemetry",
13+
Use: "telemetry",
14+
Short: "Manage anonymous usage telemetry",
15+
Annotations: map[string]string{"skipAuth": "true"},
1516
}
1617
cmd.AddCommand(
1718
newTelemetryEnableCmd(),
@@ -23,8 +24,9 @@ func newTelemetryCmd() *cobra.Command {
2324

2425
func newTelemetryEnableCmd() *cobra.Command {
2526
return &cobra.Command{
26-
Use: "enable",
27-
Short: "Enable anonymous usage telemetry",
27+
Use: "enable",
28+
Short: "Enable anonymous usage telemetry",
29+
Annotations: map[string]string{"skipAuth": "true"},
2830
RunE: func(cmd *cobra.Command, _ []string) error {
2931
return setTelemetry(cmd, true)
3032
},
@@ -33,8 +35,9 @@ func newTelemetryEnableCmd() *cobra.Command {
3335

3436
func newTelemetryDisableCmd() *cobra.Command {
3537
return &cobra.Command{
36-
Use: "disable",
37-
Short: "Disable anonymous usage telemetry",
38+
Use: "disable",
39+
Short: "Disable anonymous usage telemetry",
40+
Annotations: map[string]string{"skipAuth": "true"},
3841
RunE: func(cmd *cobra.Command, _ []string) error {
3942
return setTelemetry(cmd, false)
4043
},
@@ -43,8 +46,9 @@ func newTelemetryDisableCmd() *cobra.Command {
4346

4447
func newTelemetryStatusCmd() *cobra.Command {
4548
return &cobra.Command{
46-
Use: "status",
47-
Short: "Show current telemetry status",
49+
Use: "status",
50+
Short: "Show current telemetry status",
51+
Annotations: map[string]string{"skipAuth": "true"},
4852
RunE: func(cmd *cobra.Command, _ []string) error {
4953
enabled := IsTelemetryEnabled()
5054
if enabled {

0 commit comments

Comments
 (0)