fix: make the collaboration service events optional

This commit is contained in:
Florian Schade
2026-06-22 17:32:16 +02:00
parent 7c70c67e30
commit 435b446a6a
3 changed files with 18 additions and 10 deletions

View File

@@ -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(&notificationService))
}
// 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

View File

@@ -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
}

View File

@@ -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)
})
}
})
}