From 404c62c5c422d7629c39d75e8647651cfd4b28a3 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 11 Nov 2021 10:39:01 +0300 Subject: [PATCH] [#971] morph/neofsid: Add optional parameters Add optional parameters to the client call signature. Signed-off-by: Pavel Karpy --- pkg/morph/client/neofsid/addrm_keys.go | 8 ++++ pkg/morph/client/neofsid/wrapper/keys.go | 50 +++++++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/pkg/morph/client/neofsid/addrm_keys.go b/pkg/morph/client/neofsid/addrm_keys.go index 4c5976e8..99016c74 100644 --- a/pkg/morph/client/neofsid/addrm_keys.go +++ b/pkg/morph/client/neofsid/addrm_keys.go @@ -22,6 +22,12 @@ type commonBindArgs struct { ownerID []byte // NeoFS account identifier keys [][]byte // list of serialized public keys + + client.InvokePrmOptional +} + +func (x *commonBindArgs) SetOptionalPrm(prm client.InvokePrmOptional) { + x.InvokePrmOptional = prm } // SetOwnerID sets NeoFS account identifier. @@ -41,6 +47,7 @@ func (x *Client) AddKeys(args AddKeysArgs) error { prm.SetMethod(x.addKeysMethod) prm.SetArgs(args.ownerID, args.keys) + prm.InvokePrmOptional = args.InvokePrmOptional err := x.client.Invoke(prm) if err != nil { @@ -57,6 +64,7 @@ func (x *Client) RemoveKeys(args RemoveKeysArgs) error { prm.SetMethod(x.removeKeysMethod) prm.SetArgs(args.ownerID, args.keys) + prm.InvokePrmOptional = args.InvokePrmOptional err := x.client.Invoke(prm) if err != nil { diff --git a/pkg/morph/client/neofsid/wrapper/keys.go b/pkg/morph/client/neofsid/wrapper/keys.go index 88467607..7fda1654 100644 --- a/pkg/morph/client/neofsid/wrapper/keys.go +++ b/pkg/morph/client/neofsid/wrapper/keys.go @@ -4,16 +4,28 @@ import ( "crypto/elliptic" "fmt" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid" "github.com/nspcc-dev/neofs-sdk-go/owner" ) +// AccountKeysPrm groups parameters of AccountKeys operation. +type AccountKeysPrm struct { + id *owner.ID +} + +// SetID sets owner ID. +func (a *AccountKeysPrm) SetID(id *owner.ID) { + a.id = id +} + // AccountKeys requests public keys of NeoFS account from NeoFS ID contract. -func (x *ClientWrapper) AccountKeys(id *owner.ID) (keys.PublicKeys, error) { +func (x *ClientWrapper) AccountKeys(prm AccountKeysPrm) (keys.PublicKeys, error) { var args neofsid.KeyListingArgs - args.SetOwnerID(id.ToV2().GetValue()) + args.SetOwnerID(prm.id.ToV2().GetValue()) res, err := x.client.AccountKeys(args) if err != nil { @@ -37,11 +49,36 @@ func (x *ClientWrapper) AccountKeys(id *owner.ID) (keys.PublicKeys, error) { return ks, nil } +// ManageKeysPrm groups parameters of ManageKeys operation. +type ManageKeysPrm struct { + ownerID []byte + ks [][]byte + add bool + + client.InvokePrmOptional +} + +// SetOwnerID sets Owner ID. +func (m *ManageKeysPrm) SetOwnerID(ownerID []byte) { + m.ownerID = ownerID +} + +// SetKeys sets keys to add/remove. +func (m *ManageKeysPrm) SetKeys(ks [][]byte) { + m.ks = ks +} + +// SetAdd sets operation type. +func (m *ManageKeysPrm) SetAdd(add bool) { + m.add = add +} + // ManageKeys adds/removes list of public keys to/from NeoFS account. -func (x *ClientWrapper) ManageKeys(ownerID []byte, ks [][]byte, add bool) error { +func (x *ClientWrapper) ManageKeys(prm ManageKeysPrm) error { type args interface { SetOwnerID([]byte) SetKeys([][]byte) + SetOptionalPrm(optional client.InvokePrmOptional) } var ( @@ -49,7 +86,7 @@ func (x *ClientWrapper) ManageKeys(ownerID []byte, ks [][]byte, add bool) error call func(args) error ) - if add { + if prm.add { a = new(neofsid.AddKeysArgs) call = func(a args) error { return x.client.AddKeys(*a.(*neofsid.AddKeysArgs)) @@ -61,8 +98,9 @@ func (x *ClientWrapper) ManageKeys(ownerID []byte, ks [][]byte, add bool) error } } - a.SetOwnerID(ownerID) - a.SetKeys(ks) + a.SetOwnerID(prm.ownerID) + a.SetKeys(prm.ks) + a.SetOptionalPrm(prm.InvokePrmOptional) return call(a) }