func grpcServer()

in server/cmd/harp-server/internal/dispatchers/grpc/wire_gen.go [56:88]


func grpcServer(ctx context.Context, cfg *config.Configuration, bm manager.Backend) (*grpc.Server, error) {
	container.SetKeyring(cfg.Keyring)

	sopts := []grpc.ServerOption{}

	if cfg.GRPC.UseTLS {

		clientAuth := tls.VerifyClientCertIfGiven
		if cfg.GRPC.TLS.ClientAuthenticationRequired {
			clientAuth = tls.RequireAndVerifyClientCert
		}

		tlsConfig, err := tlsconfig.Server(&tlsconfig.Options{
			KeyFile:    cfg.GRPC.TLS.PrivateKeyPath,
			CertFile:   cfg.GRPC.TLS.CertificatePath,
			CAFile:     cfg.GRPC.TLS.CACertificatePath,
			ClientAuth: clientAuth,
		})
		if err != nil {
			log.For(ctx).Error("Unable to build TLS configuration from settings", zap.Error(err))
			return nil, err
		}

		sopts = append(sopts, grpc.Creds(credentials.NewTLS(tlsConfig)))
	} else {
		log.For(ctx).Info("No transport encryption enabled for gRPC server")
	}
	grpcServer2 := grpc.NewServer(sopts...)
	bundlev1.RegisterBundleAPIServer(grpcServer2, server.Bundle(bm))
	reflection.Register(grpcServer2)

	return grpcServer2, nil
}