[#477] Use tags and lock aggregation in handler
Reduce amount of tree service RPCs by using new method in layer package. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
7fd27e04fe
commit
8731dcfd3c
2 changed files with 13 additions and 27 deletions
|
@ -144,9 +144,9 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
VersionID: info.Version(),
|
VersionID: info.Version(),
|
||||||
}
|
}
|
||||||
|
|
||||||
tagSet, err := h.obj.GetObjectTagging(r.Context(), t)
|
tagSet, lockInfo, err := h.obj.GetObjectTaggingAndLock(r.Context(), t)
|
||||||
if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) {
|
if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) {
|
||||||
h.logAndSendError(w, "could not get object tag set", reqInfo, err)
|
h.logAndSendError(w, "could not get object meta data", reqInfo, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
overrideResponseHeaders(w.Header(), reqInfo.URL.Query())
|
overrideResponseHeaders(w.Header(), reqInfo.URL.Query())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = h.setLockingHeaders(r.Context(), bktInfo, info, w.Header()); err != nil {
|
if err = h.setLockingHeaders(bktInfo, lockInfo, w.Header()); err != nil {
|
||||||
h.logAndSendError(w, "could not get locking info", reqInfo, err)
|
h.logAndSendError(w, "could not get locking info", reqInfo, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-s3-gw/api"
|
"github.com/nspcc-dev/neofs-s3-gw/api"
|
||||||
|
@ -68,9 +67,9 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
VersionID: info.Version(),
|
VersionID: info.Version(),
|
||||||
}
|
}
|
||||||
|
|
||||||
tagSet, err := h.obj.GetObjectTagging(r.Context(), t)
|
tagSet, lockInfo, err := h.obj.GetObjectTaggingAndLock(r.Context(), t)
|
||||||
if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) {
|
if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) {
|
||||||
h.logAndSendError(w, "could not get object tag set", reqInfo, err)
|
h.logAndSendError(w, "could not get object meta data", reqInfo, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = h.setLockingHeaders(r.Context(), bktInfo, info, w.Header()); err != nil {
|
if err = h.setLockingHeaders(bktInfo, lockInfo, w.Header()); err != nil {
|
||||||
h.logAndSendError(w, "could not get locking info", reqInfo, err)
|
h.logAndSendError(w, "could not get locking info", reqInfo, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -113,7 +112,7 @@ func (h *handler) HeadBucketHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
api.WriteResponse(w, http.StatusOK, nil, api.MimeNone)
|
api.WriteResponse(w, http.StatusOK, nil, api.MimeNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) setLockingHeaders(ctx context.Context, bktInfo *data.BucketInfo, objInfo *data.ObjectInfo, header http.Header) error {
|
func (h *handler) setLockingHeaders(bktInfo *data.BucketInfo, lockInfo *data.LockInfo, header http.Header) error {
|
||||||
if !bktInfo.ObjectLockEnabled {
|
if !bktInfo.ObjectLockEnabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -121,18 +120,6 @@ func (h *handler) setLockingHeaders(ctx context.Context, bktInfo *data.BucketInf
|
||||||
legalHold := &data.LegalHold{Status: legalHoldOff}
|
legalHold := &data.LegalHold{Status: legalHoldOff}
|
||||||
retention := &data.Retention{Mode: governanceMode}
|
retention := &data.Retention{Mode: governanceMode}
|
||||||
|
|
||||||
p := &layer.ObjectVersion{
|
|
||||||
BktInfo: bktInfo,
|
|
||||||
ObjectName: objInfo.Name,
|
|
||||||
VersionID: objInfo.Version(),
|
|
||||||
}
|
|
||||||
|
|
||||||
lockInfo, err := h.obj.GetLockInfo(ctx, p)
|
|
||||||
if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if lockInfo != nil {
|
|
||||||
if lockInfo.LegalHoldOID != nil {
|
if lockInfo.LegalHoldOID != nil {
|
||||||
legalHold.Status = legalHoldOn
|
legalHold.Status = legalHoldOn
|
||||||
}
|
}
|
||||||
|
@ -142,7 +129,6 @@ func (h *handler) setLockingHeaders(ctx context.Context, bktInfo *data.BucketInf
|
||||||
retention.Mode = complianceMode
|
retention.Mode = complianceMode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
writeLockHeaders(header, legalHold, retention)
|
writeLockHeaders(header, legalHold, retention)
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue