2020-10-02 12:23:52 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
2020-10-29 15:01:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
2022-05-24 18:47:21 +00:00
|
|
|
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-01-20 09:45:58 +00:00
|
|
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-24 18:47:21 +00:00
|
|
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-10-02 12:23:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type sysObjHdr struct {
|
|
|
|
k, v string
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:32:03 +00:00
|
|
|
func (s sysObjHdr) Key() string {
|
2020-10-02 12:23:52 +00:00
|
|
|
return s.k
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:32:03 +00:00
|
|
|
func (s sysObjHdr) Value() string {
|
2020-10-02 12:23:52 +00:00
|
|
|
return s.v
|
|
|
|
}
|
|
|
|
|
|
|
|
func u64Value(v uint64) string {
|
|
|
|
return strconv.FormatUint(v, 10)
|
|
|
|
}
|
|
|
|
|
2022-05-24 18:47:21 +00:00
|
|
|
func headersFromObject(obj *object.Object, cid cidSDK.ID, oid *oidSDK.ID) []eaclSDK.Header {
|
2022-01-19 11:32:10 +00:00
|
|
|
var count int
|
2022-03-03 14:19:05 +00:00
|
|
|
for obj := obj; obj != nil; obj = obj.Parent() {
|
2022-01-19 11:32:10 +00:00
|
|
|
count += 9 + len(obj.Attributes())
|
|
|
|
}
|
2020-10-02 12:23:52 +00:00
|
|
|
|
2022-01-19 11:32:10 +00:00
|
|
|
res := make([]eaclSDK.Header, 0, count)
|
2022-03-03 14:19:05 +00:00
|
|
|
for ; obj != nil; obj = obj.Parent() {
|
2020-10-02 12:23:52 +00:00
|
|
|
res = append(res,
|
2022-05-24 18:47:21 +00:00
|
|
|
cidHeader(cid),
|
2020-10-02 12:23:52 +00:00
|
|
|
// creation epoch
|
2022-05-17 13:32:03 +00:00
|
|
|
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
|
2022-05-17 13:32:03 +00:00
|
|
|
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
|
|
|
},
|
2021-08-25 11:26:41 +00:00
|
|
|
// object version
|
2022-05-17 13:32:03 +00:00
|
|
|
sysObjHdr{
|
2021-08-25 11:26:41 +00:00
|
|
|
k: acl.FilterObjectVersion,
|
|
|
|
v: obj.Version().String(),
|
|
|
|
},
|
|
|
|
// object type
|
2022-05-17 13:32:03 +00:00
|
|
|
sysObjHdr{
|
2021-08-25 11:26:41 +00:00
|
|
|
k: acl.FilterObjectType,
|
|
|
|
v: obj.Type().String(),
|
|
|
|
},
|
2020-10-02 12:23:52 +00:00
|
|
|
)
|
|
|
|
|
2022-05-24 18:47:21 +00:00
|
|
|
if oid != nil {
|
|
|
|
res = append(res, oidHeader(*oid))
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
if idOwner := obj.OwnerID(); idOwner != nil {
|
|
|
|
res = append(res, ownerIDHeader(*idOwner))
|
|
|
|
}
|
|
|
|
|
2022-05-11 16:35:01 +00:00
|
|
|
cs, ok := obj.PayloadChecksum()
|
|
|
|
if ok {
|
2022-05-17 13:32:03 +00:00
|
|
|
res = append(res, sysObjHdr{
|
2022-05-11 16:35:01 +00:00
|
|
|
k: acl.FilterObjectPayloadHash,
|
|
|
|
v: cs.String(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
cs, ok = obj.PayloadHomomorphicHash()
|
|
|
|
if ok {
|
2022-05-17 13:32:03 +00:00
|
|
|
res = append(res, sysObjHdr{
|
2022-05-11 16:35:01 +00:00
|
|
|
k: acl.FilterObjectHomomorphicHash,
|
|
|
|
v: cs.String(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
attrs := obj.Attributes()
|
2020-10-02 12:23:52 +00:00
|
|
|
for i := range attrs {
|
2022-03-15 12:11:35 +00:00
|
|
|
res = append(res, &attrs[i]) // only pointer attrs can implement eaclSDK.Header interface
|
2020-10-02 12:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|