cmd/serve/restic: add append-only mode
This commit is contained in:
parent
a8267d1628
commit
2c2bb0f750
1 changed files with 13 additions and 1 deletions
|
@ -31,11 +31,13 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
stdio bool
|
stdio bool
|
||||||
|
appendOnly bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
httpflags.AddFlags(Command.Flags())
|
httpflags.AddFlags(Command.Flags())
|
||||||
Command.Flags().BoolVar(&stdio, "stdio", false, "run an HTTP2 server on stdin/stdout")
|
Command.Flags().BoolVar(&stdio, "stdio", false, "run an HTTP2 server on stdin/stdout")
|
||||||
|
Command.Flags().BoolVar(&appendOnly, "append-only", false, "disallow deletion of repository data")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command definition for cobra
|
// Command definition for cobra
|
||||||
|
@ -355,6 +357,16 @@ func (s *server) postObject(w http.ResponseWriter, r *http.Request, remote strin
|
||||||
|
|
||||||
// delete the remote
|
// delete the remote
|
||||||
func (s *server) deleteObject(w http.ResponseWriter, r *http.Request, remote string) {
|
func (s *server) deleteObject(w http.ResponseWriter, r *http.Request, remote string) {
|
||||||
|
if appendOnly {
|
||||||
|
parts := strings.Split(r.URL.Path, "/")
|
||||||
|
|
||||||
|
// if path doesn't end in "/locks/:name", disallow the operation
|
||||||
|
if len(parts) < 2 || parts[len(parts)-2] != "locks" {
|
||||||
|
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
o, err := s.f.NewObject(remote)
|
o, err := s.f.NewObject(remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debugf(remote, "Delete request error: %v", err)
|
fs.Debugf(remote, "Delete request error: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue