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

     1  package apiclient
     2  
     3  import (
     4  	"fmt"
     5  	"math"
     6  
     7  	"github.com/argoproj/argo-cd/v3/common"
     8  	"github.com/argoproj/argo-cd/v3/util/env"
     9  
    10  	log "github.com/sirupsen/logrus"
    11  	"google.golang.org/grpc"
    12  	"google.golang.org/grpc/credentials/insecure"
    13  
    14  	utilio "github.com/argoproj/argo-cd/v3/util/io"
    15  )
    16  
    17  // MaxGRPCMessageSize contains max grpc message size
    18  var MaxGRPCMessageSize = env.ParseNumFromEnv(common.EnvGRPCMaxSizeMB, 100, 0, math.MaxInt32) * 1024 * 1024
    19  
    20  // Clientset represents commit server api clients
    21  type Clientset interface {
    22  	NewCommitServerClient() (utilio.Closer, CommitServiceClient, error)
    23  }
    24  
    25  type clientSet struct {
    26  	address string
    27  }
    28  
    29  // NewCommitServerClient creates new instance of commit server client
    30  func (c *clientSet) NewCommitServerClient() (utilio.Closer, CommitServiceClient, error) {
    31  	conn, err := NewConnection(c.address)
    32  	if err != nil {
    33  		return nil, nil, fmt.Errorf("failed to open a new connection to commit server: %w", err)
    34  	}
    35  	return conn, NewCommitServiceClient(conn), nil
    36  }
    37  
    38  // NewConnection creates new connection to commit server
    39  func NewConnection(address string) (*grpc.ClientConn, error) {
    40  	var opts []grpc.DialOption
    41  	opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
    42  
    43  	conn, err := grpc.NewClient(address, opts...)
    44  	if err != nil {
    45  		log.Errorf("Unable to connect to commit service with address %s", address)
    46  		return nil, err
    47  	}
    48  	return conn, nil
    49  }
    50  
    51  // NewCommitServerClientset creates new instance of commit server Clientset
    52  func NewCommitServerClientset(address string) Clientset {
    53  	return &clientSet{address: address}
    54  }