github.com/argoproj/argo-cd/v3@v3.2.1/commitserver/commit/repo_client_factory.go (about)

     1  package commit
     2  
     3  import (
     4  	"github.com/argoproj/argo-cd/v3/commitserver/metrics"
     5  	"github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
     6  	"github.com/argoproj/argo-cd/v3/util/git"
     7  )
     8  
     9  // RepoClientFactory is a factory for creating git clients for a repository.
    10  type RepoClientFactory interface {
    11  	NewClient(repo *v1alpha1.Repository, rootPath string) (git.Client, error)
    12  }
    13  
    14  type repoClientFactory struct {
    15  	gitCredsStore git.CredsStore
    16  	metricsServer *metrics.Server
    17  }
    18  
    19  // NewRepoClientFactory returns a new instance of the repo client factory.
    20  func NewRepoClientFactory(gitCredsStore git.CredsStore, metricsServer *metrics.Server) RepoClientFactory {
    21  	return &repoClientFactory{
    22  		gitCredsStore: gitCredsStore,
    23  		metricsServer: metricsServer,
    24  	}
    25  }
    26  
    27  // NewClient creates a new git client for the repository.
    28  func (r *repoClientFactory) NewClient(repo *v1alpha1.Repository, rootPath string) (git.Client, error) {
    29  	gitCreds := repo.GetGitCreds(r.gitCredsStore)
    30  	opts := git.WithEventHandlers(metrics.NewGitClientEventHandlers(r.metricsServer))
    31  	return git.NewClientExt(repo.Repo, rootPath, gitCreds, repo.IsInsecure(), repo.IsLFSEnabled(), repo.Proxy, repo.NoProxy, opts)
    32  }