Skip to content

Commit 5026658

Browse files
committed
Address coderabbit
1 parent a386217 commit 5026658

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

cmd/login.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/localstack/lstk/internal/api"
7+
"github.com/localstack/lstk/internal/auth"
78
"github.com/localstack/lstk/internal/env"
89
"github.com/localstack/lstk/internal/log"
910
"github.com/localstack/lstk/internal/telemetry"
@@ -18,7 +19,17 @@ func newLoginCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra.
1819
Short: "Manage login",
1920
Long: "Manage login and store credentials in system keyring",
2021
PreRunE: initConfig,
21-
RunE: withCommandTelemetry("login", tel, cfg.AuthToken, func(cmd *cobra.Command, args []string) error {
22+
RunE: withCommandTelemetry("login", tel, func() string {
23+
tokenStorage, err := auth.NewTokenStorage(cfg.ForceFileKeyring, logger)
24+
if err != nil {
25+
return cfg.AuthToken
26+
}
27+
token, err := tokenStorage.GetAuthToken()
28+
if err != nil {
29+
return cfg.AuthToken
30+
}
31+
return token
32+
}, func(cmd *cobra.Command, args []string) error {
2233
if !isInteractiveMode(cfg) {
2334
return fmt.Errorf("login requires an interactive terminal")
2435
}

cmd/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func newLogoutCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra
2323
Use: "logout",
2424
Short: "Remove stored authentication credentials",
2525
PreRunE: initConfig,
26-
RunE: withCommandTelemetry("logout", tel, cfg.AuthToken, func(cmd *cobra.Command, args []string) error {
26+
RunE: withCommandTelemetry("logout", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
2727
platformClient := api.NewPlatformClient(cfg.APIEndpoint, logger)
2828
appConfig, err := config.Get()
2929
if err != nil {

cmd/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newLogsCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command {
1919
Short: "Show emulator logs",
2020
Long: "Show logs from the emulator. Use --follow to stream in real-time.",
2121
PreRunE: initConfig,
22-
RunE: withCommandTelemetry("logs", tel, cfg.AuthToken, func(cmd *cobra.Command, args []string) error {
22+
RunE: withCommandTelemetry("logs", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
2323
follow, err := cmd.Flags().GetBool("follow")
2424
if err != nil {
2525
return err

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func runStart(cmd *cobra.Command, rt runtime.Runtime, cfg *env.Env, tel *telemet
161161
// emitted after every invocation. Use this for commands that do not emit
162162
// lstk_lifecycle events (i.e. everything except start/stop, which manage their
163163
// own commandEventID for cross-event correlation).
164-
func withCommandTelemetry(name string, tel *telemetry.Client, authToken string, fn func(*cobra.Command, []string) error) func(*cobra.Command, []string) error {
164+
func withCommandTelemetry(name string, tel *telemetry.Client, resolveAuthToken func() string, fn func(*cobra.Command, []string) error) func(*cobra.Command, []string) error {
165165
return func(cmd *cobra.Command, args []string) error {
166166
startTime := time.Now()
167167
runErr := fn(cmd, args)
@@ -180,7 +180,7 @@ func withCommandTelemetry(name string, tel *telemetry.Client, authToken string,
180180
}
181181
}
182182
tel.Emit(cmd.Context(), "lstk_command", telemetry.ToMap(telemetry.CommandEvent{
183-
Environment: tel.GetEnvironment(authToken),
183+
Environment: tel.GetEnvironment(resolveAuthToken()),
184184
Parameters: telemetry.CommandParameters{Command: name, Flags: flags},
185185
Result: telemetry.CommandResult{
186186
DurationMS: time.Since(startTime).Milliseconds(),

cmd/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func newStatusCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command {
2222
Short: "Show emulator status and deployed resources",
2323
Long: "Show the status of a running emulator and its deployed resources",
2424
PreRunE: initConfig,
25-
RunE: withCommandTelemetry("status", tel, cfg.AuthToken, func(cmd *cobra.Command, args []string) error {
25+
RunE: withCommandTelemetry("status", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
2626
rt, err := runtime.NewDockerRuntime(cfg.DockerHost)
2727
if err != nil {
2828
return err

cmd/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newUpdateCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command {
1919
Short: "Update lstk to the latest version",
2020
Long: "Check for and apply updates to the lstk CLI. Respects the original installation method (Homebrew, npm, or direct binary).",
2121
PreRunE: initConfig,
22-
RunE: withCommandTelemetry("update", tel, cfg.AuthToken, func(cmd *cobra.Command, args []string) error {
22+
RunE: withCommandTelemetry("update", tel, func() string { return cfg.AuthToken }, func(cmd *cobra.Command, args []string) error {
2323
if isInteractiveMode(cfg) {
2424
return ui.RunUpdate(cmd.Context(), checkOnly, cfg.GitHubToken)
2525
}

0 commit comments

Comments
 (0)