Skip to content

Commit bdf58bc

Browse files
committed
fix: support member-level app keys in login command
GetAccountInfo requires account-level keys, which most users don't have. Now tries GetMemberInfo first (member-level key), falls back to GetAccountInfo (account-level key). Both paths display account name, email, and timezone on success.
1 parent a6f2d18 commit bdf58bc

5 files changed

Lines changed: 36 additions & 15 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/flashcatcloud/flashduty-cli
33
go 1.25.1
44

55
require (
6-
github.com/flashcatcloud/flashduty-sdk v0.8.1-0.20260513114317-7c106c52bd36
6+
github.com/flashcatcloud/flashduty-sdk v0.8.1-0.20260513121733-bf978e2213f5
77
github.com/spf13/cobra v1.10.2
88
golang.org/x/term v0.42.0
99
gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
22
github.com/flashcatcloud/flashduty-sdk v0.8.1-0.20260513114317-7c106c52bd36 h1:yrY7iNBkZrcj6qRZsXwCzMTXjKKzDRGlca/QRfNqiZI=
33
github.com/flashcatcloud/flashduty-sdk v0.8.1-0.20260513114317-7c106c52bd36/go.mod h1:dG4eJfdZaj4jNBMwEexbfK/3PmcIMhNeJ88L/DcZzUY=
4+
github.com/flashcatcloud/flashduty-sdk v0.8.1-0.20260513121733-bf978e2213f5 h1:AwVNa+CrGqSl60Pq2RQKRV+layS5coJQx01Np+34HD4=
5+
github.com/flashcatcloud/flashduty-sdk v0.8.1-0.20260513121733-bf978e2213f5/go.mod h1:dG4eJfdZaj4jNBMwEexbfK/3PmcIMhNeJ88L/DcZzUY=
46
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
57
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
68
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

internal/cli/command_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func (m *mockClient) GetAccountInfo(context.Context) (*flashduty.AccountInfo, er
1919
return nil, fmt.Errorf("mockClient: GetAccountInfo not implemented")
2020
}
2121

22+
func (m *mockClient) GetMemberInfo(context.Context) (*flashduty.MemberInfo, error) {
23+
return nil, fmt.Errorf("mockClient: GetMemberInfo not implemented")
24+
}
25+
2226
func (m *mockClient) ListIncidents(context.Context, *flashduty.ListIncidentsInput) (*flashduty.ListIncidentsOutput, error) {
2327
return nil, fmt.Errorf("mockClient: ListIncidents not implemented")
2428
}

internal/cli/login.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ func newLoginCmd() *cobra.Command {
3838
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
3939
defer cancel()
4040

41-
// Validate by fetching account info
42-
account, err := client.GetAccountInfo(ctx)
43-
if err != nil {
44-
return fmt.Errorf("authentication failed: %w", err)
45-
}
46-
4741
// Save to config
4842
cfg, _ := config.Load()
4943
cfg.AppKey = appKey
@@ -52,16 +46,36 @@ func newLoginCmd() *cobra.Command {
5246
}
5347

5448
w := cmd.OutOrStdout()
55-
_, _ = fmt.Fprintf(w, "Logged in successfully.\n")
56-
_, _ = fmt.Fprintf(w, " Account: %s\n", account.AccountName)
57-
if account.Email != "" {
58-
_, _ = fmt.Fprintf(w, " Email: %s\n", account.Email)
49+
50+
// Try member-level key first, fall back to account-level key
51+
member, memberErr := client.GetMemberInfo(ctx)
52+
if memberErr == nil {
53+
_, _ = fmt.Fprintf(w, "Logged in successfully.\n")
54+
_, _ = fmt.Fprintf(w, " Account: %s\n", member.AccountName)
55+
_, _ = fmt.Fprintf(w, " Member: %s\n", member.MemberName)
56+
if member.Email != "" {
57+
_, _ = fmt.Fprintf(w, " Email: %s\n", member.Email)
58+
}
59+
if member.TimeZone != "" {
60+
_, _ = fmt.Fprintf(w, " Timezone: %s\n", member.TimeZone)
61+
}
62+
return nil
5963
}
60-
if account.TimeZone != "" {
61-
_, _ = fmt.Fprintf(w, " Timezone: %s\n", account.TimeZone)
64+
65+
account, accountErr := client.GetAccountInfo(ctx)
66+
if accountErr == nil {
67+
_, _ = fmt.Fprintf(w, "Logged in successfully.\n")
68+
_, _ = fmt.Fprintf(w, " Account: %s\n", account.AccountName)
69+
if account.Email != "" {
70+
_, _ = fmt.Fprintf(w, " Email: %s\n", account.Email)
71+
}
72+
if account.TimeZone != "" {
73+
_, _ = fmt.Fprintf(w, " Timezone: %s\n", account.TimeZone)
74+
}
75+
return nil
6276
}
6377

64-
return nil
78+
return fmt.Errorf("authentication failed: %w", memberErr)
6579
},
6680
}
6781
}

internal/cli/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import (
1818

1919
// flashdutyClient defines the SDK operations used by CLI commands.
2020
type flashdutyClient interface {
21-
// === Account ===
21+
// === Account / Member ===
2222
GetAccountInfo(ctx context.Context) (*flashduty.AccountInfo, error)
23+
GetMemberInfo(ctx context.Context) (*flashduty.MemberInfo, error)
2324

2425
// === EXISTING ===
2526
ListIncidents(ctx context.Context, input *flashduty.ListIncidentsInput) (*flashduty.ListIncidentsOutput, error)

0 commit comments

Comments
 (0)