prysm-pulse/shared/backuputil/http_backup_handler.go
Raul Jordan 14e1f08208
Add Backup Webhooks to All Prysm Services With DBs (#8025)
* integrate backup webhooks

* pass slasher tests

* fix node

* cmd

* gaz

* read test passes

* radek feedback

* added comment

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
2020-12-03 22:28:57 +00:00

34 lines
839 B
Go

package backuputil
import (
"context"
"fmt"
"net/http"
"github.com/sirupsen/logrus"
)
type BackupExporter interface {
Backup(ctx context.Context, outputPath string) error
}
// BackupHandler for accepting requests to initiate a new database backup.
func BackupHandler(bk BackupExporter, outputDir string) func(http.ResponseWriter, *http.Request) {
log := logrus.WithField("prefix", "db")
return func(w http.ResponseWriter, _ *http.Request) {
log.Debug("Creating database backup from HTTP webhook")
if err := bk.Backup(context.Background(), outputDir); err != nil {
log.WithError(err).Error("Failed to create backup")
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, "OK")
if err != nil {
log.WithError(err).Error("Failed to write OK")
}
}
}