From 395fd187ac8b234fd1ee667839885324ccc19a45 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 19 May 2021 15:04:38 +0300 Subject: [PATCH] [#505] morph/container: Add key argument to client wrapper's SetEACL In recent changes argument list of set eACL call of Container contract client was extended with binary public key. In the future there will be a need to pass the table in binary format. Replace `PutEACL` method with `PutEACLBinary` one which accepts three binary parameters: eACL table, key and signature. Create `PutEACL` function similar to the removed method, but accepting `Signature` structure instead of just a signature. Use this function in Container service server in the place where `PutEACL` was used. Signed-off-by: Leonard Lyubich --- pkg/morph/client/container/wrapper/eacl.go | 30 +++++++++++++++------- pkg/services/container/morph/executor.go | 4 ++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/morph/client/container/wrapper/eacl.go b/pkg/morph/client/container/wrapper/eacl.go index 08a61622b..7a23d3478 100644 --- a/pkg/morph/client/container/wrapper/eacl.go +++ b/pkg/morph/client/container/wrapper/eacl.go @@ -52,24 +52,36 @@ func (w *Wrapper) GetEACL(cid *containerSDK.ID) (*eacl.Table, *pkg.Signature, er return table, tableSignature, nil } -// PutEACL saves the extended ACL table in NeoFS system -// through Container contract call. +// PutEACL marshals table, and passes it to Wrapper's PutEACLBinary method +// along with sig.Key() and sig.Sign(). // -// Returns any error encountered that caused the saving to interrupt. -func (w *Wrapper) PutEACL(table *eacl.Table, signature []byte) error { - if table == nil || len(signature) == 0 { +// Returns error if table is nil. +func PutEACL(w *Wrapper, table *eacl.Table, sig *pkg.Signature) error { + if table == nil { return errNilArgument } - args := client.SetEACLArgs{} - args.SetSignature(signature) - data, err := table.Marshal() if err != nil { return fmt.Errorf("can't marshal eacl table: %w", err) } - args.SetEACL(data) + return w.PutEACLBinary(data, sig.Key(), sig.Sign()) +} + +// PutEACLBinary save binary eACL table with its key and signature +// in NeoFS system through Container contract call. +// +// Returns any error encountered that caused the saving to interrupt. +func (w *Wrapper) PutEACLBinary(table, key, sig []byte) error { + if len(sig) == 0 || len(key) == 0 { + return errNilArgument + } + + args := client.SetEACLArgs{} + args.SetSignature(table) + args.SetPublicKey(key) + args.SetEACL(sig) return w.client.SetEACL(args) } diff --git a/pkg/services/container/morph/executor.go b/pkg/services/container/morph/executor.go index 9020df7a0..638c77d60 100644 --- a/pkg/services/container/morph/executor.go +++ b/pkg/services/container/morph/executor.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg" eaclSDK "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/owner" @@ -88,8 +89,9 @@ func (s *morphExecutor) List(ctx context.Context, body *container.ListRequestBod func (s *morphExecutor) SetExtendedACL(ctx context.Context, body *container.SetExtendedACLRequestBody) (*container.SetExtendedACLResponseBody, error) { table := eaclSDK.NewTableFromV2(body.GetEACL()) + sign := pkg.NewSignatureFromV2(body.GetSignature()) - err := s.wrapper.PutEACL(table, body.GetSignature().GetSign()) + err := wrapper.PutEACL(s.wrapper, table, sign) return new(container.SetExtendedACLResponseBody), err }