[#577] Add Version() to ExtendedObjectInfo

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2022-08-09 02:35:26 +04:00 committed by Kira
parent 3ac3f1cc9d
commit 37c46e926e
9 changed files with 27 additions and 22 deletions

View file

@ -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 {

View file

@ -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))
}

View file

@ -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 {

View file

@ -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)
}

View file

@ -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(),
})
}

View file

@ -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 {

View file

@ -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) {

View file

@ -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)

View file

@ -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)