diff --git a/api/data/tree.go b/api/data/tree.go index 951b48f78..4dbbe2cb1 100644 --- a/api/data/tree.go +++ b/api/data/tree.go @@ -9,6 +9,10 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/user" ) +const ( + UnversionedObjectVersionID = "null" +) + // NodeVersion represent node from tree service. type NodeVersion struct { BaseNodeVersion @@ -30,6 +34,14 @@ type ExtendedObjectInfo struct { IsLatest bool } +func (e ExtendedObjectInfo) Version() string { + if e.NodeVersion.IsUnversioned { + return UnversionedObjectVersionID + } + + return e.ObjectInfo.ID.EncodeToString() +} + // BaseNodeVersion is minimal node info from tree service. // Basically used for "system" object. type BaseNodeVersion struct { diff --git a/api/handler/attributes.go b/api/handler/attributes.go index 5c0c9fdb0..0a2650a0a 100644 --- a/api/handler/attributes.go +++ b/api/handler/attributes.go @@ -104,19 +104,19 @@ func (h *handler) GetObjectAttributesHandler(w http.ResponseWriter, r *http.Requ return } - writeAttributesHeaders(w.Header(), info, params) + writeAttributesHeaders(w.Header(), extendedInfo, params) if err = api.EncodeToResponse(w, response); err != nil { h.logAndSendError(w, "something went wrong", reqInfo, err) } } -func writeAttributesHeaders(h http.Header, info *data.ObjectInfo, params *GetObjectAttributesArgs) { - h.Set(api.LastModified, info.Created.UTC().Format(http.TimeFormat)) +func writeAttributesHeaders(h http.Header, info *data.ExtendedObjectInfo, params *GetObjectAttributesArgs) { + h.Set(api.LastModified, info.ObjectInfo.Created.UTC().Format(http.TimeFormat)) if len(params.VersionID) != 0 { h.Set(api.AmzVersionID, info.Version()) } - if info.IsDeleteMarker { + if info.NodeVersion.DeleteMarker != nil { h.Set(api.AmzDeleteMarker, strconv.FormatBool(true)) } diff --git a/api/handler/get.go b/api/handler/get.go index aa643861f..262897bc6 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -71,14 +71,15 @@ func overrideResponseHeaders(h http.Header, query url.Values) { } } -func writeHeaders(h http.Header, info *data.ObjectInfo, tagSetLength int) { +func writeHeaders(h http.Header, extendedInfo *data.ExtendedObjectInfo, tagSetLength int) { + info := extendedInfo.ObjectInfo if len(info.ContentType) > 0 && h.Get(api.ContentType) == "" { h.Set(api.ContentType, info.ContentType) } h.Set(api.LastModified, info.Created.UTC().Format(http.TimeFormat)) h.Set(api.ContentLength, strconv.FormatInt(info.Size, 10)) h.Set(api.ETag, info.HashSum) - h.Set(api.AmzVersionID, info.ID.EncodeToString()) + h.Set(api.AmzVersionID, extendedInfo.Version()) h.Set(api.AmzTaggingCount, strconv.Itoa(tagSetLength)) if cacheControl := info.Headers[api.CacheControl]; cacheControl != "" { @@ -159,7 +160,7 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) { return } - writeHeaders(w.Header(), info, len(tagSet)) + writeHeaders(w.Header(), extendedInfo, len(tagSet)) if params != nil { writeRangeHeaders(w, params, info.Size) } else { diff --git a/api/handler/head.go b/api/handler/head.go index 8f859a6ed..97198e043 100644 --- a/api/handler/head.go +++ b/api/handler/head.go @@ -92,7 +92,7 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) { return } - writeHeaders(w.Header(), info, len(tagSet)) + writeHeaders(w.Header(), extendedInfo, len(tagSet)) w.WriteHeader(http.StatusOK) } diff --git a/api/handler/object_list.go b/api/handler/object_list.go index 5c6a88d33..d1aa95ddc 100644 --- a/api/handler/object_list.go +++ b/api/handler/object_list.go @@ -272,10 +272,6 @@ func encodeListObjectVersionsToResponse(info *layer.ListObjectVersionsInfo, buck } for _, ver := range info.Version { - versionID := ver.ObjectInfo.Version() - if ver.NodeVersion.IsUnversioned { - versionID = layer.UnversionedObjectVersionID - } res.Version = append(res.Version, ObjectVersionResponse{ IsLatest: ver.IsLatest, Key: ver.ObjectInfo.Name, @@ -285,7 +281,7 @@ func encodeListObjectVersionsToResponse(info *layer.ListObjectVersionsInfo, buck DisplayName: ver.ObjectInfo.Owner.String(), }, Size: ver.ObjectInfo.Size, - VersionID: versionID, + VersionID: ver.Version(), ETag: ver.ObjectInfo.HashSum, }) } @@ -299,7 +295,7 @@ func encodeListObjectVersionsToResponse(info *layer.ListObjectVersionsInfo, buck ID: del.ObjectInfo.Owner.String(), DisplayName: del.ObjectInfo.Owner.String(), }, - VersionID: del.ObjectInfo.Version(), + VersionID: del.Version(), }) } diff --git a/api/layer/layer.go b/api/layer/layer.go index 1c43dab10..c61890c1b 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -482,7 +482,7 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings var newVersion *data.NodeVersion if settings.VersioningSuspended() { - obj.VersionID = UnversionedObjectVersionID + obj.VersionID = data.UnversionedObjectVersionID var nodeVersion *data.NodeVersion if nodeVersion, obj.Error = n.getNodeVersionToDelete(ctx, bkt, obj); obj.Error != nil { diff --git a/api/layer/object.go b/api/layer/object.go index 927cbc9e3..2d8d3daad 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -290,7 +290,7 @@ func (n *layer) headLastVersionIfNotDeleted(ctx context.Context, bkt *data.Bucke func (n *layer) headVersion(ctx context.Context, bkt *data.BucketInfo, p *HeadObjectParams) (*data.ExtendedObjectInfo, error) { var err error var foundVersion *data.NodeVersion - if p.VersionID == UnversionedObjectVersionID { + if p.VersionID == data.UnversionedObjectVersionID { foundVersion, err = n.treeService.GetUnversioned(ctx, bkt.CID, p.Object) if err != nil { if errors.Is(err, ErrNodeNotFound) { diff --git a/api/layer/tagging.go b/api/layer/tagging.go index 0e898d34a..51f6f19b0 100644 --- a/api/layer/tagging.go +++ b/api/layer/tagging.go @@ -16,7 +16,7 @@ func (n *layer) GetObjectTagging(ctx context.Context, p *ObjectVersion) (string, tags map[string]string ) - if len(p.VersionID) != 0 && p.VersionID != UnversionedObjectVersionID { + if len(p.VersionID) != 0 && p.VersionID != data.UnversionedObjectVersionID { tags = n.systemCache.GetTagging(objectTaggingCacheKey(p)) if tags != nil { return p.VersionID, tags, nil @@ -141,7 +141,7 @@ func (n *layer) getNodeVersion(ctx context.Context, objVersion *ObjectVersion) ( var err error var version *data.NodeVersion - if objVersion.VersionID == UnversionedObjectVersionID { + if objVersion.VersionID == data.UnversionedObjectVersionID { version, err = n.treeService.GetUnversioned(ctx, objVersion.BktInfo.CID, objVersion.ObjectName) } else if len(objVersion.VersionID) == 0 { version, err = n.treeService.GetLatestVersion(ctx, objVersion.BktInfo.CID, objVersion.ObjectName) diff --git a/api/layer/versioning.go b/api/layer/versioning.go index 2ba013140..003821294 100644 --- a/api/layer/versioning.go +++ b/api/layer/versioning.go @@ -7,10 +7,6 @@ import ( "github.com/nspcc-dev/neofs-s3-gw/api/data" ) -const ( - UnversionedObjectVersionID = "null" -) - func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error) { var ( allObjects = make([]*data.ExtendedObjectInfo, 0, p.MaxKeys)