diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index aa370cbdf..b4ca4b85b 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -12,7 +12,6 @@ import ( "strings" "time" - "github.com/CiscoM31/godata" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" cs3rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" @@ -21,6 +20,7 @@ import ( storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" ctxpkg "github.com/cs3org/reva/pkg/ctx" + "github.com/go-chi/chi/v5" "github.com/go-chi/render" "github.com/owncloud/ocis/graph/pkg/service/v0/errorcode" "github.com/owncloud/ocis/ocis-pkg/service/grpc" @@ -249,22 +249,14 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { } func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { - // wildcards however addressed here is not yet supported. We want to address drives by their unique - // identifiers. Any open queries need to be implemented. Same applies for sub-entities. - // For further reading: http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_AddressingaSubsetofaCollection - - // strip "/graph/v1.0/" out and parse the rest. This is how godata input is expected. - //https://github.com/CiscoM31/godata/blob/d70e191d2908191623be84401fecc40d6af4afde/url_parser_test.go#L10 - sanitized := strings.TrimPrefix(r.URL.Path, "/graph/v1.0/") - - req, err := godata.ParseRequest(r.Context(), sanitized, r.URL.Query()) + driveID := chi.URLParam(r, "driveID") + driveID, err := url.PathUnescape(driveID) if err != nil { - errorcode.GeneralException.Render(w, r, http.StatusBadRequest, err.Error()) - return + errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "unescaping drive id failed") } - if req.FirstSegment.Identifier.Get() == "" { - errorcode.GeneralException.Render(w, r, http.StatusBadRequest, "identifier cannot be empty") + if driveID == "" { + errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "missing drive id") return } @@ -274,9 +266,9 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { return } - identifierParts := strings.Split(req.FirstSegment.Identifier.Get(), "!") + identifierParts := strings.Split(driveID, "!") if len(identifierParts) != 2 { - errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid resource id: %v", req.FirstSegment.Identifier.Get())) + errorcode.GeneralException.Render(w, r, http.StatusBadRequest, fmt.Sprintf("invalid resource id: %v", driveID)) w.WriteHeader(http.StatusInternalServerError) return } @@ -294,7 +286,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { // the original storage space. StorageSpace: &provider.StorageSpace{ Id: &storageprovider.StorageSpaceId{ - OpaqueId: req.FirstSegment.Identifier.Get(), + OpaqueId: driveID, }, Root: &provider.ResourceId{ StorageId: storageID, @@ -330,7 +322,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) { } if resp.GetStatus().GetCode() != v1beta11.Code_CODE_OK { - errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "") + errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, resp.GetStatus().GetMessage()) return } diff --git a/graph/pkg/service/v0/service.go b/graph/pkg/service/v0/service.go index e722d160b..36d0cf451 100644 --- a/graph/pkg/service/v0/service.go +++ b/graph/pkg/service/v0/service.go @@ -85,9 +85,9 @@ func NewService(opts ...Option) Service { r.Route("/drives", func(r chi.Router) { r.Get("/", svc.GetDrives) r.Post("/", svc.CreateDrive) - }) - r.Route("/Drive({firstSegmentIdentifier})", func(r chi.Router) { - r.Patch("/*", svc.UpdateDrive) + r.Route("/{driveID}", func(r chi.Router) { + r.Patch("/", svc.UpdateDrive) + }) }) }) })