2023-01-10 13:01:54 +00:00
|
|
|
package frostfsid
|
2021-05-31 17:42:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-11-09 20:52:29 +00:00
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-05-31 17:42:32 +00:00
|
|
|
)
|
|
|
|
|
2022-01-31 11:04:59 +00:00
|
|
|
type CommonBindPrm struct {
|
2023-02-05 15:59:38 +00:00
|
|
|
ownerID []byte // FrostFS account identifier
|
2021-05-31 17:42:32 +00:00
|
|
|
|
|
|
|
keys [][]byte // list of serialized public keys
|
2021-11-11 07:39:01 +00:00
|
|
|
|
|
|
|
client.InvokePrmOptional
|
|
|
|
}
|
|
|
|
|
2022-01-31 11:04:59 +00:00
|
|
|
func (x *CommonBindPrm) SetOptionalPrm(prm client.InvokePrmOptional) {
|
2021-11-11 07:39:01 +00:00
|
|
|
x.InvokePrmOptional = prm
|
2021-05-31 17:42:32 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// SetOwnerID sets FrostFS account identifier.
|
2022-01-31 11:04:59 +00:00
|
|
|
func (x *CommonBindPrm) SetOwnerID(v []byte) {
|
2021-05-31 17:42:32 +00:00
|
|
|
x.ownerID = v
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetKeys sets a list of public keys in a binary format.
|
2022-01-31 11:04:59 +00:00
|
|
|
func (x *CommonBindPrm) SetKeys(v [][]byte) {
|
2021-05-31 17:42:32 +00:00
|
|
|
x.keys = v
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// AddKeys adds a list of public keys to/from FrostFS account.
|
2022-01-31 11:04:59 +00:00
|
|
|
func (x *Client) AddKeys(p CommonBindPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(addKeysMethod)
|
2022-01-31 11:04:59 +00:00
|
|
|
prm.SetArgs(p.ownerID, p.keys)
|
|
|
|
prm.InvokePrmOptional = p.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := x.client.Invoke(prm)
|
2021-05-31 17:42:32 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", addKeysMethod, err)
|
2021-05-31 17:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// RemoveKeys removes a list of public keys to/from FrostFS account.
|
2022-01-31 11:04:59 +00:00
|
|
|
func (x *Client) RemoveKeys(args CommonBindPrm) error {
|
2021-11-09 20:52:29 +00:00
|
|
|
prm := client.InvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
prm.SetMethod(removeKeysMethod)
|
2021-11-09 20:52:29 +00:00
|
|
|
prm.SetArgs(args.ownerID, args.keys)
|
2021-11-11 07:39:01 +00:00
|
|
|
prm.InvokePrmOptional = args.InvokePrmOptional
|
2021-11-09 20:52:29 +00:00
|
|
|
|
|
|
|
err := x.client.Invoke(prm)
|
2021-05-31 17:42:32 +00:00
|
|
|
if err != nil {
|
2022-01-29 13:06:36 +00:00
|
|
|
return fmt.Errorf("could not invoke method (%s): %w", removeKeysMethod, err)
|
2021-05-31 17:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|