Skip to content

Commit 48dd824

Browse files
committed
Fix auth token precedence: use resolveAPIKey() in getDefaultRequestOptions
getDefaultRequestOptions checked HYPEMAN_API_KEY and config api_key but ignored HYPEMAN_BEARER_TOKEN, while resolveAPIKey gave HYPEMAN_BEARER_TOKEN highest precedence. Commands like cp/exec that use both paths could authenticate SDK calls and WebSocket calls with different tokens. Delegate to resolveAPIKey() so both paths share the same precedence: HYPEMAN_BEARER_TOKEN > HYPEMAN_API_KEY > config api_key.
1 parent 8674492 commit 48dd824

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pkg/cmd/cmdutil.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ func getDefaultRequestOptions(cmd *cli.Command) []option.RequestOption {
3939
opts = append(opts, option.WithBaseURL(cfg.BaseURL))
4040
}
4141

42-
// Precedence for API key: env var > config file
42+
// Precedence for API key: HYPEMAN_BEARER_TOKEN > HYPEMAN_API_KEY > config file
4343
// (no CLI flag for API key for security reasons)
44-
if apiKey := os.Getenv("HYPEMAN_API_KEY"); apiKey != "" {
44+
// Uses resolveAPIKey() to keep precedence consistent with WebSocket auth.
45+
if apiKey := resolveAPIKey(); apiKey != "" {
4546
opts = append(opts, option.WithAPIKey(apiKey))
46-
} else if cfg.APIKey != "" {
47-
opts = append(opts, option.WithAPIKey(cfg.APIKey))
4847
}
4948

5049
return opts

0 commit comments

Comments
 (0)