github.com/argoproj/argo-cd@v1.8.7/reposerver/server.go (about) 1 package reposerver 2 3 import ( 4 "crypto/tls" 5 "os" 6 7 grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" 8 grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" 9 grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" 10 log "github.com/sirupsen/logrus" 11 "google.golang.org/grpc" 12 "google.golang.org/grpc/credentials" 13 "google.golang.org/grpc/health" 14 "google.golang.org/grpc/health/grpc_health_v1" 15 "google.golang.org/grpc/reflection" 16 17 "github.com/argoproj/argo-cd/common" 18 versionpkg "github.com/argoproj/argo-cd/pkg/apiclient/version" 19 "github.com/argoproj/argo-cd/reposerver/apiclient" 20 reposervercache "github.com/argoproj/argo-cd/reposerver/cache" 21 "github.com/argoproj/argo-cd/reposerver/metrics" 22 "github.com/argoproj/argo-cd/reposerver/repository" 23 "github.com/argoproj/argo-cd/server/version" 24 grpc_util "github.com/argoproj/argo-cd/util/grpc" 25 tlsutil "github.com/argoproj/argo-cd/util/tls" 26 ) 27 28 // ArgoCDRepoServer is the repo server implementation 29 type ArgoCDRepoServer struct { 30 log *log.Entry 31 metricsServer *metrics.MetricsServer 32 cache *reposervercache.Cache 33 opts []grpc.ServerOption 34 initConstants repository.RepoServerInitConstants 35 } 36 37 // NewServer returns a new instance of the Argo CD Repo server 38 func NewServer(metricsServer *metrics.MetricsServer, cache *reposervercache.Cache, tlsConfCustomizer tlsutil.ConfigCustomizer, initConstants repository.RepoServerInitConstants) (*ArgoCDRepoServer, error) { 39 // generate TLS cert 40 hosts := []string{ 41 "localhost", 42 "argocd-repo-server", 43 } 44 cert, err := tlsutil.GenerateX509KeyPair(tlsutil.CertOptions{ 45 Hosts: hosts, 46 Organization: "Argo CD", 47 IsCA: true, 48 }) 49 if err != nil { 50 return nil, err 51 } 52 53 tlsConfig := &tls.Config{Certificates: []tls.Certificate{*cert}} 54 tlsConfCustomizer(tlsConfig) 55 56 if os.Getenv(common.EnvEnableGRPCTimeHistogramEnv) == "true" { 57 grpc_prometheus.EnableHandlingTimeHistogram() 58 } 59 60 serverLog := log.NewEntry(log.StandardLogger()) 61 streamInterceptors := []grpc.StreamServerInterceptor{grpc_logrus.StreamServerInterceptor(serverLog), grpc_prometheus.StreamServerInterceptor, grpc_util.PanicLoggerStreamServerInterceptor(serverLog)} 62 unaryInterceptors := []grpc.UnaryServerInterceptor{grpc_logrus.UnaryServerInterceptor(serverLog), grpc_prometheus.UnaryServerInterceptor, grpc_util.PanicLoggerUnaryServerInterceptor(serverLog)} 63 64 return &ArgoCDRepoServer{ 65 log: serverLog, 66 metricsServer: metricsServer, 67 cache: cache, 68 initConstants: initConstants, 69 opts: []grpc.ServerOption{ 70 grpc.Creds(credentials.NewTLS(tlsConfig)), 71 grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(unaryInterceptors...)), 72 grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(streamInterceptors...)), 73 grpc.MaxRecvMsgSize(apiclient.MaxGRPCMessageSize), 74 grpc.MaxSendMsgSize(apiclient.MaxGRPCMessageSize), 75 }, 76 }, nil 77 } 78 79 // CreateGRPC creates new configured grpc server 80 func (a *ArgoCDRepoServer) CreateGRPC() *grpc.Server { 81 server := grpc.NewServer(a.opts...) 82 versionpkg.RegisterVersionServiceServer(server, version.NewServer(nil, func() (bool, error) { 83 return true, nil 84 })) 85 manifestService := repository.NewService(a.metricsServer, a.cache, a.initConstants) 86 apiclient.RegisterRepoServerServiceServer(server, manifestService) 87 88 healthService := health.NewServer() 89 grpc_health_v1.RegisterHealthServer(server, healthService) 90 91 // Register reflection service on gRPC server. 92 reflection.Register(server) 93 94 return server 95 }