feat(server): emit notifications as JSON to stderr when running under KopiaUI (#4322)

* feat(server): emit notifications as JSON to stderr when running under KopiaUI

* added tests
This commit is contained in:
Jarek Kowalski
2024-12-30 15:06:11 -08:00
committed by GitHub
parent d6b9254a4c
commit ef01650665
7 changed files with 182 additions and 11 deletions

View File

@@ -21,6 +21,8 @@
"github.com/kopia/kopia/internal/auth"
"github.com/kopia/kopia/internal/server"
"github.com/kopia/kopia/notification"
"github.com/kopia/kopia/notification/sender/jsonsender"
"github.com/kopia/kopia/repo"
)
@@ -68,7 +70,8 @@ type commandServerStart struct {
debugScheduler bool
minMaintenanceInterval time.Duration
shutdownGracePeriod time.Duration
shutdownGracePeriod time.Duration
kopiauiNotifications bool
logServerRequests bool
@@ -123,6 +126,8 @@ func (c *commandServerStart) setup(svc advancedAppServices, parent commandParent
cmd.Flag("shutdown-grace-period", "Grace period for shutting down the server").Default("5s").DurationVar(&c.shutdownGracePeriod)
cmd.Flag("kopiaui-notifications", "Enable notifications to be printed to stdout for KopiaUI").BoolVar(&c.kopiauiNotifications)
c.sf.setup(svc, cmd)
c.co.setup(svc, cmd)
c.svc = svc
@@ -271,6 +276,15 @@ func (c *commandServerStart) run(ctx context.Context) (reterr error) {
onExternalConfigReloadRequest(srv.Refresh)
// enable notification to be printed to stderr where KopiaUI will pick it up
if c.kopiauiNotifications {
notification.AdditionalSenders = append(notification.AdditionalSenders,
jsonsender.NewJSONSender(
"NOTIFICATION: ",
c.out.stderr(),
notification.SeverityVerbose))
}
return c.startServerWithOptionalTLS(ctx, httpServer)
}