mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
ae7e2764e0
* Adding ability to override directory permissions for db backup * adding new flag to usage.go * Backup now has its own directory handling method to reduce footprint of prospective change * removing unneeded test * fixing build error * switching to url param for override * stripping flag * adding in unit tests * fixing a test * minor changes for testing Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
37 lines
1001 B
Go
37 lines
1001 B
Go
package backuputil
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// BackupExporter defines a backup exporter methods.
|
|
type BackupExporter interface {
|
|
Backup(ctx context.Context, outputPath string, permissionOverride bool) 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, r *http.Request) {
|
|
log.Debug("Creating database backup from HTTP webhook")
|
|
|
|
_, permissionOverride := r.URL.Query()["permissionOverride"]
|
|
|
|
if err := bk.Backup(context.Background(), outputDir, permissionOverride); 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")
|
|
}
|
|
}
|
|
}
|