From fdc926e70be4667ab506b02bff1b5d9d5ffeec05 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Mon, 22 Aug 2022 16:32:09 +0300 Subject: [PATCH] [#661] Fix updating cache when request fails Signed-off-by: Denis Kirillov --- api/errors/errors.go | 7 +++++++ api/handler/locking.go | 6 ++++-- api/handler/versioning.go | 10 ++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/api/errors/errors.go b/api/errors/errors.go index 5c807b165..d9c095806 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -122,6 +122,7 @@ const ( ErrInvalidBucketObjectLockConfiguration ErrObjectLockConfigurationNotFound ErrObjectLockConfigurationNotAllowed + ErrObjectLockConfigurationVersioningCannotBeChanged ErrNoSuchObjectLockConfiguration ErrObjectLocked ErrInvalidRetentionDate @@ -831,6 +832,12 @@ var errorCodes = errorCodeMap{ Description: "Object Lock configuration cannot be enabled on existing buckets", HTTPStatusCode: http.StatusConflict, }, + ErrObjectLockConfigurationVersioningCannotBeChanged: { + ErrCode: ErrObjectLockConfigurationVersioningCannotBeChanged, + Code: "InvalidBucketState", + Description: "An Object Lock configuration is present on this bucket, so the versioning state cannot be changed.", + HTTPStatusCode: http.StatusConflict, + }, ErrNoSuchCORSConfiguration: { ErrCode: ErrNoSuchCORSConfiguration, Code: "NoSuchCORSConfiguration", diff --git a/api/handler/locking.go b/api/handler/locking.go index 0bcff7afc..605e60a19 100644 --- a/api/handler/locking.go +++ b/api/handler/locking.go @@ -56,11 +56,13 @@ func (h *handler) PutBucketObjectLockConfigHandler(w http.ResponseWriter, r *htt return } - settings.LockConfiguration = lockingConf + // settings pointer is stored in the cache, so modify a copy of the settings + newSettings := *settings + newSettings.LockConfiguration = lockingConf sp := &layer.PutSettingsParams{ BktInfo: bktInfo, - Settings: settings, + Settings: &newSettings, } if err = h.obj.PutBucketSettings(r.Context(), sp); err != nil { diff --git a/api/handler/versioning.go b/api/handler/versioning.go index e4da70390..8d03480f2 100644 --- a/api/handler/versioning.go +++ b/api/handler/versioning.go @@ -2,7 +2,6 @@ package handler import ( "encoding/xml" - "fmt" "net/http" "github.com/nspcc-dev/neofs-s3-gw/api" @@ -37,15 +36,18 @@ func (h *handler) PutBucketVersioningHandler(w http.ResponseWriter, r *http.Requ h.logAndSendError(w, "invalid versioning configuration", reqInfo, errors.GetAPIError(errors.ErrMalformedXML)) return } - settings.Versioning = configuration.Status + + // settings pointer is stored in the cache, so modify a copy of the settings + newSettings := *settings + newSettings.Versioning = configuration.Status p := &layer.PutSettingsParams{ BktInfo: bktInfo, - Settings: settings, + Settings: &newSettings, } if p.Settings.VersioningSuspended() && bktInfo.ObjectLockEnabled { - h.logAndSendError(w, "couldn't suspend bucket versioning", reqInfo, fmt.Errorf("object lock is enabled")) + h.logAndSendError(w, "couldn't suspend bucket versioning", reqInfo, errors.GetAPIError(errors.ErrObjectLockConfigurationVersioningCannotBeChanged)) return }