Skip to content

Commit

Permalink
OCDAV: map bad request and unimplemented codes
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Dec 2, 2020
1 parent 8b4cc17 commit 01ec606
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 29 deletions.
32 changes: 25 additions & 7 deletions internal/http/services/owncloud/ocdav/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) {
}
dst = path.Join(ns, dst)

log.Info().Str("source", src).Str("destination", dst).
log.Debug().Str("source", src).Str("destination", dst).
Str("overwrite", overwrite).Str("depth", depth).Msg("copy")

overwrite = strings.ToUpper(overwrite)
Expand Down Expand Up @@ -87,21 +87,27 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) {
srcStatReq := &provider.StatRequest{Ref: ref}
srcStatRes, err := client.Stat(ctx, srcStatReq)
if err != nil {
log.Error().Err(err).Msg("error sending grpc stat request")
log.Error().Err(err).Str("src", src).Str("dst", dst).Msg("error sending grpc stat request")
w.WriteHeader(http.StatusInternalServerError)
return
}

if srcStatRes.Status.Code != rpc.Code_CODE_OK {
switch srcStatRes.Status.Code {
case rpc.Code_CODE_NOT_FOUND:
log.Debug().Str("src", src).Interface("status", srcStatRes.Status).Msg("resource not found")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("resource not found")
w.WriteHeader(http.StatusNotFound)
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("src", src).Interface("status", srcStatRes.Status).Msg("permission denied")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("src", src).Interface("status", srcStatRes.Status).Msg("grpc stat request failed")
log.Error().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
}
return
Expand All @@ -121,10 +127,16 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) {
if dstStatRes.Status.Code != rpc.Code_CODE_OK && dstStatRes.Status.Code != rpc.Code_CODE_NOT_FOUND {
switch dstStatRes.Status.Code {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("dst", dst).Interface("status", dstStatRes.Status).Msg("permission denied")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("dst", dst).Interface("status", dstStatRes.Status).Msg("grpc stat request failed")
log.Error().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
}
return
Expand Down Expand Up @@ -161,6 +173,12 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("dst", dst).Interface("status", intStatRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("dst", dst).Interface("status", intStatRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("dst", dst).Interface("status", intStatRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("dst", dst).Interface("status", intStatRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
6 changes: 6 additions & 0 deletions internal/http/services/owncloud/ocdav/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func (s *svc) handleDelete(w http.ResponseWriter, r *http.Request, ns string) {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", res.Status).Msg("grpc delete request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
12 changes: 12 additions & 0 deletions internal/http/services/owncloud/ocdav/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func (s *svc) handleGet(w http.ResponseWriter, r *http.Request, ns string) {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", sRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", sRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", sRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", sRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -104,6 +110,12 @@ func (s *svc) handleGet(w http.ResponseWriter, r *http.Request, ns string) {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", dRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", dRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", dRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", dRes.Status).Msg("grpc initiate file download request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
6 changes: 6 additions & 0 deletions internal/http/services/owncloud/ocdav/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func (s *svc) handleHead(w http.ResponseWriter, r *http.Request, ns string) {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", res.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
12 changes: 12 additions & 0 deletions internal/http/services/owncloud/ocdav/mkcol.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func (s *svc) handleMkcol(w http.ResponseWriter, r *http.Request, ns string) {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", statRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", statRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", statRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", statRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -94,6 +100,12 @@ func (s *svc) handleMkcol(w http.ResponseWriter, r *http.Request, ns string) {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", statRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", statRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", statRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", statRes.Status).Msg("grpc create container request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
62 changes: 49 additions & 13 deletions internal/http/services/owncloud/ocdav/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
}
dst = path.Join(ns, dst)

log.Info().Str("src", src).Str("dst", dst).Str("overwrite", overwrite).Msg("move")
log.Debug().Str("src", src).Str("dst", dst).Str("overwrite", overwrite).Msg("move")

overwrite = strings.ToUpper(overwrite)
if overwrite == "" {
Expand Down Expand Up @@ -79,13 +79,19 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
if srcStatRes.Status.Code != rpc.Code_CODE_OK {
switch srcStatRes.Status.Code {
case rpc.Code_CODE_NOT_FOUND:
log.Debug().Str("src", src).Interface("status", srcStatRes.Status).Msg("resource not found")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("resource not found")
w.WriteHeader(http.StatusNotFound)
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("src", src).Interface("status", srcStatRes.Status).Msg("permission denied")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("src", src).Interface("status", srcStatRes.Status).Msg("grpc stat request failed")
log.Error().Str("src", src).Str("dst", dst).Interface("status", srcStatRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
}
return
Expand All @@ -105,10 +111,16 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
if dstStatRes.Status.Code != rpc.Code_CODE_OK && dstStatRes.Status.Code != rpc.Code_CODE_NOT_FOUND {
switch dstStatRes.Status.Code {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("dst", dst).Interface("status", dstStatRes.Status).Msg("permission denied")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("dst", dst).Interface("status", dstStatRes.Status).Msg("grpc stat request failed")
log.Error().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
}
return
Expand Down Expand Up @@ -136,10 +148,16 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
if delRes.Status.Code != rpc.Code_CODE_OK && delRes.Status.Code != rpc.Code_CODE_NOT_FOUND {
switch delRes.Status.Code {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("dst", dst).Interface("status", delRes.Status).Msg("permission denied")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", delRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", delRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", delRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("dst", dst).Interface("status", delRes.Status).Msg("grpc delete request failed")
log.Error().Str("src", src).Str("dst", dst).Interface("status", delRes.Status).Msg("grpc delete request failed")
w.WriteHeader(http.StatusInternalServerError)
}
return
Expand All @@ -163,10 +181,16 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
// 409 if intermediate dir is missing, see https://tools.ietf.org/html/rfc4918#section-9.8.5
w.WriteHeader(http.StatusConflict)
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("parent", intermediateDir).Interface("status", intStatRes.Status).Msg("permission denied")
log.Debug().Str("src", src).Str("dst", dst).Str("parent", intermediateDir).Interface("status", intStatRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("src", src).Str("dst", dst).Str("parent", intermediateDir).Interface("status", intStatRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("src", src).Str("dst", dst).Str("parent", intermediateDir).Interface("status", intStatRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("parent", intermediateDir).Interface("status", intStatRes.Status).Msg("grpc stat request failed")
log.Error().Str("src", src).Str("dst", dst).Str("parent", intermediateDir).Interface("status", intStatRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
}
return
Expand Down Expand Up @@ -196,6 +220,12 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", mRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", mRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", mRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("src", src).Str("dst", dst).Interface("status", mRes.Status).Msg("grpc move request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -213,13 +243,19 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
if dstStatRes.Status.Code != rpc.Code_CODE_OK {
switch dstStatRes.Status.Code {
case rpc.Code_CODE_NOT_FOUND:
log.Debug().Str("dst", dst).Interface("status", dstStatRes.Status).Msg("resource not found")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("resource not found")
w.WriteHeader(http.StatusNotFound)
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("dst", dst).Interface("status", dstStatRes.Status).Msg("permission denied")
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("dst", dst).Interface("status", dstStatRes.Status).Msg("grpc stat request failed")
log.Error().Str("src", src).Str("dst", dst).Interface("status", dstStatRes.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
}
return
Expand Down
18 changes: 18 additions & 0 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string)
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("permission denied")
w.WriteHeader(http.StatusMultiStatus)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", res.Status).Msg("grpc stat request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -124,6 +130,12 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string)
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", res.Status).Msg("grpc list container request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -158,6 +170,12 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string)
case rpc.Code_CODE_PERMISSION_DENIED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("permission denied")
w.WriteHeader(http.StatusForbidden)
case rpc.Code_CODE_INVALID_ARGUMENT:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("bad request")
w.WriteHeader(http.StatusBadRequest)
case rpc.Code_CODE_UNIMPLEMENTED:
log.Debug().Str("path", fn).Interface("status", res.Status).Msg("not implemented")
w.WriteHeader(http.StatusNotImplemented)
default:
log.Error().Str("path", fn).Interface("status", res.Status).Msg("grpc list container request failed")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
Loading

0 comments on commit 01ec606

Please sign in to comment.