From 6e73ee7466ac19032e4a8dc05de81e56596326f2 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Sat, 11 Dec 2021 21:40:58 +0100 Subject: [PATCH] handle non existent spaces gracefully --- .../update-spaces-handle-non-existent.md | 5 ++++ go.mod | 2 ++ go.sum | 4 +-- graph/pkg/service/v0/drives.go | 27 ++++++++++++++++--- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/update-spaces-handle-non-existent.md diff --git a/changelog/unreleased/update-spaces-handle-non-existent.md b/changelog/unreleased/update-spaces-handle-non-existent.md new file mode 100644 index 0000000000..c69fbc8d25 --- /dev/null +++ b/changelog/unreleased/update-spaces-handle-non-existent.md @@ -0,0 +1,5 @@ +Change: Return not found when updating non existent space + +If a spaceid of a space which is updated doesn't exist, handle it as a not found error. + +https://github.com/cs3org/reva/pull/2869 diff --git a/go.mod b/go.mod index a2cd56ad20..350a659b41 100644 --- a/go.mod +++ b/go.mod @@ -241,3 +241,5 @@ require ( stash.kopano.io/kgol/kcc-go/v5 v5.0.1 // indirect stash.kopano.io/kgol/oidc-go v0.3.2 // indirect ) + +replace github.com/cs3org/reva => github.com/micbar/reva v1.9.1-0.20211211204557-ace6314aca5d diff --git a/go.sum b/go.sum index e8cb72438e..be2e4c97f3 100644 --- a/go.sum +++ b/go.sum @@ -299,8 +299,6 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304 h1:e/nIPR518vyvrulo9goAZTtYD6gFfu/2/9MDe6mTGcw= github.com/cs3org/go-cs3apis v0.0.0-20211104090126-8e972dca8304/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva v1.17.0 h1:UVdiiK6gUF2pb7qN9TKhMuf55sUKVnCcVjiVSzodluw= -github.com/cs3org/reva v1.17.0/go.mod h1:gtsVzMfDrUiUjH6qlHx+QqiRKsSYjVO6wEcCzANiqUg= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= @@ -884,6 +882,8 @@ github.com/mendsley/gojwk v0.0.0-20141217222730-4d5ec6e58103 h1:Z/i1e+gTZrmcGeZy github.com/mendsley/gojwk v0.0.0-20141217222730-4d5ec6e58103/go.mod h1:o9YPB5aGP8ob35Vy6+vyq3P3bWe7NQWzf+JLiXCiMaE= github.com/mennanov/fieldmask-utils v0.5.0 h1:8em4akN0NM3hmmrg8VbvOPfdS4SSBdbFd53m9VtfOg0= github.com/mennanov/fieldmask-utils v0.5.0/go.mod h1:lah2lHczE2ff+7SqnNKpB+YzaO7M3h5iNO4LgPTJheM= +github.com/micbar/reva v1.9.1-0.20211211204557-ace6314aca5d h1:YjTtmls7nPPIa/kAdzlebZlk8bf/E3gA13RophdAFbs= +github.com/micbar/reva v1.9.1-0.20211211204557-ace6314aca5d/go.mod h1:gtsVzMfDrUiUjH6qlHx+QqiRKsSYjVO6wEcCzANiqUg= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.40/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index b4ca4b85bf..7a75629463 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -240,7 +240,7 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) { newDrive, err := cs3StorageSpaceToDrive(wdu, resp.StorageSpace) if err != nil { - g.logger.Error().Err(err).Msg("error parsing url") + g.logger.Error().Err(err).Msg("error parsing space") errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) return } @@ -322,11 +322,32 @@ 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, resp.GetStatus().GetMessage()) + switch resp.Status.GetCode() { + case v1beta11.Code_CODE_NOT_FOUND: + errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, resp.GetStatus().GetMessage()) + return + default: + errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, resp.GetStatus().GetMessage()) + return + } + } + + wdu, err := url.Parse(g.config.Spaces.WebDavBase + g.config.Spaces.WebDavPath) + if err != nil { + g.logger.Error().Err(err).Msg("error parsing url") + errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) return } - w.WriteHeader(http.StatusNoContent) + updatedDrive, err := cs3StorageSpaceToDrive(wdu, resp.StorageSpace) + if err != nil { + g.logger.Error().Err(err).Msg("error parsing space") + errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) + return + } + + render.Status(r, http.StatusOK) + render.JSON(w, r, updatedDrive) } func cs3TimestampToTime(t *types.Timestamp) time.Time {