[#556] morph/neofsid: Add Client methods to add/remove keys

Implement `AddKeys` / `RemoveKeys` methods to call `addKey` / `removeKey`
methods of NeoFS ID contract.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-31 20:42:32 +03:00 committed by Alex Vanin
parent 8c2d42368a
commit 4713e6b2b8
2 changed files with 97 additions and 0 deletions

View file

@ -22,15 +22,21 @@ type Client struct {
type Option func(*cfg)
type cfg struct {
addKeysMethod,
removeKeysMethod,
keyListingMethod string
}
const (
defaultKeyListingMethod = "key" // default key listing method name
defaultAddKeysMethod = "addKey"
defaultRemoveKeysMethod = "removeKey"
)
func defaultConfig() *cfg {
return &cfg{
addKeysMethod: defaultAddKeysMethod,
removeKeysMethod: defaultRemoveKeysMethod,
keyListingMethod: defaultKeyListingMethod,
}
}
@ -76,3 +82,31 @@ func WithKeyListingMethod(n string) Option {
}
}
}
// WithAddKeysMethod returns a client constructor option that
// specifies the method name of adding key operation.
//
// Ignores empty value.
//
// If option not provided, "addKey" is used.
func WithAddKeysMethod(n string) Option {
return func(c *cfg) {
if n != "" {
c.addKeysMethod = n
}
}
}
// WithRemoveKeysMethod returns a client constructor option that
// specifies the method name of removing key operation.
//
// Ignores empty value.
//
// If option not provided, "removeKey" is used.
func WithRemoveKeysMethod(n string) Option {
return func(c *cfg) {
if n != "" {
c.removeKeysMethod = n
}
}
}