Skip to content

Commit d14cb71

Browse files
committed
fix: unify auth precedence in SDK and WebSocket paths
Update getDefaultRequestOptions to use resolveBaseURL() and resolveAPIKey() so SDK calls and WebSocket calls share the same HYPEMAN_BEARER_TOKEN > HYPEMAN_API_KEY > config file precedence.
1 parent 8674492 commit d14cb71

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

pkg/cmd/cmdutil.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,13 @@ func getDefaultRequestOptions(cmd *cli.Command) []option.RequestOption {
2727
option.WithHeader("User-Agent", fmt.Sprintf("Hypeman/CLI %s", Version)),
2828
}
2929

30-
// Load config file for fallback values
31-
cfg := loadCLIConfig()
32-
33-
// Precedence for base URL: CLI flag > env var > config file
34-
if baseURL := cmd.String("base-url"); baseURL != "" {
35-
opts = append(opts, option.WithBaseURL(baseURL))
36-
} else if baseURL := os.Getenv("HYPEMAN_BASE_URL"); baseURL != "" {
30+
// Use the same resolvers as WebSocket commands for consistent precedence
31+
if baseURL := resolveBaseURL(cmd); baseURL != "" {
3732
opts = append(opts, option.WithBaseURL(baseURL))
38-
} else if cfg.BaseURL != "" {
39-
opts = append(opts, option.WithBaseURL(cfg.BaseURL))
4033
}
4134

42-
// Precedence for API key: env var > config file
43-
// (no CLI flag for API key for security reasons)
44-
if apiKey := os.Getenv("HYPEMAN_API_KEY"); apiKey != "" {
35+
if apiKey := resolveAPIKey(); apiKey != "" {
4536
opts = append(opts, option.WithAPIKey(apiKey))
46-
} else if cfg.APIKey != "" {
47-
opts = append(opts, option.WithAPIKey(cfg.APIKey))
4837
}
4938

5039
return opts

0 commit comments

Comments
 (0)