2023-04-13 05:15:20 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-04-13 06:00:00 +00:00
|
|
|
"fmt"
|
2023-04-13 05:15:20 +00:00
|
|
|
|
|
|
|
v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
|
|
|
|
rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
2023-04-13 06:00:00 +00:00
|
|
|
v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature"
|
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
2023-04-13 05:15:20 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PrmContainerEACL groups parameters of ContainerEACL operation.
|
|
|
|
type PrmContainerEACL struct {
|
2023-08-11 07:33:06 +00:00
|
|
|
// FrostFS request X-Headers.
|
|
|
|
XHeaders []string
|
2023-04-13 05:15:20 +00:00
|
|
|
|
2023-08-11 07:33:06 +00:00
|
|
|
ContainerID *cid.ID
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetContainer sets identifier of the FrostFS container to read the eACL table.
|
|
|
|
// Required parameter.
|
2023-08-11 07:33:06 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use PrmContainerEACL.ContainerID instead.
|
2023-04-13 05:15:20 +00:00
|
|
|
func (x *PrmContainerEACL) SetContainer(id cid.ID) {
|
2023-08-11 07:33:06 +00:00
|
|
|
x.ContainerID = &id
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-17 07:31:07 +00:00
|
|
|
func (x *PrmContainerEACL) buildRequest(c *Client) (*v2container.GetExtendedACLRequest, error) {
|
2023-08-11 07:33:06 +00:00
|
|
|
if x.ContainerID == nil {
|
2023-04-13 05:33:17 +00:00
|
|
|
return nil, errorMissingContainer
|
|
|
|
}
|
|
|
|
|
2023-08-11 07:33:06 +00:00
|
|
|
if len(x.XHeaders)%2 != 0 {
|
|
|
|
return nil, errorInvalidXHeaders
|
|
|
|
}
|
|
|
|
|
2023-04-13 05:33:17 +00:00
|
|
|
var cidV2 refs.ContainerID
|
2023-08-11 07:33:06 +00:00
|
|
|
x.ContainerID.WriteToV2(&cidV2)
|
2023-04-13 05:33:17 +00:00
|
|
|
|
|
|
|
reqBody := new(v2container.GetExtendedACLRequestBody)
|
|
|
|
reqBody.SetContainerID(&cidV2)
|
|
|
|
|
|
|
|
var req v2container.GetExtendedACLRequest
|
|
|
|
req.SetBody(reqBody)
|
2023-04-13 06:00:00 +00:00
|
|
|
c.prepareRequest(&req, new(v2session.RequestMetaHeader))
|
2023-04-13 05:33:17 +00:00
|
|
|
return &req, nil
|
|
|
|
}
|
|
|
|
|
2023-04-13 05:15:20 +00:00
|
|
|
// ResContainerEACL groups resulting values of ContainerEACL operation.
|
|
|
|
type ResContainerEACL struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
table eacl.Table
|
|
|
|
}
|
|
|
|
|
|
|
|
// Table returns eACL table of the requested container.
|
|
|
|
func (x ResContainerEACL) Table() eacl.Table {
|
|
|
|
return x.table
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContainerEACL reads eACL table of the FrostFS container.
|
|
|
|
//
|
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2023-09-15 15:52:08 +00:00
|
|
|
// If PrmInit.DisableFrostFSFailuresResolution has been called, unsuccessful
|
2023-09-12 15:57:04 +00:00
|
|
|
// FrostFS status codes are included in the returned result structure,
|
|
|
|
// otherwise, are also returned as `error`.
|
2023-04-13 05:15:20 +00:00
|
|
|
//
|
|
|
|
// Returns an error if parameters are set incorrectly (see PrmContainerEACL docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs);
|
|
|
|
// - *apistatus.ContainerNotFound;
|
|
|
|
// - *apistatus.EACLNotFound.
|
|
|
|
func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) {
|
2023-04-17 07:31:07 +00:00
|
|
|
req, err := prm.buildRequest(c)
|
2023-04-13 05:33:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 06:00:00 +00:00
|
|
|
if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
|
|
|
|
return nil, fmt.Errorf("sign request: %w", err)
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 06:00:00 +00:00
|
|
|
resp, err := rpcapi.GetEACL(&c.c, req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-04-13 05:15:20 +00:00
|
|
|
|
2023-04-13 06:00:00 +00:00
|
|
|
var res ResContainerEACL
|
|
|
|
res.st, err = c.processResponse(resp)
|
|
|
|
if err != nil || !apistatus.IsSuccessful(res.st) {
|
|
|
|
return &res, err
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 06:00:00 +00:00
|
|
|
eACL := resp.GetBody().GetEACL()
|
|
|
|
if eACL == nil {
|
|
|
|
return &res, newErrMissingResponseField("eACL")
|
2023-04-13 05:15:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-13 06:00:00 +00:00
|
|
|
res.table = *eacl.NewTableFromV2(eACL)
|
2023-04-13 05:15:20 +00:00
|
|
|
return &res, nil
|
|
|
|
}
|