diff --git a/api/backup.go b/api/backup.go index 9452bf9acb..70ebda9e73 100644 --- a/api/backup.go +++ b/api/backup.go @@ -38,14 +38,23 @@ func (s *Server) BackupTargetGet(w http.ResponseWriter, req *http.Request) error func (s *Server) BackupTargetList(w http.ResponseWriter, req *http.Request) error { apiContext := api.GetApiContext(req) - backupTargets, err := s.m.ListBackupTargetsSorted() + bts, err := s.backupTargetList(apiContext) if err != nil { return errors.Wrap(err, "failed to list backup targets") } - apiContext.Write(toBackupTargetCollection(backupTargets, apiContext)) + + apiContext.Write(bts) return nil } +func (s *Server) backupTargetList(apiContext *api.ApiContext) (*client.GenericCollection, error) { + bts, err := s.m.ListBackupTargetsSorted() + if err != nil { + return nil, errors.Wrap(err, "failed to list backup target") + } + return toBackupTargetCollection(bts, apiContext), nil +} + func (s *Server) BackupTargetCreate(rw http.ResponseWriter, req *http.Request) error { var input BackupTarget apiContext := api.GetApiContext(req) diff --git a/api/router.go b/api/router.go index e5c7953a04..75b453ceae 100644 --- a/api/router.go +++ b/api/router.go @@ -259,6 +259,10 @@ func NewRouter(s *Server) *mux.Router { r.Path("/v1/ws/backupvolumes").Handler(f(schemas, backupVolumeStream)) r.Path("/v1/ws/{period}/backupvolumes").Handler(f(schemas, backupVolumeStream)) + backupTargetStream := NewStreamHandlerFunc("backuptargets", s.wsc.NewWatcher("backupTarget"), s.backupTargetList) + r.Path("/v1/ws/backuptargets").Handler(f(schemas, backupTargetStream)) + r.Path("/v1/ws/{period}/backuptargets").Handler(f(schemas, backupTargetStream)) + // TODO: // We haven't found a way to allow passing the volume name as a parameter to filter // per-backup volume's backups change thru. WebSocket endpoint. Either by: