2021-12-01 12:27:29 +00:00
|
|
|
package morphsubnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
2021-12-01 12:27:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// UserAllowedPrm groups parameters of UserAllowed method of Subnet contract.
|
|
|
|
type UserAllowedPrm struct {
|
2023-02-21 11:42:45 +00:00
|
|
|
args [2]any
|
2021-12-01 12:27:29 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// SetID sets identifier of the subnet in a binary FrostFS API protocol format.
|
2021-12-01 12:27:29 +00:00
|
|
|
func (x *UserAllowedPrm) SetID(id []byte) {
|
|
|
|
x.args[0] = id
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// SetClient sets owner ID of the client that is being checked in a binary FrostFS API protocol format.
|
2021-12-01 12:27:29 +00:00
|
|
|
func (x *UserAllowedPrm) SetClient(id []byte) {
|
|
|
|
x.args[1] = id
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// UserAllowedRes groups the resulting values of UserAllowed method of Subnet contract.
|
2021-12-01 12:27:29 +00:00
|
|
|
type UserAllowedRes struct {
|
|
|
|
result bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed returns true iff the client is allowed to create containers in the subnet.
|
|
|
|
func (x UserAllowedRes) Allowed() bool {
|
|
|
|
return x.result
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserAllowed checks if the user has access to the subnetwork.
|
|
|
|
func (x *Client) UserAllowed(prm UserAllowedPrm) (*UserAllowedRes, error) {
|
|
|
|
args := client.TestInvokePrm{}
|
|
|
|
|
2022-01-29 13:06:36 +00:00
|
|
|
args.SetMethod(userAllowedMethod)
|
2021-12-01 12:27:29 +00:00
|
|
|
args.SetArgs(prm.args[:]...)
|
|
|
|
|
|
|
|
res, err := x.client.TestInvoke(args)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not make test invoke: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(res) == 0 {
|
|
|
|
return nil, errEmptyResponse
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := client.BoolFromStackItem(res[0])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &UserAllowedRes{
|
|
|
|
result: result,
|
|
|
|
}, nil
|
|
|
|
}
|
2021-11-28 15:48:32 +00:00
|
|
|
|
|
|
|
// ManageClientsPrm groups parameters of client management in Subnet contract.
|
|
|
|
//
|
|
|
|
// Zero value adds subnet client. Subnet, group and client ID must be specified via setters.
|
|
|
|
type ManageClientsPrm struct {
|
|
|
|
// remove or add client
|
|
|
|
rm bool
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
args [3]any
|
2021-11-28 15:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetRemove marks client to be removed. By default, client is added.
|
|
|
|
func (x *ManageClientsPrm) SetRemove() {
|
|
|
|
x.rm = 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 *ManageClientsPrm) SetSubnet(id []byte) {
|
|
|
|
x.args[0] = id
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func (x *ManageClientsPrm) SetGroup(id []byte) {
|
|
|
|
x.args[1] = id
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// SetClient sets client's user ID in a binary FrostFS API protocol format.
|
2021-11-28 15:48:32 +00:00
|
|
|
func (x *ManageClientsPrm) SetClient(id []byte) {
|
|
|
|
x.args[2] = id
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ManageClientsRes groups the resulting values of client management methods of Subnet contract.
|
2021-11-28 15:48:32 +00:00
|
|
|
type ManageClientsRes struct{}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// ManageClients manages client list of the FrostFS subnet through Subnet contract calls.
|
2021-11-28 15:48:32 +00:00
|
|
|
func (x Client) ManageClients(prm ManageClientsPrm) (*ManageClientsRes, error) {
|
|
|
|
var method string
|
|
|
|
|
|
|
|
if prm.rm {
|
2022-01-29 13:06:36 +00:00
|
|
|
method = removeUserMethod
|
2021-11-28 15:48:32 +00:00
|
|
|
} else {
|
2022-01-29 13:06:36 +00:00
|
|
|
method = addUserMethod
|
2021-11-28 15:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var prmInvoke client.InvokePrm
|
|
|
|
|
|
|
|
prmInvoke.SetMethod(method)
|
|
|
|
prmInvoke.SetArgs(prm.args[:]...)
|
|
|
|
|
|
|
|
err := x.client.Invoke(prmInvoke)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return new(ManageClientsRes), nil
|
|
|
|
}
|