[#577] Add Version() to ExtendedObjectInfo
Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
3ac3f1cc9d
commit
37c46e926e
9 changed files with 27 additions and 22 deletions
|
@ -9,6 +9,10 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/user"
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
UnversionedObjectVersionID = "null"
|
||||||
|
)
|
||||||
|
|
||||||
// NodeVersion represent node from tree service.
|
// NodeVersion represent node from tree service.
|
||||||
type NodeVersion struct {
|
type NodeVersion struct {
|
||||||
BaseNodeVersion
|
BaseNodeVersion
|
||||||
|
@ -30,6 +34,14 @@ type ExtendedObjectInfo struct {
|
||||||
IsLatest bool
|
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.
|
// BaseNodeVersion is minimal node info from tree service.
|
||||||
// Basically used for "system" object.
|
// Basically used for "system" object.
|
||||||
type BaseNodeVersion struct {
|
type BaseNodeVersion struct {
|
||||||
|
|
|
@ -104,19 +104,19 @@ func (h *handler) GetObjectAttributesHandler(w http.ResponseWriter, r *http.Requ
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeAttributesHeaders(w.Header(), info, params)
|
writeAttributesHeaders(w.Header(), extendedInfo, params)
|
||||||
if err = api.EncodeToResponse(w, response); err != nil {
|
if err = api.EncodeToResponse(w, response); err != nil {
|
||||||
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeAttributesHeaders(h http.Header, info *data.ObjectInfo, params *GetObjectAttributesArgs) {
|
func writeAttributesHeaders(h http.Header, info *data.ExtendedObjectInfo, params *GetObjectAttributesArgs) {
|
||||||
h.Set(api.LastModified, info.Created.UTC().Format(http.TimeFormat))
|
h.Set(api.LastModified, info.ObjectInfo.Created.UTC().Format(http.TimeFormat))
|
||||||
if len(params.VersionID) != 0 {
|
if len(params.VersionID) != 0 {
|
||||||
h.Set(api.AmzVersionID, info.Version())
|
h.Set(api.AmzVersionID, info.Version())
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.IsDeleteMarker {
|
if info.NodeVersion.DeleteMarker != nil {
|
||||||
h.Set(api.AmzDeleteMarker, strconv.FormatBool(true))
|
h.Set(api.AmzDeleteMarker, strconv.FormatBool(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) == "" {
|
if len(info.ContentType) > 0 && h.Get(api.ContentType) == "" {
|
||||||
h.Set(api.ContentType, info.ContentType)
|
h.Set(api.ContentType, info.ContentType)
|
||||||
}
|
}
|
||||||
h.Set(api.LastModified, info.Created.UTC().Format(http.TimeFormat))
|
h.Set(api.LastModified, info.Created.UTC().Format(http.TimeFormat))
|
||||||
h.Set(api.ContentLength, strconv.FormatInt(info.Size, 10))
|
h.Set(api.ContentLength, strconv.FormatInt(info.Size, 10))
|
||||||
h.Set(api.ETag, info.HashSum)
|
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))
|
h.Set(api.AmzTaggingCount, strconv.Itoa(tagSetLength))
|
||||||
|
|
||||||
if cacheControl := info.Headers[api.CacheControl]; cacheControl != "" {
|
if cacheControl := info.Headers[api.CacheControl]; cacheControl != "" {
|
||||||
|
@ -159,7 +160,7 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeHeaders(w.Header(), info, len(tagSet))
|
writeHeaders(w.Header(), extendedInfo, len(tagSet))
|
||||||
if params != nil {
|
if params != nil {
|
||||||
writeRangeHeaders(w, params, info.Size)
|
writeRangeHeaders(w, params, info.Size)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
writeHeaders(w.Header(), info, len(tagSet))
|
writeHeaders(w.Header(), extendedInfo, len(tagSet))
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,10 +272,6 @@ func encodeListObjectVersionsToResponse(info *layer.ListObjectVersionsInfo, buck
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ver := range info.Version {
|
for _, ver := range info.Version {
|
||||||
versionID := ver.ObjectInfo.Version()
|
|
||||||
if ver.NodeVersion.IsUnversioned {
|
|
||||||
versionID = layer.UnversionedObjectVersionID
|
|
||||||
}
|
|
||||||
res.Version = append(res.Version, ObjectVersionResponse{
|
res.Version = append(res.Version, ObjectVersionResponse{
|
||||||
IsLatest: ver.IsLatest,
|
IsLatest: ver.IsLatest,
|
||||||
Key: ver.ObjectInfo.Name,
|
Key: ver.ObjectInfo.Name,
|
||||||
|
@ -285,7 +281,7 @@ func encodeListObjectVersionsToResponse(info *layer.ListObjectVersionsInfo, buck
|
||||||
DisplayName: ver.ObjectInfo.Owner.String(),
|
DisplayName: ver.ObjectInfo.Owner.String(),
|
||||||
},
|
},
|
||||||
Size: ver.ObjectInfo.Size,
|
Size: ver.ObjectInfo.Size,
|
||||||
VersionID: versionID,
|
VersionID: ver.Version(),
|
||||||
ETag: ver.ObjectInfo.HashSum,
|
ETag: ver.ObjectInfo.HashSum,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -299,7 +295,7 @@ func encodeListObjectVersionsToResponse(info *layer.ListObjectVersionsInfo, buck
|
||||||
ID: del.ObjectInfo.Owner.String(),
|
ID: del.ObjectInfo.Owner.String(),
|
||||||
DisplayName: del.ObjectInfo.Owner.String(),
|
DisplayName: del.ObjectInfo.Owner.String(),
|
||||||
},
|
},
|
||||||
VersionID: del.ObjectInfo.Version(),
|
VersionID: del.Version(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -482,7 +482,7 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings
|
||||||
var newVersion *data.NodeVersion
|
var newVersion *data.NodeVersion
|
||||||
|
|
||||||
if settings.VersioningSuspended() {
|
if settings.VersioningSuspended() {
|
||||||
obj.VersionID = UnversionedObjectVersionID
|
obj.VersionID = data.UnversionedObjectVersionID
|
||||||
|
|
||||||
var nodeVersion *data.NodeVersion
|
var nodeVersion *data.NodeVersion
|
||||||
if nodeVersion, obj.Error = n.getNodeVersionToDelete(ctx, bkt, obj); obj.Error != nil {
|
if nodeVersion, obj.Error = n.getNodeVersionToDelete(ctx, bkt, obj); obj.Error != nil {
|
||||||
|
|
|
@ -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) {
|
func (n *layer) headVersion(ctx context.Context, bkt *data.BucketInfo, p *HeadObjectParams) (*data.ExtendedObjectInfo, error) {
|
||||||
var err error
|
var err error
|
||||||
var foundVersion *data.NodeVersion
|
var foundVersion *data.NodeVersion
|
||||||
if p.VersionID == UnversionedObjectVersionID {
|
if p.VersionID == data.UnversionedObjectVersionID {
|
||||||
foundVersion, err = n.treeService.GetUnversioned(ctx, bkt.CID, p.Object)
|
foundVersion, err = n.treeService.GetUnversioned(ctx, bkt.CID, p.Object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrNodeNotFound) {
|
if errors.Is(err, ErrNodeNotFound) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ func (n *layer) GetObjectTagging(ctx context.Context, p *ObjectVersion) (string,
|
||||||
tags map[string]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))
|
tags = n.systemCache.GetTagging(objectTaggingCacheKey(p))
|
||||||
if tags != nil {
|
if tags != nil {
|
||||||
return p.VersionID, tags, nil
|
return p.VersionID, tags, nil
|
||||||
|
@ -141,7 +141,7 @@ func (n *layer) getNodeVersion(ctx context.Context, objVersion *ObjectVersion) (
|
||||||
var err error
|
var err error
|
||||||
var version *data.NodeVersion
|
var version *data.NodeVersion
|
||||||
|
|
||||||
if objVersion.VersionID == UnversionedObjectVersionID {
|
if objVersion.VersionID == data.UnversionedObjectVersionID {
|
||||||
version, err = n.treeService.GetUnversioned(ctx, objVersion.BktInfo.CID, objVersion.ObjectName)
|
version, err = n.treeService.GetUnversioned(ctx, objVersion.BktInfo.CID, objVersion.ObjectName)
|
||||||
} else if len(objVersion.VersionID) == 0 {
|
} else if len(objVersion.VersionID) == 0 {
|
||||||
version, err = n.treeService.GetLatestVersion(ctx, objVersion.BktInfo.CID, objVersion.ObjectName)
|
version, err = n.treeService.GetLatestVersion(ctx, objVersion.BktInfo.CID, objVersion.ObjectName)
|
||||||
|
|
|
@ -7,10 +7,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
UnversionedObjectVersionID = "null"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error) {
|
func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error) {
|
||||||
var (
|
var (
|
||||||
allObjects = make([]*data.ExtendedObjectInfo, 0, p.MaxKeys)
|
allObjects = make([]*data.ExtendedObjectInfo, 0, p.MaxKeys)
|
||||||
|
|
Loading…
Reference in a new issue