From f17216ce1f5bf4ad2e9502bd2fc861e0116fc01a Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Mon, 18 Dec 2023 09:31:59 -0800 Subject: [PATCH 1/2] Don't attempt to create client with stored credentials in auth login --- internal/client/client.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/client/client.go b/internal/client/client.go index 7ecf392..d999003 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -10,8 +10,6 @@ import ( ) func NewClient(opts ...replicate.ClientOption) (*replicate.Client, error) { - baseURL := config.GetAPIBaseURL() - token, err := config.GetAPIToken() if err != nil { return nil, fmt.Errorf("failed to get API token: %w", err) @@ -20,6 +18,12 @@ func NewClient(opts ...replicate.ClientOption) (*replicate.Client, error) { return nil, fmt.Errorf("please authenticate with `replicate auth login`") } + return NewClientWithAPIToken(token, opts...) +} + +func NewClientWithAPIToken(token string, opts ...replicate.ClientOption) (*replicate.Client, error) { + baseURL := config.GetAPIBaseURL() + userAgent := fmt.Sprintf("replicate-cli/%s", internal.Version()) opts = append([]replicate.ClientOption{ @@ -37,7 +41,7 @@ func NewClient(opts ...replicate.ClientOption) (*replicate.Client, error) { } func VerifyToken(ctx context.Context, token string) (bool, error) { - r8, err := NewClient(replicate.WithToken(token)) + r8, err := NewClientWithAPIToken(token) if err != nil { return false, err } From 8b4d5edb35fc834d324b3435c9b1580d2516fca3 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Mon, 18 Dec 2023 09:35:17 -0800 Subject: [PATCH 2/2] Validate blank token when creating client for default base URL --- internal/client/client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/client/client.go b/internal/client/client.go index d999003..38478e2 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -14,7 +14,10 @@ func NewClient(opts ...replicate.ClientOption) (*replicate.Client, error) { if err != nil { return nil, fmt.Errorf("failed to get API token: %w", err) } - if token == "" { + + // Validate token when connecting to api.replicate.com. + // Alternate API hosts proxying Replicate may not require a token. + if token == "" && config.GetAPIBaseURL() == config.DefaultBaseURL { return nil, fmt.Errorf("please authenticate with `replicate auth login`") }