2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
v2container "github.com/nspcc-dev/neofs-api-go/v2/container"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
2021-11-16 18:15:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
2021-12-02 12:21:54 +00:00
|
|
|
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
|
2021-11-09 08:07:49 +00:00
|
|
|
v2signature "github.com/nspcc-dev/neofs-api-go/v2/signature"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/container"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/signature"
|
|
|
|
sigutil "github.com/nspcc-dev/neofs-sdk-go/util/signature"
|
|
|
|
)
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// ContainerPutPrm groups parameters of PutContainer operation.
|
|
|
|
type ContainerPutPrm struct {
|
|
|
|
cnrSet bool
|
|
|
|
cnr container.Container
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetContainer sets structured information about new NeoFS container.
|
|
|
|
// Required parameter.
|
|
|
|
func (x *ContainerPutPrm) SetContainer(cnr container.Container) {
|
|
|
|
x.cnr = cnr
|
|
|
|
x.cnrSet = true
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// ContainerPutRes groups resulting values of PutContainer operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type ContainerPutRes struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
id *cid.ID
|
|
|
|
}
|
|
|
|
|
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).
|
|
|
|
//
|
|
|
|
// Client doesn't retain value so modification is safe.
|
2021-11-16 18:17:25 +00:00
|
|
|
func (x ContainerPutRes) ID() *cid.ID {
|
|
|
|
return x.id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *ContainerPutRes) setID(id *cid.ID) {
|
|
|
|
x.id = id
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// PutContainer sends request to save container in NeoFS.
|
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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// 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 ContainerPutRes.ID).
|
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see ContainerPutPrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
func (c *Client) PutContainer(ctx context.Context, prm ContainerPutPrm) (*ContainerPutRes, error) {
|
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case !prm.cnrSet:
|
|
|
|
panic(panicMsgMissingContainer)
|
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
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.PutRequestBody)
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetContainer(prm.cnr.ToV2())
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
// sign container
|
|
|
|
signWrapper := v2signature.StableMarshalerWrapper{SM: reqBody.GetContainer()}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
err := sigutil.SignDataWithHandler(c.opts.key, signWrapper, func(key []byte, sig []byte) {
|
2021-11-09 08:07:49 +00:00
|
|
|
containerSignature := new(refs.Signature)
|
|
|
|
containerSignature.SetKey(key)
|
|
|
|
containerSignature.SetSign(sig)
|
|
|
|
reqBody.SetSignature(containerSignature)
|
|
|
|
}, sigutil.SignWithRFC6979())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form meta header
|
|
|
|
var meta v2session.RequestMetaHeader
|
2022-02-03 16:17:30 +00:00
|
|
|
meta.SetSessionToken(prm.cnr.SessionToken().ToV2())
|
2021-11-09 08:07:49 +00:00
|
|
|
|
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
|
|
|
|
res ContainerPutRes
|
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) {
|
|
|
|
return rpcapi.PutContainer(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2container.PutResponse)
|
|
|
|
res.setID(cid.NewFromV2(resp.GetBody().GetContainerID()))
|
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
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// ContainerGetPrm groups parameters of GetContainer operation.
|
|
|
|
type ContainerGetPrm struct {
|
|
|
|
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.
|
|
|
|
func (x *ContainerGetPrm) SetContainer(id cid.ID) {
|
|
|
|
x.id = id
|
|
|
|
x.idSet = true
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// ContainerGetRes groups resulting values of GetContainer operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type ContainerGetRes struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
cnr *container.Container
|
|
|
|
}
|
|
|
|
|
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.
|
2021-11-16 18:17:25 +00:00
|
|
|
func (x ContainerGetRes) Container() *container.Container {
|
|
|
|
return x.cnr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *ContainerGetRes) setContainer(cnr *container.Container) {
|
|
|
|
x.cnr = cnr
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 10:33:43 +00:00
|
|
|
// GetContainer reads NeoFS 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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see ContainerGetPrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
func (c *Client) GetContainer(ctx context.Context, prm ContainerGetPrm) (*ContainerGetRes, error) {
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case !prm.idSet:
|
|
|
|
panic(panicMsgMissingContainer)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.GetRequestBody)
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetContainerID(prm.id.ToV2())
|
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
|
|
|
|
res ContainerGetRes
|
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) {
|
|
|
|
return rpcapi.GetContainer(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2container.GetResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
body := resp.GetBody()
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
cnr := container.NewContainerFromV2(body.GetContainer())
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
cnr.SetSessionToken(
|
|
|
|
session.NewTokenFromV2(body.GetSessionToken()),
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
cnr.SetSignature(
|
|
|
|
signature.NewFromV2(body.GetSignature()),
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
res.setContainer(cnr)
|
|
|
|
}
|
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
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// ContainerListPrm groups parameters of ListContainers operation.
|
|
|
|
type ContainerListPrm struct {
|
|
|
|
ownerSet bool
|
|
|
|
ownerID owner.ID
|
|
|
|
}
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetAccount sets identifier of the NeoFS account to list the containers.
|
|
|
|
// Required parameter. Must be a valid ID according to NeoFS API protocol.
|
|
|
|
func (x *ContainerListPrm) SetAccount(id owner.ID) {
|
|
|
|
x.ownerID = id
|
|
|
|
x.ownerSet = true
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// ContainerListRes groups resulting values of ListContainers operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type ContainerListRes struct {
|
|
|
|
statusRes
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
ids []*cid.ID
|
|
|
|
}
|
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.
|
|
|
|
func (x ContainerListRes) Containers() []*cid.ID {
|
2021-11-16 18:17:25 +00:00
|
|
|
return x.ids
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
func (x *ContainerListRes) setContainers(ids []*cid.ID) {
|
2021-11-16 18:17:25 +00:00
|
|
|
x.ids = ids
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// ListContainers 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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see ContainerListPrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
func (c *Client) ListContainers(ctx context.Context, prm ContainerListPrm) (*ContainerListRes, error) {
|
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case !prm.ownerSet:
|
|
|
|
panic("account not set")
|
|
|
|
case !prm.ownerID.Valid():
|
|
|
|
panic("invalid account")
|
|
|
|
}
|
|
|
|
|
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.ListRequestBody)
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetOwnerID(prm.ownerID.ToV2())
|
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
|
|
|
|
res ContainerListRes
|
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) {
|
|
|
|
return rpcapi.ListContainers(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2container.ListResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
ids := make([]*cid.ID, 0, len(resp.GetBody().GetContainerIDs()))
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
for _, cidV2 := range resp.GetBody().GetContainerIDs() {
|
|
|
|
ids = append(ids, cid.NewFromV2(cidV2))
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
res.setContainers(ids)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContainerDeletePrm groups parameters of DeleteContainer operation.
|
|
|
|
type ContainerDeletePrm struct {
|
|
|
|
prmSession
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
idSet bool
|
|
|
|
id cid.ID
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetContainer sets identifier of the NeoFS container to be removed.
|
|
|
|
// Required parameter.
|
|
|
|
func (x *ContainerDeletePrm) SetContainer(id cid.ID) {
|
|
|
|
x.id = id
|
|
|
|
x.idSet = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContainerDeleteRes groups resulting values of DeleteContainer operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type ContainerDeleteRes struct {
|
|
|
|
statusRes
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// implements github.com/nspcc-dev/neofs-sdk-go/util/signature.DataSource.
|
|
|
|
type delContainerSignWrapper struct {
|
|
|
|
body *v2container.DeleteRequestBody
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c delContainerSignWrapper) ReadSignedData([]byte) ([]byte, error) {
|
|
|
|
return c.body.GetContainerID().GetValue(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c delContainerSignWrapper) SignedDataSize() int {
|
|
|
|
return len(c.body.GetContainerID().GetValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteContainer sends request to remove the NeoFS 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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// 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).
|
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see ContainerDeletePrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
|
|
|
// Exactly one return value is non-nil. Server status return is returned in ContainerDeleteRes.
|
|
|
|
// Reflects all internal errors in second return value (transport problems, response processing, etc.).
|
2022-01-24 10:33:43 +00:00
|
|
|
//
|
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
func (c *Client) DeleteContainer(ctx context.Context, prm ContainerDeletePrm) (*ContainerDeleteRes, error) {
|
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case !prm.idSet:
|
|
|
|
panic(panicMsgMissingContainer)
|
|
|
|
}
|
|
|
|
|
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.DeleteRequestBody)
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetContainerID(prm.id.ToV2())
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
// sign container
|
2021-12-02 12:21:54 +00:00
|
|
|
err := sigutil.SignDataWithHandler(c.opts.key,
|
2021-11-09 08:07:49 +00:00
|
|
|
delContainerSignWrapper{
|
|
|
|
body: reqBody,
|
|
|
|
},
|
|
|
|
func(key []byte, sig []byte) {
|
|
|
|
containerSignature := new(refs.Signature)
|
|
|
|
containerSignature.SetKey(key)
|
|
|
|
containerSignature.SetSign(sig)
|
|
|
|
reqBody.SetSignature(containerSignature)
|
|
|
|
},
|
|
|
|
sigutil.SignWithRFC6979())
|
|
|
|
if err != nil {
|
2021-11-16 18:17:25 +00:00
|
|
|
return nil, err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form meta header
|
|
|
|
var meta v2session.RequestMetaHeader
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
prm.prmSession.writeToMetaHeader(&meta)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
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
|
|
|
|
res ContainerDeleteRes
|
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) {
|
|
|
|
return rpcapi.DeleteContainer(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
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
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// EACLPrm groups parameters of EACL operation.
|
|
|
|
type EACLPrm struct {
|
|
|
|
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 NeoFS container to read the eACL table.
|
|
|
|
// Required parameter.
|
|
|
|
func (x *EACLPrm) SetContainer(id cid.ID) {
|
|
|
|
x.id = id
|
|
|
|
x.idSet = true
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// EACLRes groups resulting values of EACL operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type EACLRes struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
table *eacl.Table
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// Table returns eACL table of the requested container.
|
|
|
|
//
|
|
|
|
// Client doesn't retain value so modification is safe.
|
2021-11-16 18:17:25 +00:00
|
|
|
func (x EACLRes) Table() *eacl.Table {
|
|
|
|
return x.table
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
func (x *EACLRes) setTable(table *eacl.Table) {
|
2021-11-16 18:17:25 +00:00
|
|
|
x.table = table
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// EACL reads eACL table of the NeoFS 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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// in the returned result structure.
|
2021-12-02 12:21:54 +00:00
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see EACLPrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
func (c *Client) EACL(ctx context.Context, prm EACLPrm) (*EACLRes, error) {
|
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case !prm.idSet:
|
|
|
|
panic(panicMsgMissingContainer)
|
|
|
|
}
|
|
|
|
|
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.GetExtendedACLRequestBody)
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetContainerID(prm.id.ToV2())
|
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
|
|
|
|
res EACLRes
|
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) {
|
|
|
|
return rpcapi.GetEACL(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
|
|
|
cc.result = func(r responseV2) {
|
|
|
|
resp := r.(*v2container.GetExtendedACLResponse)
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
body := resp.GetBody()
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
table := eacl.NewTableFromV2(body.GetEACL())
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
table.SetSessionToken(
|
|
|
|
session.NewTokenFromV2(body.GetSessionToken()),
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
table.SetSignature(
|
|
|
|
signature.NewFromV2(body.GetSignature()),
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
res.setTable(table)
|
|
|
|
}
|
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
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetEACLPrm groups parameters of SetEACL operation.
|
|
|
|
type SetEACLPrm struct {
|
|
|
|
prmSession
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
tableSet bool
|
|
|
|
table eacl.Table
|
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.
|
|
|
|
func (x *SetEACLPrm) SetTable(table eacl.Table) {
|
|
|
|
x.table = table
|
|
|
|
x.tableSet = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEACLRes groups resulting values of SetEACL operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type SetEACLRes struct {
|
|
|
|
statusRes
|
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// SetEACL sends request to update eACL table of the NeoFS 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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// 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).
|
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see SetEACLPrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
func (c *Client) SetEACL(ctx context.Context, prm SetEACLPrm) (*SetEACLRes, error) {
|
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case !prm.tableSet:
|
|
|
|
panic("eACL table not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
// form request body
|
2021-11-09 08:07:49 +00:00
|
|
|
reqBody := new(v2container.SetExtendedACLRequestBody)
|
2021-12-02 12:21:54 +00:00
|
|
|
reqBody.SetEACL(prm.table.ToV2())
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// sign the eACL table
|
2021-11-09 08:07:49 +00:00
|
|
|
signWrapper := v2signature.StableMarshalerWrapper{SM: reqBody.GetEACL()}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
err := sigutil.SignDataWithHandler(c.opts.key, signWrapper, func(key []byte, sig []byte) {
|
2021-11-09 08:07:49 +00:00
|
|
|
eaclSignature := new(refs.Signature)
|
|
|
|
eaclSignature.SetKey(key)
|
|
|
|
eaclSignature.SetSign(sig)
|
|
|
|
reqBody.SetSignature(eaclSignature)
|
|
|
|
}, sigutil.SignWithRFC6979())
|
|
|
|
if err != nil {
|
2021-11-16 18:17:25 +00:00
|
|
|
return nil, err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// form meta header
|
|
|
|
var meta v2session.RequestMetaHeader
|
2021-11-16 18:17:25 +00:00
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
prm.prmSession.writeToMetaHeader(&meta)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
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
|
|
|
|
res SetEACLRes
|
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) {
|
|
|
|
return rpcapi.SetEACL(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
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
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// AnnounceSpacePrm groups parameters of AnnounceContainerUsedSpace operation.
|
|
|
|
type AnnounceSpacePrm struct {
|
|
|
|
announcements []container.UsedSpaceAnnouncement
|
|
|
|
}
|
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.
|
|
|
|
func (x *AnnounceSpacePrm) SetValues(announcements []container.UsedSpaceAnnouncement) {
|
|
|
|
x.announcements = announcements
|
2021-11-16 18:17:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// AnnounceSpaceRes groups resulting values of AnnounceContainerUsedSpace operation.
|
2021-11-16 18:17:25 +00:00
|
|
|
type AnnounceSpaceRes struct {
|
|
|
|
statusRes
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 12:21:54 +00:00
|
|
|
// AnnounceContainerUsedSpace 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`.
|
|
|
|
// If WithNeoFSErrorParsing option has been provided, unsuccessful
|
|
|
|
// NeoFS status codes are returned as `error`, otherwise, are included
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Immediately panics if parameters are set incorrectly (see AnnounceSpacePrm docs).
|
|
|
|
// Context is required and must not be nil. It is used for network communication.
|
|
|
|
//
|
2022-01-24 10:33:43 +00:00
|
|
|
// Return statuses:
|
|
|
|
// - global (see Client docs).
|
2021-12-02 12:21:54 +00:00
|
|
|
func (c *Client) AnnounceContainerUsedSpace(ctx context.Context, prm AnnounceSpacePrm) (*AnnounceSpaceRes, error) {
|
|
|
|
// check parameters
|
|
|
|
switch {
|
|
|
|
case ctx == nil:
|
|
|
|
panic(panicMsgMissingContext)
|
|
|
|
case len(prm.announcements) == 0:
|
|
|
|
panic("missing announcements")
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert list of SDK announcement structures into NeoFS-API v2 list
|
2021-12-02 12:21:54 +00:00
|
|
|
v2announce := make([]*v2container.UsedSpaceAnnouncement, 0, len(prm.announcements))
|
|
|
|
for i := range prm.announcements {
|
|
|
|
v2announce = append(v2announce, prm.announcements[i].ToV2())
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// prepare body of the NeoFS-API v2 request and request itself
|
|
|
|
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
|
|
|
|
res AnnounceSpaceRes
|
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) {
|
|
|
|
return rpcapi.AnnounceUsedSpace(c.Raw(), &req, client.WithContext(ctx))
|
|
|
|
}
|
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
|
|
|
}
|