From 5bcbf058b740be0a8eb614ed5742f452d6bab3c2 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 5 Nov 2024 10:01:42 +0545 Subject: [PATCH] fix: auth token isn't mandatory for all services --- pkg/clients/git/connectors/git_access_token.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/clients/git/connectors/git_access_token.go b/pkg/clients/git/connectors/git_access_token.go index 8b22b374..851bf9eb 100644 --- a/pkg/clients/git/connectors/git_access_token.go +++ b/pkg/clients/git/connectors/git_access_token.go @@ -2,6 +2,7 @@ package connectors import ( "fmt" + netHTTP "net/http" "os" "github.com/flanksource/commons/logger" @@ -36,19 +37,15 @@ type GitAccessTokenClient struct { func NewAccessTokenClient(service, owner, repoName, accessToken string) (Connector, error) { logger.Infof("Creating %s client for %s/%s using access token: %s", service, owner, repoName, logger.PrintableSecret(accessToken)) scmClient, err := factory.NewClient(service, "", accessToken) + if err != nil { + return nil, fmt.Errorf("failed to create git client with access token: %v", err) + } if scmClient.Client == nil { - if accessToken == "" { - return nil, fmt.Errorf("unable to create %s client. missing access token", service) - } - - return nil, fmt.Errorf("unable to create %s client for unknown reason", service) + scmClient.Client = netHTTP.DefaultClient } scmClient.Client.Transport = logger.NewHttpLogger(logger.GetLogger("git"), scmClient.Client.Transport) - if err != nil { - return nil, fmt.Errorf("failed to create git client with access token: %v", err) - } client := &GitAccessTokenClient{ service: service,