forked from TrueCloudLab/frostfs-node
[#1386] eacl/v2: Use raw structs where possible
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
3f4475f97b
commit
b24589b62d
4 changed files with 39 additions and 44 deletions
|
@ -1,6 +1,7 @@
|
||||||
package v2
|
package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session"
|
sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,6 +57,10 @@ func NewMessageHeaderSource(opts ...Option) (eaclSDK.TypedHeaderSource, error) {
|
||||||
opts[i](cfg)
|
opts[i](cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.msg == nil {
|
||||||
|
return nil, errors.New("message is not provided")
|
||||||
|
}
|
||||||
|
|
||||||
objHdrs, err := cfg.objectHeaders()
|
objHdrs, err := cfg.objectHeaders()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -93,7 +99,7 @@ func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) {
|
||||||
switch m := h.msg.(type) {
|
switch m := h.msg.(type) {
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unexpected message type %T", h.msg))
|
panic(fmt.Sprintf("unexpected message type %T", h.msg))
|
||||||
case *requestXHeaderSource:
|
case requestXHeaderSource:
|
||||||
switch req := m.req.(type) {
|
switch req := m.req.(type) {
|
||||||
case *objectV2.GetRequest:
|
case *objectV2.GetRequest:
|
||||||
return h.localObjectHeaders(h.addr)
|
return h.localObjectHeaders(h.addr)
|
||||||
|
@ -148,9 +154,9 @@ func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return []eaclSDK.Header{cidHeader(&cnr)}, nil
|
return []eaclSDK.Header{cidHeader(cnr)}, nil
|
||||||
}
|
}
|
||||||
case *responseXHeaderSource:
|
case responseXHeaderSource:
|
||||||
switch resp := m.resp.(type) {
|
switch resp := m.resp.(type) {
|
||||||
default:
|
default:
|
||||||
hs, _ := h.localObjectHeaders(h.addr)
|
hs, _ := h.localObjectHeaders(h.addr)
|
||||||
|
@ -205,17 +211,24 @@ func (h *cfg) localObjectHeaders(addr *objectSDKAddress.Address) ([]eaclSDK.Head
|
||||||
return headersFromObject(obj, addr), nil
|
return headersFromObject(obj, addr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cidHeader(idCnr *cid.ID) eaclSDK.Header {
|
func cidHeader(idCnr cid.ID) sysObjHdr {
|
||||||
return &sysObjHdr{
|
return sysObjHdr{
|
||||||
k: acl.FilterObjectContainerID,
|
k: acl.FilterObjectContainerID,
|
||||||
v: cidValue(idCnr),
|
v: idCnr.String(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func oidHeader(oid *objectSDKID.ID) eaclSDK.Header {
|
func oidHeader(oid objectSDKID.ID) sysObjHdr {
|
||||||
return &sysObjHdr{
|
return sysObjHdr{
|
||||||
k: acl.FilterObjectID,
|
k: acl.FilterObjectID,
|
||||||
v: idValue(oid),
|
v: oid.String(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ownerIDHeader(ownerID *owner.ID) sysObjHdr {
|
||||||
|
return sysObjHdr{
|
||||||
|
k: acl.FilterObjectOwnerID,
|
||||||
|
v: ownerID.String(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,10 +236,10 @@ func addressHeaders(addr *objectSDKAddress.Address) []eaclSDK.Header {
|
||||||
cnr, _ := addr.ContainerID()
|
cnr, _ := addr.ContainerID()
|
||||||
|
|
||||||
res := make([]eaclSDK.Header, 1, 2)
|
res := make([]eaclSDK.Header, 1, 2)
|
||||||
res[0] = cidHeader(&cnr)
|
res[0] = cidHeader(cnr)
|
||||||
|
|
||||||
if oid, ok := addr.ObjectID(); ok {
|
if oid, ok := addr.ObjectID(); ok {
|
||||||
res = append(res, oidHeader(&oid))
|
res = append(res, oidHeader(oid))
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -4,38 +4,23 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
||||||
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
||||||
objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type sysObjHdr struct {
|
type sysObjHdr struct {
|
||||||
k, v string
|
k, v string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysObjHdr) Key() string {
|
func (s sysObjHdr) Key() string {
|
||||||
return s.k
|
return s.k
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysObjHdr) Value() string {
|
func (s sysObjHdr) Value() string {
|
||||||
return s.v
|
return s.v
|
||||||
}
|
}
|
||||||
|
|
||||||
func idValue(id *objectSDKID.ID) string {
|
|
||||||
return id.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func cidValue(id *cid.ID) string {
|
|
||||||
return id.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func ownerIDValue(id *owner.ID) string {
|
|
||||||
return id.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func u64Value(v uint64) string {
|
func u64Value(v uint64) string {
|
||||||
return strconv.FormatUint(v, 10)
|
return strconv.FormatUint(v, 10)
|
||||||
}
|
}
|
||||||
|
@ -52,30 +37,27 @@ func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eac
|
||||||
id, _ := addr.ObjectID()
|
id, _ := addr.ObjectID()
|
||||||
|
|
||||||
res = append(res,
|
res = append(res,
|
||||||
cidHeader(&cnr),
|
cidHeader(cnr),
|
||||||
// owner ID
|
// owner ID
|
||||||
&sysObjHdr{
|
ownerIDHeader(obj.OwnerID()),
|
||||||
k: acl.FilterObjectOwnerID,
|
|
||||||
v: ownerIDValue(obj.OwnerID()),
|
|
||||||
},
|
|
||||||
// creation epoch
|
// creation epoch
|
||||||
&sysObjHdr{
|
sysObjHdr{
|
||||||
k: acl.FilterObjectCreationEpoch,
|
k: acl.FilterObjectCreationEpoch,
|
||||||
v: u64Value(obj.CreationEpoch()),
|
v: u64Value(obj.CreationEpoch()),
|
||||||
},
|
},
|
||||||
// payload size
|
// payload size
|
||||||
&sysObjHdr{
|
sysObjHdr{
|
||||||
k: acl.FilterObjectPayloadLength,
|
k: acl.FilterObjectPayloadLength,
|
||||||
v: u64Value(obj.PayloadSize()),
|
v: u64Value(obj.PayloadSize()),
|
||||||
},
|
},
|
||||||
oidHeader(&id),
|
oidHeader(id),
|
||||||
// object version
|
// object version
|
||||||
&sysObjHdr{
|
sysObjHdr{
|
||||||
k: acl.FilterObjectVersion,
|
k: acl.FilterObjectVersion,
|
||||||
v: obj.Version().String(),
|
v: obj.Version().String(),
|
||||||
},
|
},
|
||||||
// object type
|
// object type
|
||||||
&sysObjHdr{
|
sysObjHdr{
|
||||||
k: acl.FilterObjectType,
|
k: acl.FilterObjectType,
|
||||||
v: obj.Type().String(),
|
v: obj.Type().String(),
|
||||||
},
|
},
|
||||||
|
@ -83,7 +65,7 @@ func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eac
|
||||||
|
|
||||||
cs, ok := obj.PayloadChecksum()
|
cs, ok := obj.PayloadChecksum()
|
||||||
if ok {
|
if ok {
|
||||||
res = append(res, &sysObjHdr{
|
res = append(res, sysObjHdr{
|
||||||
k: acl.FilterObjectPayloadHash,
|
k: acl.FilterObjectPayloadHash,
|
||||||
v: cs.String(),
|
v: cs.String(),
|
||||||
})
|
})
|
||||||
|
@ -91,7 +73,7 @@ func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eac
|
||||||
|
|
||||||
cs, ok = obj.PayloadHomomorphicHash()
|
cs, ok = obj.PayloadHomomorphicHash()
|
||||||
if ok {
|
if ok {
|
||||||
res = append(res, &sysObjHdr{
|
res = append(res, sysObjHdr{
|
||||||
k: acl.FilterObjectHomomorphicHash,
|
k: acl.FilterObjectHomomorphicHash,
|
||||||
v: cs.String(),
|
v: cs.String(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,7 +21,7 @@ func WithLocalObjectStorage(v *engine.StorageEngine) Option {
|
||||||
|
|
||||||
func WithServiceRequest(v Request) Option {
|
func WithServiceRequest(v Request) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.msg = &requestXHeaderSource{
|
c.msg = requestXHeaderSource{
|
||||||
req: v,
|
req: v,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func WithServiceRequest(v Request) Option {
|
||||||
|
|
||||||
func WithServiceResponse(resp Response, req Request) Option {
|
func WithServiceResponse(resp Response, req Request) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.msg = &responseXHeaderSource{
|
c.msg = responseXHeaderSource{
|
||||||
resp: resp,
|
resp: resp,
|
||||||
req: req,
|
req: req,
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ type responseXHeaderSource struct {
|
||||||
req Request
|
req Request
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *requestXHeaderSource) GetXHeaders() []session.XHeader {
|
func (s requestXHeaderSource) GetXHeaders() []session.XHeader {
|
||||||
ln := 0
|
ln := 0
|
||||||
xHdrs := make([][]session.XHeader, 0)
|
xHdrs := make([][]session.XHeader, 0)
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ func (s *requestXHeaderSource) GetXHeaders() []session.XHeader {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *responseXHeaderSource) GetXHeaders() []session.XHeader {
|
func (s responseXHeaderSource) GetXHeaders() []session.XHeader {
|
||||||
ln := 0
|
ln := 0
|
||||||
xHdrs := make([][]session.XHeader, 0)
|
xHdrs := make([][]session.XHeader, 0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue