From 435b446a6a1b8cb41f23578b277c6a89e7a5a5cc Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Mon, 22 Jun 2026 17:32:16 +0200 Subject: [PATCH] fix: make the collaboration service events optional --- services/collaboration/pkg/command/server.go | 11 ++++++----- services/collaboration/pkg/server/http/option.go | 4 ++-- services/collaboration/pkg/server/http/server.go | 13 ++++++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/services/collaboration/pkg/command/server.go b/services/collaboration/pkg/command/server.go index 21c7654676..c1ff55b2bf 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/pkg/command/server.go @@ -12,7 +12,6 @@ import ( "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" "github.com/opencloud-eu/reva/v2/pkg/store" "github.com/spf13/afero" - "github.com/spf13/cobra" "go-micro.dev/v4/selector" microstore "go-micro.dev/v4/store" @@ -175,8 +174,9 @@ func Server(cfg *config.Config) *cobra.Command { } } + var optionalHTTPServerOptions []http.Option var notificationService notification.Service - { + if cfg.Events.Endpoint != "" { // notifications are optional connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus) natsStream, err := stream.NatsFromConfig(connName, true, stream.NatsConfig(cfg.Events)) if err != nil { @@ -192,10 +192,12 @@ func Server(cfg *config.Config) *cobra.Command { if err != nil { return err } + + optionalHTTPServerOptions = append(optionalHTTPServerOptions, http.NotificationService(¬ificationService)) } // start HTTP server - httpServer, err := http.Server( + httpServer, err := http.Server(append([]http.Option{ http.Adapter(connector.NewHttpAdapter(gatewaySelector, cfg, st, selector.NewSelector(selector.Registry(registry.GetRegistry())))), http.Logger(logger), http.Config(cfg), @@ -203,8 +205,7 @@ func Server(cfg *config.Config) *cobra.Command { http.TracerProvider(traceProvider), http.Store(st), http.FontService(fontService), - http.NotificationService(notificationService), - ) + }, optionalHTTPServerOptions...)...) if err != nil { logger.Info().Err(err).Str("transport", "http").Msg("Failed to initialize server") return err diff --git a/services/collaboration/pkg/server/http/option.go b/services/collaboration/pkg/server/http/option.go index de009249b4..a3335e6a3f 100644 --- a/services/collaboration/pkg/server/http/option.go +++ b/services/collaboration/pkg/server/http/option.go @@ -25,7 +25,7 @@ type Options struct { TracerProvider trace.TracerProvider Store microstore.Store FontService font.Service - NotificationService notification.Service + NotificationService *notification.Service } // newOptions initializes the available default options. @@ -89,7 +89,7 @@ func FontService(val font.Service) Option { } // NotificationService provides a function to set the NotificationService option -func NotificationService(val notification.Service) Option { +func NotificationService(val *notification.Service) Option { return func(o *Options) { o.NotificationService = val } diff --git a/services/collaboration/pkg/server/http/server.go b/services/collaboration/pkg/server/http/server.go index a2f4282c35..b234eb5e04 100644 --- a/services/collaboration/pkg/server/http/server.go +++ b/services/collaboration/pkg/server/http/server.go @@ -22,6 +22,10 @@ import ( func Server(opts ...Option) (http.Service, error) { options := newOptions(opts...) + if options.NotificationService == nil { + options.Logger.Warn().Msg("running without notification service: no notifications will be sent, set the events endpoint to enable them") + } + service, err := http.NewService( http.TLSConfig(options.Config.HTTP.TLS), http.Logger(options.Logger), @@ -219,9 +223,6 @@ func prepareRoutes(r *chi.Mux, options Options) { account.Logger(options.Logger), account.JWTSecret(options.Config.TokenManager.JWTSecret), ) - r.With(auth).Route("/notify", func(r chi.Router) { - r.Post("/", notificationService.HandleNotification) - }) r.Route("/fonts", func(r chi.Router) { r.Get("/", fontService.ListFonts) r.Get("/{id}", fontService.GetFont) @@ -231,5 +232,11 @@ func prepareRoutes(r *chi.Mux, options Options) { r.Delete("/{id}", fontService.DeleteFont) }) }) + + if notificationService != nil { // optional + r.With(auth).Route("/notify", func(r chi.Router) { + r.Post("/", notificationService.HandleNotification) + }) + } }) }