[#971] morph/neofsid: Add optional parameters

Add optional parameters to the client call
signature.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-11-11 10:39:01 +03:00 committed by Alex Vanin
parent bad739258e
commit 404c62c5c4
2 changed files with 52 additions and 6 deletions

View file

@ -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 {

View file

@ -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)
}