[#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
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
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"
|
||||
sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session"
|
||||
)
|
||||
|
||||
|
@ -55,6 +57,10 @@ func NewMessageHeaderSource(opts ...Option) (eaclSDK.TypedHeaderSource, error) {
|
|||
opts[i](cfg)
|
||||
}
|
||||
|
||||
if cfg.msg == nil {
|
||||
return nil, errors.New("message is not provided")
|
||||
}
|
||||
|
||||
objHdrs, err := cfg.objectHeaders()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -93,7 +99,7 @@ func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) {
|
|||
switch m := h.msg.(type) {
|
||||
default:
|
||||
panic(fmt.Sprintf("unexpected message type %T", h.msg))
|
||||
case *requestXHeaderSource:
|
||||
case requestXHeaderSource:
|
||||
switch req := m.req.(type) {
|
||||
case *objectV2.GetRequest:
|
||||
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) {
|
||||
default:
|
||||
hs, _ := h.localObjectHeaders(h.addr)
|
||||
|
@ -205,17 +211,24 @@ func (h *cfg) localObjectHeaders(addr *objectSDKAddress.Address) ([]eaclSDK.Head
|
|||
return headersFromObject(obj, addr), nil
|
||||
}
|
||||
|
||||
func cidHeader(idCnr *cid.ID) eaclSDK.Header {
|
||||
return &sysObjHdr{
|
||||
func cidHeader(idCnr cid.ID) sysObjHdr {
|
||||
return sysObjHdr{
|
||||
k: acl.FilterObjectContainerID,
|
||||
v: cidValue(idCnr),
|
||||
v: idCnr.String(),
|
||||
}
|
||||
}
|
||||
|
||||
func oidHeader(oid *objectSDKID.ID) eaclSDK.Header {
|
||||
return &sysObjHdr{
|
||||
func oidHeader(oid objectSDKID.ID) sysObjHdr {
|
||||
return sysObjHdr{
|
||||
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()
|
||||
|
||||
res := make([]eaclSDK.Header, 1, 2)
|
||||
res[0] = cidHeader(&cnr)
|
||||
res[0] = cidHeader(cnr)
|
||||
|
||||
if oid, ok := addr.ObjectID(); ok {
|
||||
res = append(res, oidHeader(&oid))
|
||||
res = append(res, oidHeader(oid))
|
||||
}
|
||||
|
||||
return res
|
||||
|
|
|
@ -4,38 +4,23 @@ import (
|
|||
"strconv"
|
||||
|
||||
"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"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
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 {
|
||||
k, v string
|
||||
}
|
||||
|
||||
func (s *sysObjHdr) Key() string {
|
||||
func (s sysObjHdr) Key() string {
|
||||
return s.k
|
||||
}
|
||||
|
||||
func (s *sysObjHdr) Value() string {
|
||||
func (s sysObjHdr) Value() string {
|
||||
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 {
|
||||
return strconv.FormatUint(v, 10)
|
||||
}
|
||||
|
@ -52,30 +37,27 @@ func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eac
|
|||
id, _ := addr.ObjectID()
|
||||
|
||||
res = append(res,
|
||||
cidHeader(&cnr),
|
||||
cidHeader(cnr),
|
||||
// owner ID
|
||||
&sysObjHdr{
|
||||
k: acl.FilterObjectOwnerID,
|
||||
v: ownerIDValue(obj.OwnerID()),
|
||||
},
|
||||
ownerIDHeader(obj.OwnerID()),
|
||||
// creation epoch
|
||||
&sysObjHdr{
|
||||
sysObjHdr{
|
||||
k: acl.FilterObjectCreationEpoch,
|
||||
v: u64Value(obj.CreationEpoch()),
|
||||
},
|
||||
// payload size
|
||||
&sysObjHdr{
|
||||
sysObjHdr{
|
||||
k: acl.FilterObjectPayloadLength,
|
||||
v: u64Value(obj.PayloadSize()),
|
||||
},
|
||||
oidHeader(&id),
|
||||
oidHeader(id),
|
||||
// object version
|
||||
&sysObjHdr{
|
||||
sysObjHdr{
|
||||
k: acl.FilterObjectVersion,
|
||||
v: obj.Version().String(),
|
||||
},
|
||||
// object type
|
||||
&sysObjHdr{
|
||||
sysObjHdr{
|
||||
k: acl.FilterObjectType,
|
||||
v: obj.Type().String(),
|
||||
},
|
||||
|
@ -83,7 +65,7 @@ func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eac
|
|||
|
||||
cs, ok := obj.PayloadChecksum()
|
||||
if ok {
|
||||
res = append(res, &sysObjHdr{
|
||||
res = append(res, sysObjHdr{
|
||||
k: acl.FilterObjectPayloadHash,
|
||||
v: cs.String(),
|
||||
})
|
||||
|
@ -91,7 +73,7 @@ func headersFromObject(obj *object.Object, addr *objectSDKAddress.Address) []eac
|
|||
|
||||
cs, ok = obj.PayloadHomomorphicHash()
|
||||
if ok {
|
||||
res = append(res, &sysObjHdr{
|
||||
res = append(res, sysObjHdr{
|
||||
k: acl.FilterObjectHomomorphicHash,
|
||||
v: cs.String(),
|
||||
})
|
||||
|
|
|
@ -21,7 +21,7 @@ func WithLocalObjectStorage(v *engine.StorageEngine) Option {
|
|||
|
||||
func WithServiceRequest(v Request) Option {
|
||||
return func(c *cfg) {
|
||||
c.msg = &requestXHeaderSource{
|
||||
c.msg = requestXHeaderSource{
|
||||
req: v,
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func WithServiceRequest(v Request) Option {
|
|||
|
||||
func WithServiceResponse(resp Response, req Request) Option {
|
||||
return func(c *cfg) {
|
||||
c.msg = &responseXHeaderSource{
|
||||
c.msg = responseXHeaderSource{
|
||||
resp: resp,
|
||||
req: req,
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ type responseXHeaderSource struct {
|
|||
req Request
|
||||
}
|
||||
|
||||
func (s *requestXHeaderSource) GetXHeaders() []session.XHeader {
|
||||
func (s requestXHeaderSource) GetXHeaders() []session.XHeader {
|
||||
ln := 0
|
||||
xHdrs := make([][]session.XHeader, 0)
|
||||
|
||||
|
@ -41,7 +41,7 @@ func (s *requestXHeaderSource) GetXHeaders() []session.XHeader {
|
|||
return res
|
||||
}
|
||||
|
||||
func (s *responseXHeaderSource) GetXHeaders() []session.XHeader {
|
||||
func (s responseXHeaderSource) GetXHeaders() []session.XHeader {
|
||||
ln := 0
|
||||
xHdrs := make([][]session.XHeader, 0)
|
||||
|
||||
|
|
Loading…
Reference in a new issue