[#233] pool: Introduce ape-manager methods
All checks were successful
DCO / DCO (pull_request) Successful in 1m26s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m21s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m33s
Tests and linters / Lint (pull_request) Successful in 2m20s

* Remove GetEACL, SetEACL methods as they are deprecated;
* Fix mock;
* Introduce add/remove/list methods to request ape-manager from
  the client.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2024-07-03 17:20:58 +03:00
parent 1a5886e776
commit 27e965007d
2 changed files with 167 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import (
sessionv2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/ape"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
@ -103,6 +104,18 @@ func (m *mockClient) containerSetEACL(context.Context, PrmContainerSetEACL) erro
return nil
}
func (c *mockClient) apeManagerAddChain(ctx context.Context, prm PrmAddAPEChain) error {
return nil
}
func (c *mockClient) apeManagerRemoveChain(ctx context.Context, prm PrmRemoveAPEChain) error {
return nil
}
func (c *mockClient) apeManagerListChains(ctx context.Context, prm PrmListAPEChains) ([]ape.Chain, error) {
return []ape.Chain{}, nil
}
func (m *mockClient) endpointInfo(ctx context.Context, _ prmEndpointInfo) (netmap.NodeInfo, error) {
var ni netmap.NodeInfo

View file

@ -15,6 +15,7 @@ import (
"time"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/ape"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
sdkClient "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
@ -53,6 +54,12 @@ type client interface {
containerEACL(context.Context, PrmContainerEACL) (eacl.Table, error)
// see clientWrapper.containerSetEACL.
containerSetEACL(context.Context, PrmContainerSetEACL) error
// see clientWrapper.apeManagerAddChain.
apeManagerAddChain(context.Context, PrmAddAPEChain) error
// see clientWrapper.apeManagerRemoveChain.
apeManagerRemoveChain(context.Context, PrmRemoveAPEChain) error
// see clientWrapper.apeManagerListChains.
apeManagerListChains(context.Context, PrmListAPEChains) ([]ape.Chain, error)
// see clientWrapper.endpointInfo.
endpointInfo(context.Context, prmEndpointInfo) (netmap.NodeInfo, error)
// see clientWrapper.networkInfo.
@ -169,6 +176,9 @@ const (
methodObjectHead
methodObjectRange
methodSessionCreate
methodAPEManagerAddChain
methodAPEManagerRemoveChain
methodAPEManagerListChains
methodLast
)
@ -207,6 +217,12 @@ func (m MethodIndex) String() string {
return "objectRange"
case methodSessionCreate:
return "sessionCreate"
case methodAPEManagerAddChain:
return "apeManagerAddChain"
case methodAPEManagerRemoveChain:
return "apeManagerRemoveChain"
case methodAPEManagerListChains:
return "apeManagerListChains"
case methodLast:
return "it's a system name rather than a method"
default:
@ -641,6 +657,83 @@ func (c *clientWrapper) containerSetEACL(ctx context.Context, prm PrmContainerSe
return nil
}
// apeManagerAddChain invokes sdkClient.APEManagerAddChain and parse response status to error.
func (c *clientWrapper) apeManagerAddChain(ctx context.Context, prm PrmAddAPEChain) error {
cl, err := c.getClient()
if err != nil {
return err
}
cliPrm := sdkClient.PrmAPEManagerAddChain{
ChainTarget: prm.Target,
Chain: prm.Chain,
}
start := time.Now()
res, err := cl.APEManagerAddChain(ctx, cliPrm)
c.incRequests(time.Since(start), methodAPEManagerAddChain)
var st apistatus.Status
if res != nil {
st = res.Status()
}
if err = c.handleError(ctx, st, err); err != nil {
return fmt.Errorf("add chain error: %w", err)
}
return nil
}
// apeManagerRemoveChain invokes sdkClient.APEManagerRemoveChain and parse response status to error.
func (c *clientWrapper) apeManagerRemoveChain(ctx context.Context, prm PrmRemoveAPEChain) error {
cl, err := c.getClient()
if err != nil {
return err
}
cliPrm := sdkClient.PrmAPEManagerRemoveChain{
ChainTarget: prm.Target,
ChainID: prm.ChainID,
}
start := time.Now()
res, err := cl.APEManagerRemoveChain(ctx, cliPrm)
c.incRequests(time.Since(start), methodAPEManagerRemoveChain)
var st apistatus.Status
if res != nil {
st = res.Status()
}
if err = c.handleError(ctx, st, err); err != nil {
return fmt.Errorf("remove chain error: %w", err)
}
return nil
}
// apeManagerListChains invokes sdkClient.APEManagerListChains. Returns chains and parsed response status to error.
func (c *clientWrapper) apeManagerListChains(ctx context.Context, prm PrmListAPEChains) ([]ape.Chain, error) {
cl, err := c.getClient()
if err != nil {
return nil, err
}
cliPrm := sdkClient.PrmAPEManagerListChains{
ChainTarget: prm.Target,
}
start := time.Now()
res, err := cl.APEManagerListChains(ctx, cliPrm)
c.incRequests(time.Since(start), methodAPEManagerListChains)
var st apistatus.Status
if res != nil {
st = res.Status()
}
if err = c.handleError(ctx, st, err); err != nil {
return nil, fmt.Errorf("list chains error: %w", err)
}
return res.Chains, nil
}
// endpointInfo invokes sdkClient.EndpointInfo parse response status to error and return result as is.
func (c *clientWrapper) endpointInfo(ctx context.Context, _ prmEndpointInfo) (netmap.NodeInfo, error) {
cl, err := c.getClient()
@ -1723,6 +1816,22 @@ type PrmContainerSetEACL struct {
WaitParams *WaitParams
}
type PrmAddAPEChain struct {
Target ape.ChainTarget
Chain ape.Chain
}
type PrmRemoveAPEChain struct {
Target ape.ChainTarget
ChainID ape.ChainID
}
type PrmListAPEChains struct {
Target ape.ChainTarget
}
// SetTable sets structure of container's extended ACL to be used as a
// parameter of the base client's operation.
//
@ -2727,6 +2836,51 @@ func (p *Pool) SetEACL(ctx context.Context, prm PrmContainerSetEACL) error {
return nil
}
// AddAPEChain sends a request to set APE chain rules for a target (basically, for a container).
func (p *Pool) AddAPEChain(ctx context.Context, prm PrmAddAPEChain) error {
cp, err := p.connection()
if err != nil {
return err
}
err = cp.apeManagerAddChain(ctx, prm)
if err != nil {
return fmt.Errorf("add ape chain via client '%s': %w", cp.address(), err)
}
return nil
}
// RemoveAPEChain sends a request to remove APE chain rules for a target.
func (p *Pool) RemoveAPEChain(ctx context.Context, prm PrmRemoveAPEChain) error {
cp, err := p.connection()
if err != nil {
return err
}
err = cp.apeManagerRemoveChain(ctx, prm)
if err != nil {
return fmt.Errorf("remove ape chain via client '%s': %w", cp.address(), err)
}
return nil
}
// ListAPEChains sends a request to list APE chains rules for a target.
func (p *Pool) ListAPEChains(ctx context.Context, prm PrmListAPEChains) ([]ape.Chain, error) {
cp, err := p.connection()
if err != nil {
return nil, err
}
chains, err := cp.apeManagerListChains(ctx, prm)
if err != nil {
return nil, fmt.Errorf("list ape chains via client '%s': %w", cp.address(), err)
}
return chains, nil
}
// Balance requests current balance of the FrostFS account.
//
// Main return value MUST NOT be processed on an erroneous return.