2020-10-02 12:23:52 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
2020-10-02 12:23:52 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
2020-10-29 15:01:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
2020-10-02 12:23:52 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl"
|
|
|
|
)
|
|
|
|
|
|
|
|
type sysObjHdr struct {
|
|
|
|
k, v string
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
func (s *sysObjHdr) Key() string {
|
2020-10-02 12:23:52 +00:00
|
|
|
return s.k
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
func (s *sysObjHdr) Value() string {
|
2020-10-02 12:23:52 +00:00
|
|
|
return s.v
|
|
|
|
}
|
|
|
|
|
|
|
|
func idValue(id *objectSDK.ID) string {
|
2020-10-21 15:49:38 +00:00
|
|
|
return id.String()
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-31 11:03:17 +00:00
|
|
|
func cidValue(id *cid.ID) string {
|
2020-10-21 15:49:38 +00:00
|
|
|
return id.String()
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ownerIDValue(id *owner.ID) string {
|
2020-10-21 15:49:38 +00:00
|
|
|
return id.String()
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func u64Value(v uint64) string {
|
|
|
|
return strconv.FormatUint(v, 10)
|
|
|
|
}
|
|
|
|
|
2020-12-15 09:06:04 +00:00
|
|
|
func headersFromObject(obj *object.Object, addr *objectSDK.Address) []eacl.Header {
|
2020-10-02 12:23:52 +00:00
|
|
|
// TODO: optimize allocs
|
|
|
|
res := make([]eacl.Header, 0)
|
|
|
|
|
|
|
|
for ; obj != nil; obj = obj.GetParent() {
|
|
|
|
res = append(res,
|
2020-12-15 09:06:04 +00:00
|
|
|
cidHeader(addr.ContainerID()),
|
2020-10-02 12:23:52 +00:00
|
|
|
// owner ID
|
|
|
|
&sysObjHdr{
|
2020-10-29 15:01:58 +00:00
|
|
|
k: acl.FilterObjectOwnerID,
|
2020-11-16 09:43:52 +00:00
|
|
|
v: ownerIDValue(obj.OwnerID()),
|
2020-10-02 12:23:52 +00:00
|
|
|
},
|
|
|
|
// creation epoch
|
|
|
|
&sysObjHdr{
|
2020-10-29 15:01:58 +00:00
|
|
|
k: acl.FilterObjectCreationEpoch,
|
2020-11-16 09:43:52 +00:00
|
|
|
v: u64Value(obj.CreationEpoch()),
|
2020-10-02 12:23:52 +00:00
|
|
|
},
|
|
|
|
// payload size
|
|
|
|
&sysObjHdr{
|
2020-10-29 15:01:58 +00:00
|
|
|
k: acl.FilterObjectPayloadLength,
|
2020-11-16 09:43:52 +00:00
|
|
|
v: u64Value(obj.PayloadSize()),
|
2020-10-02 12:23:52 +00:00
|
|
|
},
|
2020-12-15 09:06:04 +00:00
|
|
|
oidHeader(addr.ObjectID()),
|
2020-10-29 15:01:58 +00:00
|
|
|
// TODO: add others fields after neofs-api#84
|
2020-10-02 12:23:52 +00:00
|
|
|
)
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
attrs := obj.Attributes()
|
2020-10-02 12:23:52 +00:00
|
|
|
hs := make([]eacl.Header, 0, len(attrs))
|
|
|
|
|
|
|
|
for i := range attrs {
|
|
|
|
hs = append(hs, attrs[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
res = append(res, hs...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|