[#19] Update eACL service methods

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-09-04 15:18:47 +03:00
parent 03b170237f
commit 8f5ea75eb6
3 changed files with 32 additions and 18 deletions

View file

@ -15,6 +15,8 @@ type EACLArgs struct {
// returned by get eACL test invoke. // returned by get eACL test invoke.
type EACLValues struct { type EACLValues struct {
eacl []byte // extended ACL table eacl []byte // extended ACL table
signature []byte // signature of extended ACL table
} }
// SetCID sets the container identifier // SetCID sets the container identifier
@ -29,6 +31,10 @@ func (g *EACLValues) EACL() []byte {
return g.eacl return g.eacl
} }
func (g *EACLValues) Signature() []byte {
return g.signature
}
// EACL performs the test invoke of get eACL // EACL performs the test invoke of get eACL
// method of NeoFS Container contract. // method of NeoFS Container contract.
func (c *Client) EACL(args EACLArgs) (*EACLValues, error) { func (c *Client) EACL(args EACLArgs) (*EACLValues, error) {
@ -42,12 +48,27 @@ func (c *Client) EACL(args EACLArgs) (*EACLValues, error) {
return nil, errors.Errorf("unexpected stack item count (%s): %d", c.eaclMethod, ln) return nil, errors.Errorf("unexpected stack item count (%s): %d", c.eaclMethod, ln)
} }
eacl, err := client.BytesFromStackItem(prms[0]) arr, err := client.ArrayFromStackItem(prms[0])
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "could not get byte array from stack item (%s)", c.eaclMethod) return nil, errors.Wrapf(err, "could not get item array of eACL (%s)", c.eaclMethod)
}
if len(arr) != 2 {
return nil, errors.Errorf("unexpected eacl stack item count (%s): %d", c.eaclMethod, len(arr))
}
eacl, err := client.BytesFromStackItem(arr[0])
if err != nil {
return nil, errors.Wrapf(err, "could not get byte array of eACL (%s)", c.eaclMethod)
}
sig, err := client.BytesFromStackItem(arr[1])
if err != nil {
return nil, errors.Wrapf(err, "could not get byte array of eACL signature (%s)", c.eaclMethod)
} }
return &EACLValues{ return &EACLValues{
eacl: eacl, eacl: eacl,
signature: sig,
}, nil }, nil
} }

View file

@ -5,19 +5,11 @@ import "github.com/pkg/errors"
// SetEACLArgs groups the arguments // SetEACLArgs groups the arguments
// of set eACL invocation call. // of set eACL invocation call.
type SetEACLArgs struct { type SetEACLArgs struct {
cid []byte // container identifier in a binary format
eacl []byte // extended ACL table eacl []byte // extended ACL table
sig []byte // eACL table signature sig []byte // eACL table signature
} }
// SetCID sets the container identifier
// in a binary format.
func (p *SetEACLArgs) SetCID(v []byte) {
p.cid = v
}
// SetEACL sets the extended ACL table // SetEACL sets the extended ACL table
// in a binary format. // in a binary format.
func (p *SetEACLArgs) SetEACL(v []byte) { func (p *SetEACLArgs) SetEACL(v []byte) {
@ -35,7 +27,6 @@ func (p *SetEACLArgs) SetSignature(v []byte) {
func (c *Client) SetEACL(args SetEACLArgs) error { func (c *Client) SetEACL(args SetEACLArgs) error {
return errors.Wrapf(c.client.Invoke( return errors.Wrapf(c.client.Invoke(
c.setEACLMethod, c.setEACLMethod,
args.cid,
args.eacl, args.eacl,
args.sig, args.sig,
), "could not invoke method (%s)", c.setEACLMethod) ), "could not invoke method (%s)", c.setEACLMethod)

View file

@ -115,18 +115,12 @@ func (s *morphExecutor) List(ctx context.Context, body *container.ListRequestBod
func (s *morphExecutor) SetExtendedACL(ctx context.Context, body *container.SetExtendedACLRequestBody) (*container.SetExtendedACLResponseBody, error) { func (s *morphExecutor) SetExtendedACL(ctx context.Context, body *container.SetExtendedACLRequestBody) (*container.SetExtendedACLResponseBody, error) {
eacl := body.GetEACL() eacl := body.GetEACL()
cidBytes, err := eacl.GetContainerID().StableMarshal(nil)
if err != nil {
return nil, errors.Wrap(err, "could not marshal container ID")
}
eaclBytes, err := eacl.StableMarshal(nil) eaclBytes, err := eacl.StableMarshal(nil)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not marshal eACL table") return nil, errors.Wrap(err, "could not marshal eACL table")
} }
args := containerMorph.SetEACLArgs{} args := containerMorph.SetEACLArgs{}
args.SetCID(cidBytes)
args.SetEACL(eaclBytes) args.SetEACL(eaclBytes)
args.SetSignature(body.GetSignature().GetSign()) args.SetSignature(body.GetSignature().GetSign())
@ -154,8 +148,16 @@ func (s *morphExecutor) GetExtendedACL(ctx context.Context, req *container.GetEx
eacl := acl.TableFromGRPCMessage(eaclGRPC) eacl := acl.TableFromGRPCMessage(eaclGRPC)
eaclSignature := new(refs.Signature)
eaclSignature.SetSign(val.Signature())
res := new(container.GetExtendedACLResponseBody) res := new(container.GetExtendedACLResponseBody)
res.SetEACL(eacl) res.SetEACL(eacl)
// Public key should be obtained by request sender, so we set up only
// the signature. Technically, node can make invocation to find container
// owner public key, but request sender cannot trust this info.
res.SetSignature(eaclSignature)
return res, nil return res, nil
} }