2021-11-28 15:48:32 +00:00
|
|
|
package morphsubnet
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
import "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-11-28 15:48:32 +00:00
|
|
|
|
|
|
|
// ManageAdminsPrm groups parameters of administer methods of Subnet contract.
|
|
|
|
//
|
|
|
|
// Zero value adds node admin. Subnet, key and group must be specified via setters.
|
|
|
|
type ManageAdminsPrm struct {
|
|
|
|
// remove or add admin
|
|
|
|
rm bool
|
|
|
|
|
|
|
|
// client or node admin
|
|
|
|
client bool
|
|
|
|
|
|
|
|
subnet []byte
|
|
|
|
|
|
|
|
admin []byte
|
|
|
|
|
|
|
|
group []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRemove marks admin to be removed. By default, admin is added.
|
|
|
|
func (x *ManageAdminsPrm) SetRemove() {
|
|
|
|
x.rm = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetClient switches to client admin. By default, node admin is modified.
|
|
|
|
func (x *ManageAdminsPrm) SetClient() {
|
|
|
|
x.client = true
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// SetSubnet sets identifier of the subnet in a binary FrostFS API protocol format.
|
2021-11-28 15:48:32 +00:00
|
|
|
func (x *ManageAdminsPrm) SetSubnet(id []byte) {
|
|
|
|
x.subnet = id
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetAdmin sets admin's public key in a binary format.
|
|
|
|
func (x *ManageAdminsPrm) SetAdmin(key []byte) {
|
|
|
|
x.admin = key
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// SetGroup sets identifier of the client group in a binary FrostFS API protocol format.
|
2021-11-28 15:48:32 +00:00
|
|
|
// Makes sense only for client admins (see ManageAdminsPrm.SetClient).
|
|
|
|
func (x *ManageAdminsPrm) SetGroup(id []byte) {
|
|
|
|
x.group = id
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ManageAdminsRes groups the resulting values of node administer methods of Subnet contract.
|
2021-11-28 15:48:32 +00:00
|
|
|
type ManageAdminsRes struct{}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// ManageAdmins manages admin list of the FrostFS subnet through Subnet contract calls.
|
2021-11-28 15:48:32 +00:00
|
|
|
func (x Client) ManageAdmins(prm ManageAdminsPrm) (*ManageAdminsPrm, error) {
|
|
|
|
var method string
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
args := make([]any, 1, 3)
|
2021-11-28 15:48:32 +00:00
|
|
|
args[0] = prm.subnet
|
|
|
|
|
|
|
|
if prm.client {
|
|
|
|
args = append(args, prm.group, prm.admin)
|
|
|
|
|
|
|
|
if prm.rm {
|
2022-01-29 13:06:36 +00:00
|
|
|
method = removeClientAdminMethod
|
2021-11-28 15:48:32 +00:00
|
|
|
} else {
|
2022-01-29 13:06:36 +00:00
|
|
|
method = addClientAdminMethod
|
2021-11-28 15:48:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args = append(args, prm.admin)
|
|
|
|
|
|
|
|
if prm.rm {
|
2022-01-29 13:06:36 +00:00
|
|
|
method = removeNodeAdminMethod
|
2021-11-28 15:48:32 +00:00
|
|
|
} else {
|
2022-01-29 13:06:36 +00:00
|
|
|
method = addNodeAdminMethod
|
2021-11-28 15:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var prmInvoke client.InvokePrm
|
|
|
|
|
|
|
|
prmInvoke.SetMethod(method)
|
|
|
|
prmInvoke.SetArgs(args...)
|
|
|
|
|
|
|
|
err := x.client.Invoke(prmInvoke)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return new(ManageAdminsPrm), nil
|
|
|
|
}
|