diff --git a/api/handler/tagging.go b/api/handler/tagging.go index cacc092a3..a0c927024 100644 --- a/api/handler/tagging.go +++ b/api/handler/tagging.go @@ -66,7 +66,6 @@ func (h *handler) PutObjectTaggingHandler(w http.ResponseWriter, r *http.Request func (h *handler) GetObjectTaggingHandler(w http.ResponseWriter, r *http.Request) { reqInfo := api.GetReqInfo(r.Context()) - versionID := reqInfo.URL.Query().Get("versionId") bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName) if err != nil { @@ -74,19 +73,27 @@ func (h *handler) GetObjectTaggingHandler(w http.ResponseWriter, r *http.Request return } + settings, err := h.obj.GetBucketSettings(r.Context(), bktInfo) + if err != nil { + h.logAndSendError(w, "could not get bucket settings", reqInfo, err) + return + } + p := &layer.ObjectVersion{ BktInfo: bktInfo, ObjectName: reqInfo.ObjectName, - VersionID: versionID, + VersionID: reqInfo.URL.Query().Get("versionId"), } - tagSet, err := h.obj.GetObjectTagging(r.Context(), p) + versionID, tagSet, err := h.obj.GetObjectTagging(r.Context(), p) if err != nil { h.logAndSendError(w, "could not get object tagging", reqInfo, err) return } - w.Header().Set(api.AmzVersionID, versionID) + if settings.VersioningEnabled { + w.Header().Set(api.AmzVersionID, versionID) + } if err = api.EncodeToResponse(w, encodeTagging(tagSet)); err != nil { h.logAndSendError(w, "something went wrong", reqInfo, err) } diff --git a/api/layer/compound.go b/api/layer/compound.go index fb8e37a17..914a841b1 100644 --- a/api/layer/compound.go +++ b/api/layer/compound.go @@ -26,6 +26,7 @@ func (n *layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *ObjectV if err != nil { return nil, nil, err } + objVersion.VersionID = version.OID.EncodeToString() tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, &objVersion.BktInfo.CID, version) if err != nil { diff --git a/api/layer/layer.go b/api/layer/layer.go index 894ae3b2f..cbc96c84d 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -224,7 +224,7 @@ type ( PutBucketTagging(ctx context.Context, cnrID *cid.ID, tagSet map[string]string) error DeleteBucketTagging(ctx context.Context, cnrID *cid.ID) error - GetObjectTagging(ctx context.Context, p *ObjectVersion) (map[string]string, error) + GetObjectTagging(ctx context.Context, p *ObjectVersion) (string, map[string]string, error) PutObjectTagging(ctx context.Context, p *ObjectVersion, tagSet map[string]string) error DeleteObjectTagging(ctx context.Context, p *ObjectVersion) error diff --git a/api/layer/tagging.go b/api/layer/tagging.go index acffc5ec3..7a932b980 100644 --- a/api/layer/tagging.go +++ b/api/layer/tagging.go @@ -10,34 +10,36 @@ import ( "go.uber.org/zap" ) -func (n *layer) GetObjectTagging(ctx context.Context, p *ObjectVersion) (map[string]string, error) { +func (n *layer) GetObjectTagging(ctx context.Context, p *ObjectVersion) (string, map[string]string, error) { var ( err error tags map[string]string ) + tags = n.systemCache.GetTagging(objectTaggingCacheKey(p)) if tags != nil { - return tags, nil + return p.VersionID, tags, nil } version, err := n.getNodeVersion(ctx, p) if err != nil { - return nil, err + return "", nil, err } + p.VersionID = version.OID.EncodeToString() tags, err = n.treeService.GetObjectTagging(ctx, &p.BktInfo.CID, version) if err != nil { if errorsStd.Is(err, ErrNodeNotFound) { - return nil, errors.GetAPIError(errors.ErrNoSuchKey) + return "", nil, errors.GetAPIError(errors.ErrNoSuchKey) } - return nil, err + return "", nil, err } if err = n.systemCache.PutTagging(objectTaggingCacheKey(p), tags); err != nil { n.log.Error("couldn't cache system object", zap.Error(err)) } - return tags, nil + return p.VersionID, tags, nil } func (n *layer) PutObjectTagging(ctx context.Context, p *ObjectVersion, tagSet map[string]string) error { @@ -45,6 +47,7 @@ func (n *layer) PutObjectTagging(ctx context.Context, p *ObjectVersion, tagSet m if err != nil { return err } + p.VersionID = version.OID.EncodeToString() err = n.treeService.PutObjectTagging(ctx, &p.BktInfo.CID, version, tagSet) if err != nil {