2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-06-25 09:54:42 +00:00
|
|
|
"errors"
|
2022-04-05 11:13:34 +00:00
|
|
|
"fmt"
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2023-03-07 11:20:03 +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"
|
|
|
|
v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
|
|
|
|
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2021-11-09 08:07:49 +00:00
|
|
|
)
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmContainerPut groups parameters of ContainerPut operation.
|
|
|
|
type PrmContainerPut struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
cnrSet bool
|
|
|
|
cnr container.Container
|
2022-06-21 14:50:39 +00:00
|
|
|
|
|
|
|
sessionSet bool
|
|
|
|
session session.Container
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// SetContainer sets structured information about new FrostFS container.
|
2021-12-02 12:21:54 +00:00
|
|
|
// Required parameter.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmContainerPut) SetContainer(cnr container.Container) {
|
2021-12-02 12:21:54 +00:00
|
|
|
x.cnr = cnr
|
|
|
|
x.cnrSet = true
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 14:50:39 +00:00
|
|
|
// WithinSession specifies session within which container should be saved.
|
|
|
|
//
|
|
|
|
// Creator of the session acquires the authorship of the request. This affects
|
|
|
|
// the execution of an operation (e.g. access control).
|
|
|
|
//
|
|
|
|
// Session is optional, if set the following requirements apply:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - session operation MUST be session.VerbContainerPut (ForVerb)
|
|
|
|
// - token MUST be signed using private key of the owner of the container to be saved
|
2022-06-21 14:50:39 +00:00
|
|
|
func (x *PrmContainerPut) WithinSession(s session.Container) {
|
|
|
|
x.session = s
|
|
|
|
x.sessionSet = true
|
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResContainerPut groups resulting values of ContainerPut operation.
|
|
|
|
type ResContainerPut struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
id cid.ID
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// ID returns identifier of the container declared to be stored in the system.
|
|
|
|
// Used as a link to information about the container (in particular, you can
|
|
|
|
// asynchronously check if the save was successful).
|
2022-08-05 07:56:49 +00:00
|
|
|
func (x ResContainerPut) ID() cid.ID {
|
2021-11-16 18:17:25 +00:00
|
|
|
return x.id
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// ContainerPut sends request to save container in FrostFS.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
|
|
|
// The required time is also not predictable.
|
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Success can be verified by reading by identifier (see ResContainerPut.ID).
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmContainerPut docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResContainerPut, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContext
|
2021-12-02 12:21:54 +00:00
|
|
|
case !prm.cnrSet:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContainer
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// TODO: check private key is set before forming the request
|
2022-04-05 11:13:34 +00:00
|
|
|
// sign container
|
2022-06-25 09:54:42 +00:00
|
|
|
var cnr v2container.Container
|
|
|
|
prm.cnr.WriteToV2(&cnr)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
var sig frostfscrypto.Signature
|
2022-04-05 11:13:34 +00:00
|
|
|
|
2022-06-25 09:54:42 +00:00
|
|
|
err := container.CalculateSignature(&sig, prm.cnr, c.prm.key)
|
2021-11-09 08:07:49 +00:00
|
|
|
if err != nil {
|
2022-06-25 09:54:42 +00:00
|
|
|
return nil, fmt.Errorf("calculate container signature: %w", err)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 11:13:34 +00:00
|
|
|
var sigv2 refs.Signature
|
|
|
|
|
|
|
|
sig.WriteToV2(&sigv2)
|
|
|
|
|
|
|
|
// form request body
|
|
|
|
reqBody := new(v2container.PutRequestBody)
|
2022-06-25 09:54:42 +00:00
|
|
|
reqBody.SetContainer(&cnr)
|
2022-04-05 11:13:34 +00:00
|
|
|
reqBody.SetSignature(&sigv2)
|
2022-02-24 11:45:52 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form meta header
|
|
|
|
var meta v2session.RequestMetaHeader
|
2022-08-23 17:55:00 +00:00
|
|
|
writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-06-21 14:50:39 +00:00
|
|
|
if prm.sessionSet {
|
2022-04-07 16:09:15 +00:00
|
|
|
var tokv2 v2session.Token
|
2022-06-21 14:50:39 +00:00
|
|
|
prm.session.WriteToV2(&tokv2)
|
2022-04-07 16:09:15 +00:00
|
|
|
|
|
|
|
meta.SetSessionToken(&tokv2)
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2container.PutRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(&meta)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResContainerPut
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.PutContainer(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2container.PutResponse)
|
2022-04-11 16:25:14 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
const fieldCnrID = "container ID"
|
2022-04-11 16:25:14 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
cidV2 := resp.GetBody().GetContainerID()
|
|
|
|
if cidV2 == nil {
|
|
|
|
cc.err = newErrMissingResponseField(fieldCnrID)
|
|
|
|
return
|
2022-04-11 16:25:14 +00:00
|
|
|
}
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
cc.err = res.id.ReadFromV2(*cidV2)
|
|
|
|
if cc.err != nil {
|
|
|
|
cc.err = newErrInvalidResponseField(fieldCnrID, cc.err)
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmContainerGet groups parameters of ContainerGet operation.
|
|
|
|
type PrmContainerGet struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
idSet bool
|
|
|
|
id cid.ID
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetContainer sets identifier of the container to be read.
|
|
|
|
// Required parameter.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmContainerGet) SetContainer(id cid.ID) {
|
2021-12-02 12:21:54 +00:00
|
|
|
x.id = id
|
|
|
|
x.idSet = true
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResContainerGet groups resulting values of ContainerGet operation.
|
|
|
|
type ResContainerGet struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
|
|
|
|
2022-06-25 09:54:42 +00:00
|
|
|
cnr container.Container
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// Container returns structured information about the requested container.
|
|
|
|
//
|
|
|
|
// Client doesn't retain value so modification is safe.
|
2022-06-25 09:54:42 +00:00
|
|
|
func (x ResContainerGet) Container() container.Container {
|
2021-11-16 18:17:25 +00:00
|
|
|
return x.cnr
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// ContainerGet reads FrostFS container by ID.
|
2021-11-09 08:07:49 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmContainerGet docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
2022-02-28 10:56:46 +00:00
|
|
|
// - global (see Client docs);
|
|
|
|
// - *apistatus.ContainerNotFound.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) ContainerGet(ctx context.Context, prm PrmContainerGet) (*ResContainerGet, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContext
|
2021-12-02 12:21:54 +00:00
|
|
|
case !prm.idSet:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContainer
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 16:25:14 +00:00
|
|
|
var cidV2 refs.ContainerID
|
|
|
|
prm.id.WriteToV2(&cidV2)
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.GetRequestBody)
|
2022-04-11 16:25:14 +00:00
|
|
|
reqBody.SetContainerID(&cidV2)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2container.GetRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
req.SetBody(reqBody)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResContainerGet
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.GetContainer(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2container.GetResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-06-25 09:54:42 +00:00
|
|
|
cnrV2 := resp.GetBody().GetContainer()
|
|
|
|
if cnrV2 == nil {
|
|
|
|
cc.err = errors.New("missing container in response")
|
|
|
|
return
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
cc.err = res.cnr.ReadFromV2(*cnrV2)
|
|
|
|
if cc.err != nil {
|
|
|
|
cc.err = fmt.Errorf("invalid container in response: %w", cc.err)
|
2022-06-25 09:54:42 +00:00
|
|
|
}
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmContainerList groups parameters of ContainerList operation.
|
|
|
|
type PrmContainerList struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
ownerSet bool
|
2022-04-11 06:30:22 +00:00
|
|
|
ownerID user.ID
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// SetAccount sets identifier of the FrostFS account to list the containers.
|
2022-04-11 06:30:22 +00:00
|
|
|
// Required parameter.
|
|
|
|
func (x *PrmContainerList) SetAccount(id user.ID) {
|
2021-12-02 12:21:54 +00:00
|
|
|
x.ownerID = id
|
|
|
|
x.ownerSet = true
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResContainerList groups resulting values of ContainerList operation.
|
|
|
|
type ResContainerList struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-03-11 09:16:08 +00:00
|
|
|
ids []cid.ID
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// Containers returns list of identifiers of the account-owned containers.
|
|
|
|
//
|
|
|
|
// Client doesn't retain value so modification is safe.
|
2022-03-11 09:16:08 +00:00
|
|
|
func (x ResContainerList) Containers() []cid.ID {
|
2021-11-16 18:17:25 +00:00
|
|
|
return x.ids
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ContainerList requests identifiers of the account-owned containers.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmContainerList docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResContainerList, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContext
|
2021-12-02 12:21:54 +00:00
|
|
|
case !prm.ownerSet:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorAccountNotSet
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// form request body
|
2022-04-11 06:30:22 +00:00
|
|
|
var ownerV2 refs.OwnerID
|
|
|
|
prm.ownerID.WriteToV2(&ownerV2)
|
|
|
|
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.ListRequestBody)
|
2022-04-11 06:30:22 +00:00
|
|
|
reqBody.SetOwnerID(&ownerV2)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2container.ListRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
req.SetBody(reqBody)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResContainerList
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.ListContainers(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2container.ListResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
res.ids = make([]cid.ID, len(resp.GetBody().GetContainerIDs()))
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-03-11 09:16:08 +00:00
|
|
|
for i, cidV2 := range resp.GetBody().GetContainerIDs() {
|
2022-08-05 07:56:49 +00:00
|
|
|
cc.err = res.ids[i].ReadFromV2(cidV2)
|
|
|
|
if cc.err != nil {
|
|
|
|
cc.err = fmt.Errorf("invalid ID in the response: %w", cc.err)
|
|
|
|
return
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmContainerDelete groups parameters of ContainerDelete operation.
|
|
|
|
type PrmContainerDelete struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
idSet bool
|
|
|
|
id cid.ID
|
2022-04-07 16:09:15 +00:00
|
|
|
|
|
|
|
tokSet bool
|
|
|
|
tok session.Container
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// SetContainer sets identifier of the FrostFS container to be removed.
|
2021-12-02 12:21:54 +00:00
|
|
|
// Required parameter.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmContainerDelete) SetContainer(id cid.ID) {
|
2021-12-02 12:21:54 +00:00
|
|
|
x.id = id
|
|
|
|
x.idSet = true
|
|
|
|
}
|
|
|
|
|
2022-04-07 16:09:15 +00:00
|
|
|
// WithinSession specifies session within which container should be removed.
|
|
|
|
//
|
|
|
|
// Creator of the session acquires the authorship of the request.
|
|
|
|
// This may affect the execution of an operation (e.g. access control).
|
|
|
|
//
|
|
|
|
// Must be signed.
|
|
|
|
func (x *PrmContainerDelete) WithinSession(tok session.Container) {
|
|
|
|
x.tok = tok
|
|
|
|
x.tokSet = true
|
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResContainerDelete groups resulting values of ContainerDelete operation.
|
|
|
|
type ResContainerDelete struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// ContainerDelete sends request to remove the FrostFS container.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
|
|
|
// The required time is also not predictable.
|
|
|
|
//
|
|
|
|
// Success can be verified by reading by identifier (see GetContainer).
|
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmContainerDelete docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-02-17 16:10:49 +00:00
|
|
|
// Exactly one return value is non-nil. Server status return is returned in ResContainerDelete.
|
2021-12-02 12:21:54 +00:00
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
2022-01-24 10:33:43 +00:00
|
|
|
//
|
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) ContainerDelete(ctx context.Context, prm PrmContainerDelete) (*ResContainerDelete, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContext
|
2021-12-02 12:21:54 +00:00
|
|
|
case !prm.idSet:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContainer
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 11:13:34 +00:00
|
|
|
// sign container ID
|
2022-04-11 16:25:14 +00:00
|
|
|
var cidV2 refs.ContainerID
|
|
|
|
prm.id.WriteToV2(&cidV2)
|
|
|
|
|
2022-05-04 11:58:46 +00:00
|
|
|
// container contract expects signature of container ID value
|
|
|
|
// don't get confused with stable marshaled protobuf container.ID structure
|
|
|
|
data := cidV2.GetValue()
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
var sig frostfscrypto.Signature
|
2022-04-05 11:13:34 +00:00
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
err := sig.Calculate(frostfsecdsa.SignerRFC6979(c.prm.key), data)
|
2021-11-09 08:07:49 +00:00
|
|
|
if err != nil {
|
2022-04-05 11:13:34 +00:00
|
|
|
return nil, fmt.Errorf("calculate signature: %w", err)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 11:13:34 +00:00
|
|
|
var sigv2 refs.Signature
|
|
|
|
|
|
|
|
sig.WriteToV2(&sigv2)
|
|
|
|
|
|
|
|
// form request body
|
|
|
|
reqBody := new(v2container.DeleteRequestBody)
|
|
|
|
reqBody.SetContainerID(&cidV2)
|
|
|
|
reqBody.SetSignature(&sigv2)
|
2022-02-24 11:45:52 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form meta header
|
|
|
|
var meta v2session.RequestMetaHeader
|
2022-08-23 17:55:00 +00:00
|
|
|
writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-04-07 16:09:15 +00:00
|
|
|
if prm.tokSet {
|
|
|
|
var tokv2 v2session.Token
|
|
|
|
prm.tok.WriteToV2(&tokv2)
|
|
|
|
|
|
|
|
meta.SetSessionToken(&tokv2)
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2container.DeleteRequest
|
|
|
|
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(&meta)
|
|
|
|
|
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResContainerDelete
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.DeleteContainer(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmContainerEACL groups parameters of ContainerEACL operation.
|
|
|
|
type PrmContainerEACL struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
idSet bool
|
|
|
|
id cid.ID
|
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// SetContainer sets identifier of the FrostFS container to read the eACL table.
|
2021-12-02 12:21:54 +00:00
|
|
|
// Required parameter.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmContainerEACL) SetContainer(id cid.ID) {
|
2021-12-02 12:21:54 +00:00
|
|
|
x.id = id
|
|
|
|
x.idSet = true
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResContainerEACL groups resulting values of ContainerEACL operation.
|
|
|
|
type ResContainerEACL struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
table eacl.Table
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// Table returns eACL table of the requested container.
|
2022-08-05 07:56:49 +00:00
|
|
|
func (x ResContainerEACL) Table() eacl.Table {
|
2021-11-16 18:17:25 +00:00
|
|
|
return x.table
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// ContainerEACL reads eACL table of the FrostFS container.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmContainerEACL docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
2022-02-28 10:56:46 +00:00
|
|
|
// - global (see Client docs);
|
2022-08-01 14:17:48 +00:00
|
|
|
// - *apistatus.ContainerNotFound;
|
|
|
|
// - *apistatus.EACLNotFound.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResContainerEACL, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContext
|
2021-12-02 12:21:54 +00:00
|
|
|
case !prm.idSet:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContainer
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 16:25:14 +00:00
|
|
|
var cidV2 refs.ContainerID
|
|
|
|
prm.id.WriteToV2(&cidV2)
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.GetExtendedACLRequestBody)
|
2022-04-11 16:25:14 +00:00
|
|
|
reqBody.SetContainerID(&cidV2)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2container.GetExtendedACLRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
req.SetBody(reqBody)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResContainerEACL
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.GetEACL(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2container.GetExtendedACLResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
eACL := resp.GetBody().GetEACL()
|
|
|
|
if eACL == nil {
|
|
|
|
cc.err = newErrMissingResponseField("eACL")
|
|
|
|
return
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
res.table = *eacl.NewTableFromV2(eACL)
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmContainerSetEACL groups parameters of ContainerSetEACL operation.
|
|
|
|
type PrmContainerSetEACL struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
tableSet bool
|
|
|
|
table eacl.Table
|
2022-06-21 14:50:39 +00:00
|
|
|
|
|
|
|
sessionSet bool
|
|
|
|
session session.Container
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetTable sets eACL table structure to be set for the container.
|
|
|
|
// Required parameter.
|
2022-02-17 16:10:49 +00:00
|
|
|
func (x *PrmContainerSetEACL) SetTable(table eacl.Table) {
|
2021-12-02 12:21:54 +00:00
|
|
|
x.table = table
|
|
|
|
x.tableSet = true
|
|
|
|
}
|
|
|
|
|
2022-06-21 14:50:39 +00:00
|
|
|
// WithinSession specifies session within which extended ACL of the container
|
|
|
|
// should be saved.
|
|
|
|
//
|
|
|
|
// Creator of the session acquires the authorship of the request. This affects
|
|
|
|
// the execution of an operation (e.g. access control).
|
|
|
|
//
|
|
|
|
// Session is optional, if set the following requirements apply:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - if particular container is specified (ApplyOnlyTo), it MUST equal the container
|
|
|
|
// for which extended ACL is going to be set
|
|
|
|
// - session operation MUST be session.VerbContainerSetEACL (ForVerb)
|
|
|
|
// - token MUST be signed using private key of the owner of the container to be saved
|
2022-06-21 14:50:39 +00:00
|
|
|
func (x *PrmContainerSetEACL) WithinSession(s session.Container) {
|
|
|
|
x.session = s
|
|
|
|
x.sessionSet = true
|
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResContainerSetEACL groups resulting values of ContainerSetEACL operation.
|
|
|
|
type ResContainerSetEACL struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// ContainerSetEACL sends request to update eACL table of the FrostFS container.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
|
|
|
// The required time is also not predictable.
|
|
|
|
//
|
|
|
|
// Success can be verified by reading by identifier (see EACL).
|
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmContainerSetEACL docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) ContainerSetEACL(ctx context.Context, prm PrmContainerSetEACL) (*ResContainerSetEACL, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContext
|
2021-12-02 12:21:54 +00:00
|
|
|
case !prm.tableSet:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorEACLTableNotSet
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sign the eACL table
|
2022-04-05 11:13:34 +00:00
|
|
|
eaclV2 := prm.table.ToV2()
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
var sig frostfscrypto.Signature
|
2022-04-05 11:13:34 +00:00
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
err := sig.Calculate(frostfsecdsa.SignerRFC6979(c.prm.key), eaclV2.StableMarshal(nil))
|
2022-04-05 11:13:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("calculate signature: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var sigv2 refs.Signature
|
|
|
|
|
|
|
|
sig.WriteToV2(&sigv2)
|
|
|
|
|
|
|
|
// form request body
|
|
|
|
reqBody := new(v2container.SetExtendedACLRequestBody)
|
|
|
|
reqBody.SetEACL(eaclV2)
|
|
|
|
reqBody.SetSignature(&sigv2)
|
2022-02-24 11:45:52 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form meta header
|
|
|
|
var meta v2session.RequestMetaHeader
|
2022-08-23 17:55:00 +00:00
|
|
|
writeXHeadersToMeta(prm.prmCommonMeta.xHeaders, &meta)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2022-06-21 14:50:39 +00:00
|
|
|
if prm.sessionSet {
|
2022-04-07 16:09:15 +00:00
|
|
|
var tokv2 v2session.Token
|
2022-06-21 14:50:39 +00:00
|
|
|
prm.session.WriteToV2(&tokv2)
|
2022-04-07 16:09:15 +00:00
|
|
|
|
|
|
|
meta.SetSessionToken(&tokv2)
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2container.SetExtendedACLRequest
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(&meta)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResContainerSetEACL
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.SetEACL(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// PrmAnnounceSpace groups parameters of ContainerAnnounceUsedSpace operation.
|
|
|
|
type PrmAnnounceSpace struct {
|
2022-03-03 11:04:53 +00:00
|
|
|
prmCommonMeta
|
|
|
|
|
2022-06-25 09:54:42 +00:00
|
|
|
announcements []container.SizeEstimation
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetValues sets values describing volume of space that is used for the container objects.
|
|
|
|
// Required parameter. Must not be empty.
|
|
|
|
//
|
|
|
|
// Must not be mutated before the end of the operation.
|
2022-06-25 09:54:42 +00:00
|
|
|
func (x *PrmAnnounceSpace) SetValues(vs []container.SizeEstimation) {
|
|
|
|
x.announcements = vs
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ResAnnounceSpace groups resulting values of ContainerAnnounceUsedSpace operation.
|
|
|
|
type ResAnnounceSpace struct {
|
2021-11-16 18:17:25 +00:00
|
|
|
statusRes
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:10:49 +00:00
|
|
|
// ContainerAnnounceUsedSpace sends request to announce volume of the space used for the container objects.
|
2021-12-29 13:55:29 +00:00
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
2022-01-11 12:44:22 +00:00
|
|
|
// Any client's internal or transport errors are returned as `error`.
|
2022-12-29 10:46:18 +00:00
|
|
|
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
|
|
|
// FrostFS status codes are returned as `error`, otherwise, are included
|
2022-01-11 12:44:22 +00:00
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
|
|
|
// The required time is also not predictable.
|
|
|
|
//
|
|
|
|
// At this moment success can not be checked.
|
|
|
|
//
|
2023-02-27 07:53:27 +00:00
|
|
|
// Returns an error if parameters are set incorrectly (see PrmAnnounceSpace docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
2022-08-24 14:17:40 +00:00
|
|
|
// - global (see Client docs).
|
2022-02-17 16:10:49 +00:00
|
|
|
func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounceSpace) (*ResAnnounceSpace, error) {
|
2021-12-02 12:21:54 +00:00
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingContext
|
2021-12-02 12:21:54 +00:00
|
|
|
case len(prm.announcements) == 0:
|
2023-02-27 07:53:27 +00:00
|
|
|
return nil, errorMissingAnnouncements
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// convert list of SDK announcement structures into FrostFS-API v2 list
|
2022-03-11 09:16:08 +00:00
|
|
|
v2announce := make([]v2container.UsedSpaceAnnouncement, len(prm.announcements))
|
2021-12-02 12:21:54 +00:00
|
|
|
for i := range prm.announcements {
|
2022-06-25 09:54:42 +00:00
|
|
|
prm.announcements[i].WriteToV2(&v2announce[i])
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
// prepare body of the FrostFS-API v2 request and request itself
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.AnnounceUsedSpaceRequestBody)
|
|
|
|
reqBody.SetAnnouncements(v2announce)
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request
|
|
|
|
var req v2container.AnnounceUsedSpaceRequest
|
|
|
|
|
2021-11-09 08:07:49 +00:00
|
|
|
req.SetBody(reqBody)
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// init call context
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
2021-12-02 12:21:54 +00:00
|
|
|
cc contextCall
|
2022-02-17 16:10:49 +00:00
|
|
|
res ResAnnounceSpace
|
2021-11-16 18:17:25 +00:00
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
c.initCallContext(&cc)
|
2022-03-03 11:04:53 +00:00
|
|
|
cc.meta = prm.prmCommonMeta
|
2021-12-02 12:21:54 +00:00
|
|
|
cc.req = &req
|
|
|
|
cc.statusRes = &res
|
|
|
|
cc.call = func() (responseV2, error) {
|
2022-03-07 11:39:49 +00:00
|
|
|
return rpcapi.AnnounceUsedSpace(&c.c, &req, client.WithContext(ctx))
|
2021-12-02 12:21:54 +00:00
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// process call
|
|
|
|
if !cc.processCall() {
|
|
|
|
return nil, cc.err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
return &res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
2022-04-26 15:03:14 +00:00
|
|
|
|
|
|
|
// SyncContainerWithNetwork requests network configuration using passed client
|
|
|
|
// and applies it to the container. Container MUST not be nil.
|
|
|
|
//
|
|
|
|
// Note: if container does not match network configuration, SyncContainerWithNetwork
|
|
|
|
// changes it.
|
|
|
|
//
|
|
|
|
// Returns any network/parsing config errors.
|
|
|
|
//
|
|
|
|
// See also NetworkInfo, container.ApplyNetworkConfig.
|
|
|
|
func SyncContainerWithNetwork(ctx context.Context, cnr *container.Container, c *Client) error {
|
|
|
|
res, err := c.NetworkInfo(ctx, PrmNetworkInfo{})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("network info call: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-08-05 07:56:49 +00:00
|
|
|
container.ApplyNetworkConfig(cnr, res.Info())
|
2022-04-26 15:03:14 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|