Skip to content

Commit

Permalink
fix: auth token isn't mandatory for all services
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 5, 2024
1 parent 87bc493 commit 5bcbf05
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pkg/clients/git/connectors/git_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package connectors

import (
"fmt"
netHTTP "net/http"
"os"

"github.com/flanksource/commons/logger"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5bcbf05

Please sign in to comment.