From 6a5e21eff4da92c14a5e4cd8de375499ff0d5577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sw=C3=A4rd?= Date: Mon, 31 Jul 2023 12:57:59 +0200 Subject: [PATCH] Replacing implicit grpc client initialization with explicit package local variables. --- ocis-pkg/service/grpc/client.go | 60 ------------------- ocis-pkg/service/grpc/service.go | 5 -- ocis/pkg/command/server.go | 5 -- services/eventhistory/pkg/command/server.go | 3 +- services/eventhistory/pkg/config/config.go | 2 + .../eventhistory/pkg/server/grpc/server.go | 4 +- services/graph/pkg/command/server.go | 14 ----- .../graph/pkg/service/v0/application_test.go | 2 - .../pkg/service/v0/approleassignments_test.go | 2 - .../graph/pkg/service/v0/driveitems_test.go | 2 - .../pkg/service/v0/educationclasses_test.go | 2 - .../pkg/service/v0/educationschools_test.go | 2 - .../pkg/service/v0/educationuser_test.go | 2 - services/graph/pkg/service/v0/groups_test.go | 2 - services/graph/pkg/service/v0/users_test.go | 3 - .../notifications/pkg/service/service_test.go | 3 - services/policies/pkg/command/server.go | 5 +- services/search/pkg/command/server.go | 7 +++ services/search/pkg/config/config.go | 4 +- services/search/pkg/server/grpc/server.go | 3 +- services/settings/pkg/command/server.go | 2 +- services/settings/pkg/config/config.go | 2 + services/settings/pkg/server/grpc/server.go | 3 +- services/store/pkg/command/server.go | 4 +- services/store/pkg/config/config.go | 2 + services/store/pkg/server/grpc/server.go | 3 +- 26 files changed, 33 insertions(+), 115 deletions(-) diff --git a/ocis-pkg/service/grpc/client.go b/ocis-pkg/service/grpc/client.go index 61690e166..f8e857882 100644 --- a/ocis-pkg/service/grpc/client.go +++ b/ocis-pkg/service/grpc/client.go @@ -5,7 +5,6 @@ import ( "crypto/x509" "errors" "os" - "sync" mgrpcc "github.com/go-micro/plugins/v4/client/grpc" mbreaker "github.com/go-micro/plugins/v4/wrapper/breaker/gobreaker" @@ -16,11 +15,6 @@ import ( "go.opentelemetry.io/otel/trace" ) -var ( - defaultClient client.Client - once sync.Once -) - // ClientOptions represent options (e.g. tls settings) for the grpc clients type ClientOptions struct { tlsMode string @@ -56,60 +50,6 @@ func WithTraceProvider(tp trace.TracerProvider) ClientOption { } } -// Configure configures the default oOCIS grpc client (e.g. TLS settings) -func Configure(opts ...ClientOption) error { - var options ClientOptions - for _, opt := range opts { - opt(&options) - } - var outerr error - once.Do(func() { - reg := registry.GetRegistry() - var tlsConfig *tls.Config - cOpts := []client.Option{ - client.Registry(reg), - client.Wrap(mbreaker.NewClientWrapper()), - client.Wrap(mtracer.NewClientWrapper( - mtracer.WithTraceProvider(options.tp), - )), - } - switch options.tlsMode { - case "insecure": - tlsConfig = &tls.Config{ - InsecureSkipVerify: true, - } - cOpts = append(cOpts, mgrpcc.AuthTLS(tlsConfig)) - case "on": - tlsConfig = &tls.Config{} - // Note: If caCert is empty we use the system's default set of trusted CAs - if options.caCert != "" { - certs := x509.NewCertPool() - pemData, err := os.ReadFile(options.caCert) - if err != nil { - outerr = err - return - } - if !certs.AppendCertsFromPEM(pemData) { - outerr = errors.New("could not initialize default client, adding CA cert failed") - return - } - tlsConfig.RootCAs = certs - } - cOpts = append(cOpts, mgrpcc.AuthTLS(tlsConfig)) - // case "off": - // default: - } - - defaultClient = mgrpcc.NewClient(cOpts...) - }) - return outerr -} - -// DefaultClient returns a custom oCIS grpc configured client. -func DefaultClient() client.Client { - return defaultClient -} - func GetClientOptions(t *shared.GRPCClientTLS) []ClientOption { opts := []ClientOption{ WithTLSMode(t.Mode), diff --git a/ocis-pkg/service/grpc/service.go b/ocis-pkg/service/grpc/service.go index 730d161e2..5da803167 100644 --- a/ocis-pkg/service/grpc/service.go +++ b/ocis-pkg/service/grpc/service.go @@ -21,11 +21,6 @@ type Service struct { micro.Service } -// NewService initializes a new grpc service. -func NewService(opts ...Option) (Service, error) { - return NewServiceWithClient(DefaultClient(), opts...) -} - // NewServiceWithClient initializes a new grpc service with explicit client. func NewServiceWithClient(client client.Client, opts ...Option) (Service, error) { var mServer server.Server diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index 25057f58a..60d450cf9 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -5,7 +5,6 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/config/parser" "github.com/owncloud/ocis/v2/ocis-pkg/registry" - "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis/pkg/register" "github.com/owncloud/ocis/v2/ocis/pkg/runtime" "github.com/urfave/cli/v2" @@ -23,10 +22,6 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { // Prefer the in-memory registry as the default when running in single-binary mode registry.Configure("memory") - err := grpc.Configure(grpc.GetClientOptions(cfg.GRPCClientTLS)...) - if err != nil { - return err - } r := runtime.New(cfg) return r.Start() }, diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index 655a2cd8e..cee95fd4a 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -37,7 +37,8 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - err = ogrpc.Configure( + + cfg.GrpcClient, err = ogrpc.NewClient( append(ogrpc.GetClientOptions(cfg.GRPCClientTLS), ogrpc.WithTraceProvider(traceProvider))..., ) if err != nil { diff --git a/services/eventhistory/pkg/config/config.go b/services/eventhistory/pkg/config/config.go index 68c18a993..46bd91dcb 100644 --- a/services/eventhistory/pkg/config/config.go +++ b/services/eventhistory/pkg/config/config.go @@ -5,6 +5,7 @@ import ( "time" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "go-micro.dev/v4/client" ) // Config combines all available configuration parts. @@ -19,6 +20,7 @@ type Config struct { GRPC GRPCConfig `yaml:"grpc"` GRPCClientTLS *shared.GRPCClientTLS `yaml:"grpc_client_tls"` + GrpcClient client.Client `yaml:"-"` Events Events `yaml:"events"` Store Store `yaml:"store"` diff --git a/services/eventhistory/pkg/server/grpc/server.go b/services/eventhistory/pkg/server/grpc/server.go index f7b346752..033eb1dc2 100644 --- a/services/eventhistory/pkg/server/grpc/server.go +++ b/services/eventhistory/pkg/server/grpc/server.go @@ -11,7 +11,8 @@ import ( func NewService(opts ...Option) grpc.Service { options := newOptions(opts...) - service, err := grpc.NewService( + service, err := grpc.NewServiceWithClient( + options.Config.GrpcClient, grpc.TLSEnabled(options.Config.GRPC.TLS.Enabled), grpc.TLSCert( options.Config.GRPC.TLS.Cert, @@ -25,7 +26,6 @@ func NewService(opts ...Option) grpc.Service { grpc.Context(options.Context), grpc.Flags(options.Flags...), grpc.Version(version.GetString()), - grpc.TraceProvider(options.TraceProvider), ) if err != nil { options.Logger.Fatal().Err(err).Msg("Error creating event history service") diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index 0372eef47..8fa889993 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -6,8 +6,6 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" - "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/graph/pkg/config" "github.com/owncloud/ocis/v2/services/graph/pkg/config/parser" @@ -29,18 +27,6 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) - traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) - if err != nil { - return err - } - err = ogrpc.Configure( - append( - ogrpc.GetClientOptions(cfg.GRPCClientTLS), - ogrpc.WithTraceProvider(traceProvider), - )...) - if err != nil { - return err - } gr := run.Group{} ctx, cancel := func() (context.Context, context.CancelFunc) { diff --git a/services/graph/pkg/service/v0/application_test.go b/services/graph/pkg/service/v0/application_test.go index dc136709c..d46f10900 100644 --- a/services/graph/pkg/service/v0/application_test.go +++ b/services/graph/pkg/service/v0/application_test.go @@ -14,7 +14,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0" settings "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" @@ -71,7 +70,6 @@ var _ = Describe("Applications", func() { cfg.GRPCClientTLS = &shared.GRPCClientTLS{} cfg.Application.ID = "some-application-ID" - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) svc, _ = service.NewService( service.Config(cfg), service.WithGatewaySelector(gatewaySelector), diff --git a/services/graph/pkg/service/v0/approleassignments_test.go b/services/graph/pkg/service/v0/approleassignments_test.go index 7315df703..c262d6f85 100644 --- a/services/graph/pkg/service/v0/approleassignments_test.go +++ b/services/graph/pkg/service/v0/approleassignments_test.go @@ -18,7 +18,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0" settings "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" @@ -81,7 +80,6 @@ var _ = Describe("AppRoleAssignments", func() { cfg.GRPCClientTLS = &shared.GRPCClientTLS{} cfg.Application.ID = "some-application-ID" - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) svc, _ = service.NewService( service.Config(cfg), service.WithGatewaySelector(gatewaySelector), diff --git a/services/graph/pkg/service/v0/driveitems_test.go b/services/graph/pkg/service/v0/driveitems_test.go index c907ec670..6e6b5ccd0 100644 --- a/services/graph/pkg/service/v0/driveitems_test.go +++ b/services/graph/pkg/service/v0/driveitems_test.go @@ -17,7 +17,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" "github.com/owncloud/ocis/v2/services/graph/mocks" "github.com/owncloud/ocis/v2/services/graph/pkg/config" @@ -76,7 +75,6 @@ var _ = Describe("Driveitems", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) svc, _ = service.NewService( service.Config(cfg), service.WithGatewaySelector(gatewaySelector), diff --git a/services/graph/pkg/service/v0/educationclasses_test.go b/services/graph/pkg/service/v0/educationclasses_test.go index 530d31d6b..586813127 100644 --- a/services/graph/pkg/service/v0/educationclasses_test.go +++ b/services/graph/pkg/service/v0/educationclasses_test.go @@ -19,7 +19,6 @@ import ( . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" "github.com/owncloud/ocis/v2/ocis-pkg/log" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" "github.com/owncloud/ocis/v2/services/graph/mocks" "github.com/owncloud/ocis/v2/services/graph/pkg/config" @@ -80,7 +79,6 @@ var _ = Describe("EducationClass", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) svc, _ = service.NewService( service.Config(cfg), service.WithGatewaySelector(gatewaySelector), diff --git a/services/graph/pkg/service/v0/educationschools_test.go b/services/graph/pkg/service/v0/educationschools_test.go index a4424c9b4..798a56510 100644 --- a/services/graph/pkg/service/v0/educationschools_test.go +++ b/services/graph/pkg/service/v0/educationschools_test.go @@ -22,7 +22,6 @@ import ( "google.golang.org/grpc" libregraph "github.com/owncloud/libre-graph-api-go" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" "github.com/owncloud/ocis/v2/services/graph/pkg/config" "github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults" @@ -79,7 +78,6 @@ var _ = Describe("Schools", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) svc, _ = service.NewService( service.Config(cfg), service.WithGatewaySelector(gatewaySelector), diff --git a/services/graph/pkg/service/v0/educationuser_test.go b/services/graph/pkg/service/v0/educationuser_test.go index 80e5ed41d..5158c088d 100644 --- a/services/graph/pkg/service/v0/educationuser_test.go +++ b/services/graph/pkg/service/v0/educationuser_test.go @@ -20,7 +20,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" "github.com/owncloud/ocis/v2/services/graph/mocks" @@ -81,7 +80,6 @@ var _ = Describe("EducationUsers", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) svc, _ = service.NewService( service.Config(cfg), service.WithGatewaySelector(gatewaySelector), diff --git a/services/graph/pkg/service/v0/groups_test.go b/services/graph/pkg/service/v0/groups_test.go index b1dee30a4..79d52c836 100644 --- a/services/graph/pkg/service/v0/groups_test.go +++ b/services/graph/pkg/service/v0/groups_test.go @@ -18,7 +18,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" "github.com/owncloud/ocis/v2/services/graph/mocks" "github.com/owncloud/ocis/v2/services/graph/pkg/config" @@ -81,7 +80,6 @@ var _ = Describe("Groups", func() { cfg.Commons = &shared.Commons{} cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) svc, _ = service.NewService( service.Config(cfg), service.WithGatewaySelector(gatewaySelector), diff --git a/services/graph/pkg/service/v0/users_test.go b/services/graph/pkg/service/v0/users_test.go index 38ee84349..8e67a5152 100644 --- a/services/graph/pkg/service/v0/users_test.go +++ b/services/graph/pkg/service/v0/users_test.go @@ -21,7 +21,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" libregraph "github.com/owncloud/libre-graph-api-go" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0" settings "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" @@ -85,7 +84,6 @@ var _ = Describe("Users", func() { cfg.GRPCClientTLS = &shared.GRPCClientTLS{} cfg.Application.ID = "some-application-ID" - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) svc, _ = service.NewService( service.Config(cfg), service.WithGatewaySelector(gatewaySelector), @@ -690,7 +688,6 @@ var _ = Describe("Users", func() { localCfg.API.UsernameMatch = usernameMatch - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) localSvc, _ := service.NewService( service.Config(localCfg), service.WithGatewaySelector(gatewaySelector), diff --git a/services/notifications/pkg/service/service_test.go b/services/notifications/pkg/service/service_test.go index 28b37068c..6b95c7414 100644 --- a/services/notifications/pkg/service/service_test.go +++ b/services/notifications/pkg/service/service_test.go @@ -15,7 +15,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/owncloud/ocis/v2/ocis-pkg/log" - ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/shared" settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" "github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults" @@ -77,7 +76,6 @@ var _ = Describe("Notifications", func() { func(tc testChannel, ev events.Event) { cfg := defaults.FullDefaultConfig() cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) ch := make(chan events.Event) evts := service.NewEventsNotifier(ch, tc, log.NewLogger(), gatewaySelector, vs, "", "", "") go evts.Run() @@ -276,7 +274,6 @@ var _ = Describe("Notifications X-Site Scripting", func() { func(tc testChannel, ev events.Event) { cfg := defaults.FullDefaultConfig() cfg.GRPCClientTLS = &shared.GRPCClientTLS{} - _ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) ch := make(chan events.Event) evts := service.NewEventsNotifier(ch, tc, log.NewLogger(), gatewaySelector, vs, "", "", "") go evts.Run() diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index bf23e97ed..f9951118b 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -61,12 +61,13 @@ func Server(cfg *config.Config) *cli.Command { } { - err = grpc.Configure(grpc.GetClientOptions(cfg.GRPCClientTLS)...) + grpcClient, err := grpc.NewClient(grpc.GetClientOptions(cfg.GRPCClientTLS)...) if err != nil { return err } - svc, err := grpc.NewService( + svc, err := grpc.NewServiceWithClient( + grpcClient, grpc.Logger(logger), grpc.TLSEnabled(cfg.GRPC.TLS.Enabled), grpc.TLSCert( diff --git a/services/search/pkg/command/server.go b/services/search/pkg/command/server.go index ed99aa144..4983ab9a8 100644 --- a/services/search/pkg/command/server.go +++ b/services/search/pkg/command/server.go @@ -6,6 +6,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" + ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/search/pkg/config" @@ -33,6 +34,12 @@ func Server(cfg *config.Config) *cli.Command { return err } + cfg.GrpcClient, err = ogrpc.NewClient( + append(ogrpc.GetClientOptions(cfg.GRPCClientTLS), ogrpc.WithTraceProvider(traceProvider))..., + ) + if err != nil { + return err + } gr := run.Group{} ctx, cancel := func() (context.Context, context.CancelFunc) { if cfg.Context == nil { diff --git a/services/search/pkg/config/config.go b/services/search/pkg/config/config.go index ab164fe0c..9b66cd808 100644 --- a/services/search/pkg/config/config.go +++ b/services/search/pkg/config/config.go @@ -4,6 +4,7 @@ import ( "context" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "go-micro.dev/v4/client" ) // Config combines all available configuration parts. @@ -16,7 +17,8 @@ type Config struct { Log *Log `yaml:"log"` Debug Debug `yaml:"debug"` - GRPC GRPCConfig `yaml:"grpc"` + GRPC GRPCConfig `yaml:"grpc"` + GrpcClient client.Client `yaml:"-"` TokenManager *TokenManager `yaml:"token_manager"` diff --git a/services/search/pkg/server/grpc/server.go b/services/search/pkg/server/grpc/server.go index d47b0d19d..c193da94f 100644 --- a/services/search/pkg/server/grpc/server.go +++ b/services/search/pkg/server/grpc/server.go @@ -11,7 +11,8 @@ import ( func Server(opts ...Option) (grpc.Service, func(), error) { options := newOptions(opts...) - service, err := grpc.NewService( + service, err := grpc.NewServiceWithClient( + options.Config.GrpcClient, grpc.TLSEnabled(options.Config.GRPC.TLS.Enabled), grpc.TLSCert( options.Config.GRPC.TLS.Cert, diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index 1f60f59da..d252f822c 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -35,7 +35,7 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - err = ogrpc.Configure( + cfg.GrpcClient, err = ogrpc.NewClient( append(ogrpc.GetClientOptions(cfg.GRPCClientTLS), ogrpc.WithTraceProvider(tracingProvider))..., ) if err != nil { diff --git a/services/settings/pkg/config/config.go b/services/settings/pkg/config/config.go index 021cae3d6..e606b1865 100644 --- a/services/settings/pkg/config/config.go +++ b/services/settings/pkg/config/config.go @@ -6,6 +6,7 @@ import ( "github.com/owncloud/ocis/v2/ocis-pkg/shared" settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0" + "go-micro.dev/v4/client" ) // Config combines all available configuration parts. @@ -22,6 +23,7 @@ type Config struct { GRPC GRPCConfig `yaml:"grpc"` GRPCClientTLS *shared.GRPCClientTLS `yaml:"grpc_client_tls"` + GrpcClient client.Client `yaml:"-"` StoreType string `yaml:"store_type" env:"SETTINGS_STORE_TYPE" desc:"Store type configures the persistency driver. Supported values are 'metadata' and 'filesystem'. Note that the value 'filesystem' is considered deprecated."` DataPath string `yaml:"data_path" env:"SETTINGS_DATA_PATH" desc:"The directory where the filesystem storage will store ocis settings. If not defined, the root directory derives from $OCIS_BASE_DATA_PATH:/settings."` diff --git a/services/settings/pkg/server/grpc/server.go b/services/settings/pkg/server/grpc/server.go index dd4e5cdae..7a98ee77a 100644 --- a/services/settings/pkg/server/grpc/server.go +++ b/services/settings/pkg/server/grpc/server.go @@ -15,7 +15,8 @@ import ( func Server(opts ...Option) grpc.Service { options := newOptions(opts...) - service, err := grpc.NewService( + service, err := grpc.NewServiceWithClient( + options.Config.GrpcClient, grpc.TLSEnabled(options.Config.GRPC.TLS.Enabled), grpc.TLSCert( options.Config.GRPC.TLS.Cert, diff --git a/services/store/pkg/command/server.go b/services/store/pkg/command/server.go index bf8da8f46..f02765a6b 100644 --- a/services/store/pkg/command/server.go +++ b/services/store/pkg/command/server.go @@ -34,7 +34,9 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - err = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...) + cfg.GrpcClient, err = ogrpc.NewClient( + ogrpc.GetClientOptions(cfg.GRPCClientTLS)..., + ) if err != nil { return err } diff --git a/services/store/pkg/config/config.go b/services/store/pkg/config/config.go index b485ea21f..b6f5013c7 100644 --- a/services/store/pkg/config/config.go +++ b/services/store/pkg/config/config.go @@ -4,6 +4,7 @@ import ( "context" "github.com/owncloud/ocis/v2/ocis-pkg/shared" + "go-micro.dev/v4/client" ) // Config combines all available configuration parts. @@ -19,6 +20,7 @@ type Config struct { GRPC GRPCConfig `yaml:"grpc"` GRPCClientTLS *shared.GRPCClientTLS `yaml:"grpc_client_tls"` + GrpcClient client.Client `yaml:"-"` Datapath string `yaml:"data_path" env:"STORE_DATA_PATH" desc:"The directory where the filesystem storage will store ocis settings. If not defined, the root directory derives from $OCIS_BASE_DATA_PATH:/store."` diff --git a/services/store/pkg/server/grpc/server.go b/services/store/pkg/server/grpc/server.go index 73783385e..8e9c037fc 100644 --- a/services/store/pkg/server/grpc/server.go +++ b/services/store/pkg/server/grpc/server.go @@ -11,7 +11,8 @@ import ( func Server(opts ...Option) grpc.Service { options := newOptions(opts...) - service, err := grpc.NewService( + service, err := grpc.NewServiceWithClient( + options.Config.GrpcClient, grpc.TLSEnabled(options.Config.GRPC.TLS.Enabled), grpc.TLSCert( options.Config.GRPC.TLS.Cert,