2020-10-02 12:23:52 +00:00
|
|
|
package v2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func cidValue(id *container.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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func headersFromObject(obj *object.Object) []eacl.Header {
|
|
|
|
// TODO: optimize allocs
|
|
|
|
res := make([]eacl.Header, 0)
|
|
|
|
|
|
|
|
for ; obj != nil; obj = obj.GetParent() {
|
|
|
|
res = append(res,
|
|
|
|
// container ID
|
|
|
|
&sysObjHdr{
|
2020-10-29 15:01:58 +00:00
|
|
|
k: acl.FilterObjectContainerID,
|
2020-11-16 09:43:52 +00:00
|
|
|
v: cidValue(obj.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-11-25 07:18:06 +00:00
|
|
|
&sysObjHdr{
|
|
|
|
k: acl.FilterObjectID,
|
|
|
|
v: idValue(obj.ID()),
|
|
|
|
},
|
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
|
|
|
|
}
|