refactor(auth): organize constants and improve header casing in requests fo CI
This commit is contained in:
parent
853e023605
commit
383c80b477
4 changed files with 13 additions and 7 deletions
|
|
@ -16,8 +16,11 @@ import (
|
||||||
"github.com/sipeed/picoclaw/pkg/providers"
|
"github.com/sipeed/picoclaw/pkg/providers"
|
||||||
)
|
)
|
||||||
|
|
||||||
const supportedProvidersMsg = "supported providers: openai, anthropic, google-antigravity"
|
const (
|
||||||
const defaultAnthropicModel = "claude-sonnet-4.6"
|
supportedProvidersMsg = "supported providers: openai, anthropic, google-antigravity"
|
||||||
|
defaultAnthropicModel = "claude-sonnet-4.6"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
func authLoginCmd(provider string, useDeviceCode bool, useOauth bool) error {
|
func authLoginCmd(provider string, useDeviceCode bool, useOauth bool) error {
|
||||||
switch provider {
|
switch provider {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@ func newLoginCommand() *cobra.Command {
|
||||||
|
|
||||||
cmd.Flags().StringVarP(&provider, "provider", "p", "", "Provider to login with (openai, anthropic)")
|
cmd.Flags().StringVarP(&provider, "provider", "p", "", "Provider to login with (openai, anthropic)")
|
||||||
cmd.Flags().BoolVar(&useDeviceCode, "device-code", false, "Use device code flow (for headless environments)")
|
cmd.Flags().BoolVar(&useDeviceCode, "device-code", false, "Use device code flow (for headless environments)")
|
||||||
cmd.Flags().BoolVar(&useOauth, "setup-token", false, "Use setup-token flow for Anthropic (from `claude setup-token`)")
|
cmd.Flags().BoolVar(
|
||||||
|
&useOauth, "setup-token", false,
|
||||||
|
"Use setup-token flow for Anthropic (from `claude setup-token`)",
|
||||||
|
)
|
||||||
_ = cmd.MarkFlagRequired("provider")
|
_ = cmd.MarkFlagRequired("provider")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ func FetchAnthropicUsage(token string) (*AnthropicUsage, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "Bearer "+token)
|
req.Header.Set("Authorization", "Bearer "+token)
|
||||||
req.Header.Set("anthropic-version", anthropicAPIVersion)
|
req.Header.Set("Anthropic-Version", anthropicAPIVersion)
|
||||||
req.Header.Set("anthropic-beta", anthropicBetaHeader)
|
req.Header.Set("Anthropic-Beta", anthropicBetaHeader)
|
||||||
|
|
||||||
client := &http.Client{Timeout: 10 * time.Second}
|
client := &http.Client{Timeout: 10 * time.Second}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ func TestFetchAnthropicUsage_Success(t *testing.T) {
|
||||||
if got := r.Header.Get("Authorization"); got != "Bearer test-token" {
|
if got := r.Header.Get("Authorization"); got != "Bearer test-token" {
|
||||||
t.Errorf("Authorization = %q, want %q", got, "Bearer test-token")
|
t.Errorf("Authorization = %q, want %q", got, "Bearer test-token")
|
||||||
}
|
}
|
||||||
if got := r.Header.Get("anthropic-beta"); got != anthropicBetaHeader {
|
if got := r.Header.Get("Anthropic-Beta"); got != anthropicBetaHeader {
|
||||||
t.Errorf("anthropic-beta = %q, want %q", got, anthropicBetaHeader)
|
t.Errorf("Anthropic-Beta = %q, want %q", got, anthropicBetaHeader)
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(`{"five_hour":{"utilization":0.42},"seven_day":{"utilization":0.85}}`))
|
w.Write([]byte(`{"five_hour":{"utilization":0.42},"seven_day":{"utilization":0.85}}`))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue