Marina Biryukova
298662df9d
All checks were successful
/ Vulncheck (pull_request) Successful in 1m38s
/ Lint (pull_request) Successful in 2m49s
/ Tests (1.20) (pull_request) Successful in 1m56s
/ Tests (1.21) (pull_request) Successful in 1m44s
/ DCO (pull_request) Successful in 3m56s
/ Builds (1.20) (pull_request) Successful in 6m25s
/ Builds (1.21) (pull_request) Successful in 1m36s
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
85 lines
2.7 KiB
Go
85 lines
2.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
|
)
|
|
|
|
func (h *handler) PutBucketVersioningHandler(w http.ResponseWriter, r *http.Request) {
|
|
reqInfo := middleware.GetReqInfo(r.Context())
|
|
|
|
configuration := new(VersioningConfiguration)
|
|
if err := h.cfg.NewXMLDecoder(r.Body).Decode(configuration); err != nil {
|
|
h.logAndSendError(w, "couldn't decode versioning configuration", reqInfo, errors.GetAPIError(errors.ErrIllegalVersioningConfigurationException))
|
|
return
|
|
}
|
|
|
|
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
|
|
if err != nil {
|
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
|
return
|
|
}
|
|
|
|
settings, err := h.obj.GetBucketSettings(r.Context(), bktInfo)
|
|
if err != nil {
|
|
h.logAndSendError(w, "couldn't get bucket settings", reqInfo, err)
|
|
return
|
|
}
|
|
|
|
if configuration.Status != data.VersioningEnabled && configuration.Status != data.VersioningSuspended {
|
|
h.logAndSendError(w, "invalid versioning configuration", reqInfo, errors.GetAPIError(errors.ErrMalformedXML))
|
|
return
|
|
}
|
|
|
|
// 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: &newSettings,
|
|
}
|
|
|
|
if p.Settings.VersioningSuspended() && bktInfo.ObjectLockEnabled {
|
|
h.logAndSendError(w, "couldn't suspend bucket versioning", reqInfo, errors.GetAPIError(errors.ErrObjectLockConfigurationVersioningCannotBeChanged))
|
|
return
|
|
}
|
|
|
|
if err = h.obj.PutBucketSettings(r.Context(), p); err != nil {
|
|
h.logAndSendError(w, "couldn't put update versioning settings", reqInfo, err)
|
|
}
|
|
}
|
|
|
|
// GetBucketVersioningHandler implements bucket versioning getter handler.
|
|
func (h *handler) GetBucketVersioningHandler(w http.ResponseWriter, r *http.Request) {
|
|
reqInfo := middleware.GetReqInfo(r.Context())
|
|
|
|
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
|
|
if err != nil {
|
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
|
return
|
|
}
|
|
|
|
settings, err := h.obj.GetBucketSettings(r.Context(), bktInfo)
|
|
if err != nil {
|
|
h.logAndSendError(w, "couldn't get version settings", reqInfo, err)
|
|
return
|
|
}
|
|
|
|
if err = middleware.EncodeToResponse(w, formVersioningConfiguration(settings)); err != nil {
|
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
|
}
|
|
}
|
|
|
|
func formVersioningConfiguration(settings *data.BucketSettings) *VersioningConfiguration {
|
|
res := &VersioningConfiguration{}
|
|
if !settings.Unversioned() {
|
|
res.Status = settings.Versioning
|
|
}
|
|
|
|
return res
|
|
}
|