2021-11-09 08:07:49 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
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-11-09 08:07:49 +00:00
|
|
|
v2signature "github.com/nspcc-dev/neofs-api-go/v2/signature"
|
2021-11-16 18:17:25 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2021-11-09 08:07:49 +00:00
|
|
|
"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"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Container contains methods related to container and ACL.
|
|
|
|
type Container interface {
|
|
|
|
// PutContainer creates new container in the NeoFS network.
|
2021-11-16 18:17:25 +00:00
|
|
|
PutContainer(context.Context, *container.Container, ...CallOption) (*ContainerPutRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
// GetContainer returns container by ID.
|
2021-11-16 18:17:25 +00:00
|
|
|
GetContainer(context.Context, *cid.ID, ...CallOption) (*ContainerGetRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
// ListContainers return container list with the provided owner.
|
2021-11-16 18:17:25 +00:00
|
|
|
ListContainers(context.Context, *owner.ID, ...CallOption) (*ContainerListRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
// DeleteContainer removes container from NeoFS network.
|
2021-11-16 18:17:25 +00:00
|
|
|
DeleteContainer(context.Context, *cid.ID, ...CallOption) (*ContainerDeleteRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
// EACL returns extended ACL for a given container.
|
|
|
|
EACL(context.Context, *cid.ID, ...CallOption) (*EACLRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
// SetEACL sets extended ACL.
|
2021-11-16 18:17:25 +00:00
|
|
|
SetEACL(context.Context, *eacl.Table, ...CallOption) (*SetEACLRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
|
|
|
// AnnounceContainerUsedSpace announces amount of space which is taken by stored objects.
|
2021-11-16 18:17:25 +00:00
|
|
|
AnnounceContainerUsedSpace(context.Context, []container.UsedSpaceAnnouncement, ...CallOption) (*AnnounceSpaceRes, error)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type delContainerSignWrapper struct {
|
|
|
|
body *v2container.DeleteRequestBody
|
|
|
|
}
|
|
|
|
|
|
|
|
// EACLWithSignature represents eACL table/signature pair.
|
|
|
|
type EACLWithSignature struct {
|
|
|
|
table *eacl.Table
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c delContainerSignWrapper) ReadSignedData(bytes []byte) ([]byte, error) {
|
|
|
|
return c.body.GetContainerID().GetValue(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c delContainerSignWrapper) SignedDataSize() int {
|
|
|
|
return len(c.body.GetContainerID().GetValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
// EACL returns eACL table.
|
|
|
|
func (e EACLWithSignature) EACL() *eacl.Table {
|
|
|
|
return e.table
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signature returns table signature.
|
|
|
|
//
|
|
|
|
// Deprecated: use EACL().Signature() instead.
|
|
|
|
func (e EACLWithSignature) Signature() *signature.Signature {
|
|
|
|
return e.table.Signature()
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
type ContainerPutRes struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
id *cid.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x ContainerPutRes) ID() *cid.ID {
|
|
|
|
return x.id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *ContainerPutRes) setID(id *cid.ID) {
|
|
|
|
x.id = id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*ContainerPutRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
// apply all available options
|
|
|
|
callOptions := c.defaultCallOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
// set transport version
|
|
|
|
cnr.SetVersion(version.Current())
|
|
|
|
|
|
|
|
// if container owner is not set, then use client key as owner
|
|
|
|
if cnr.OwnerID() == nil {
|
|
|
|
w, err := owner.NEO3WalletFromPublicKey(&callOptions.key.PublicKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ownerID := new(owner.ID)
|
|
|
|
ownerID.SetNeo3Wallet(w)
|
|
|
|
|
|
|
|
cnr.SetOwnerID(ownerID)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2container.PutRequestBody)
|
|
|
|
reqBody.SetContainer(cnr.ToV2())
|
|
|
|
|
|
|
|
// sign container
|
|
|
|
signWrapper := v2signature.StableMarshalerWrapper{SM: reqBody.GetContainer()}
|
|
|
|
|
|
|
|
err := sigutil.SignDataWithHandler(callOptions.key, signWrapper, func(key []byte, sig []byte) {
|
|
|
|
containerSignature := new(refs.Signature)
|
|
|
|
containerSignature.SetKey(key)
|
|
|
|
containerSignature.SetSign(sig)
|
|
|
|
reqBody.SetSignature(containerSignature)
|
|
|
|
}, sigutil.SignWithRFC6979())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req := new(v2container.PutRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
|
|
|
|
meta := v2MetaHeaderFromOpts(callOptions)
|
|
|
|
meta.SetSessionToken(cnr.SessionToken().ToV2())
|
|
|
|
|
|
|
|
req.SetMetaHeader(meta)
|
|
|
|
|
|
|
|
err = v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.PutContainer(c.Raw(), req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(ContainerPutRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
|
|
|
|
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
// sets result status
|
|
|
|
st := apistatus.FromStatusV2(resp.GetMetaHeader().GetStatus())
|
|
|
|
|
|
|
|
res.setStatus(st)
|
|
|
|
|
|
|
|
if apistatus.IsSuccessful(st) {
|
|
|
|
res.setID(cid.NewFromV2(resp.GetBody().GetContainerID()))
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContainerGetRes struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
cnr *container.Container
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// GetContainer receives container structure through NeoFS API call.
|
|
|
|
//
|
|
|
|
// Returns error if container structure is received but does not meet NeoFS API specification.
|
2021-11-16 18:17:25 +00:00
|
|
|
func (c *clientImpl) GetContainer(ctx context.Context, id *cid.ID, opts ...CallOption) (*ContainerGetRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
// apply all available options
|
|
|
|
callOptions := c.defaultCallOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2container.GetRequestBody)
|
|
|
|
reqBody.SetContainerID(id.ToV2())
|
|
|
|
|
|
|
|
req := new(v2container.GetRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions))
|
|
|
|
|
|
|
|
err := v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.GetContainer(c.Raw(), req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("transport error: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(ContainerGetRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
body := resp.GetBody()
|
|
|
|
|
|
|
|
cnr := container.NewContainerFromV2(body.GetContainer())
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
cnr.SetSessionToken(
|
|
|
|
session.NewTokenFromV2(body.GetSessionToken()),
|
|
|
|
)
|
|
|
|
|
|
|
|
cnr.SetSignature(
|
|
|
|
signature.NewFromV2(body.GetSignature()),
|
|
|
|
)
|
|
|
|
|
|
|
|
res.setContainer(cnr)
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
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-11-16 18:17:25 +00:00
|
|
|
func (x ContainerListRes) IDList() []*cid.ID {
|
|
|
|
return x.ids
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
func (x *ContainerListRes) setIDList(ids []*cid.ID) {
|
|
|
|
x.ids = ids
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) (*ContainerListRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
// apply all available options
|
|
|
|
callOptions := c.defaultCallOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ownerID == nil {
|
|
|
|
w, err := owner.NEO3WalletFromPublicKey(&callOptions.key.PublicKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ownerID = new(owner.ID)
|
|
|
|
ownerID.SetNeo3Wallet(w)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2container.ListRequestBody)
|
|
|
|
reqBody.SetOwnerID(ownerID.ToV2())
|
|
|
|
|
|
|
|
req := new(v2container.ListRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions))
|
|
|
|
|
|
|
|
err := v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.ListContainers(c.Raw(), req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("transport error: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(ContainerListRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
ids := make([]*cid.ID, 0, len(resp.GetBody().GetContainerIDs()))
|
|
|
|
|
2021-11-09 08:07:49 +00:00
|
|
|
for _, cidV2 := range resp.GetBody().GetContainerIDs() {
|
2021-11-16 18:17:25 +00:00
|
|
|
ids = append(ids, cid.NewFromV2(cidV2))
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
res.setIDList(ids)
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContainerDeleteRes struct {
|
|
|
|
statusRes
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
func (c *clientImpl) DeleteContainer(ctx context.Context, id *cid.ID, opts ...CallOption) (*ContainerDeleteRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
// apply all available options
|
|
|
|
callOptions := c.defaultCallOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2container.DeleteRequestBody)
|
|
|
|
reqBody.SetContainerID(id.ToV2())
|
|
|
|
|
|
|
|
// sign container
|
|
|
|
err := sigutil.SignDataWithHandler(callOptions.key,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
req := new(v2container.DeleteRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions))
|
|
|
|
|
|
|
|
err = v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
2021-11-16 18:17:25 +00:00
|
|
|
return nil, err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.DeleteContainer(c.Raw(), req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
2021-11-16 18:17:25 +00:00
|
|
|
return nil, fmt.Errorf("transport error: %w", err)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(ContainerDeleteRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type EACLRes struct {
|
|
|
|
statusRes
|
|
|
|
|
|
|
|
table *eacl.Table
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x EACLRes) Table() *eacl.Table {
|
|
|
|
return x.table
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *EACLRes) SetTable(table *eacl.Table) {
|
|
|
|
x.table = table
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
func (c *clientImpl) EACL(ctx context.Context, id *cid.ID, opts ...CallOption) (*EACLRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
// apply all available options
|
|
|
|
callOptions := c.defaultCallOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2container.GetExtendedACLRequestBody)
|
|
|
|
reqBody.SetContainerID(id.ToV2())
|
|
|
|
|
|
|
|
req := new(v2container.GetExtendedACLRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions))
|
|
|
|
|
|
|
|
err := v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.GetEACL(c.Raw(), req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("transport error: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(EACLRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
body := resp.GetBody()
|
|
|
|
|
|
|
|
table := eacl.NewTableFromV2(body.GetEACL())
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
table.SetSessionToken(
|
|
|
|
session.NewTokenFromV2(body.GetSessionToken()),
|
|
|
|
)
|
|
|
|
|
|
|
|
table.SetSignature(
|
|
|
|
signature.NewFromV2(body.GetSignature()),
|
|
|
|
)
|
|
|
|
|
|
|
|
res.SetTable(table)
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
type SetEACLRes struct {
|
|
|
|
statusRes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *clientImpl) SetEACL(ctx context.Context, eacl *eacl.Table, opts ...CallOption) (*SetEACLRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
// apply all available options
|
|
|
|
callOptions := c.defaultCallOptions()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqBody := new(v2container.SetExtendedACLRequestBody)
|
|
|
|
reqBody.SetEACL(eacl.ToV2())
|
|
|
|
|
|
|
|
signWrapper := v2signature.StableMarshalerWrapper{SM: reqBody.GetEACL()}
|
|
|
|
|
|
|
|
err := sigutil.SignDataWithHandler(callOptions.key, signWrapper, func(key []byte, sig []byte) {
|
|
|
|
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-11-16 18:17:25 +00:00
|
|
|
req := new(v2container.SetExtendedACLRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
|
2021-11-09 08:07:49 +00:00
|
|
|
meta := v2MetaHeaderFromOpts(callOptions)
|
|
|
|
meta.SetSessionToken(eacl.SessionToken().ToV2())
|
|
|
|
|
|
|
|
req.SetMetaHeader(meta)
|
|
|
|
|
|
|
|
err = v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
2021-11-16 18:17:25 +00:00
|
|
|
return nil, err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.SetEACL(c.Raw(), req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
2021-11-16 18:17:25 +00:00
|
|
|
return nil, fmt.Errorf("transport error: %w", err)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(SetEACLRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type AnnounceSpaceRes struct {
|
|
|
|
statusRes
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AnnounceContainerUsedSpace used by storage nodes to estimate their container
|
|
|
|
// sizes during lifetime. Use it only in storage node applications.
|
|
|
|
func (c *clientImpl) AnnounceContainerUsedSpace(
|
|
|
|
ctx context.Context,
|
|
|
|
announce []container.UsedSpaceAnnouncement,
|
2021-11-16 18:17:25 +00:00
|
|
|
opts ...CallOption,
|
|
|
|
) (*AnnounceSpaceRes, error) {
|
2021-11-09 08:07:49 +00:00
|
|
|
callOptions := c.defaultCallOptions() // apply all available options
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](callOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert list of SDK announcement structures into NeoFS-API v2 list
|
|
|
|
v2announce := make([]*v2container.UsedSpaceAnnouncement, 0, len(announce))
|
|
|
|
for i := range announce {
|
|
|
|
v2announce = append(v2announce, announce[i].ToV2())
|
|
|
|
}
|
|
|
|
|
|
|
|
// prepare body of the NeoFS-API v2 request and request itself
|
|
|
|
reqBody := new(v2container.AnnounceUsedSpaceRequestBody)
|
|
|
|
reqBody.SetAnnouncements(v2announce)
|
|
|
|
|
|
|
|
req := new(v2container.AnnounceUsedSpaceRequest)
|
|
|
|
req.SetBody(reqBody)
|
|
|
|
req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions))
|
|
|
|
|
|
|
|
// sign the request
|
|
|
|
err := v2signature.SignServiceMessage(callOptions.key, req)
|
|
|
|
if err != nil {
|
2021-11-16 18:17:25 +00:00
|
|
|
return nil, err
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := rpcapi.AnnounceUsedSpace(c.Raw(), req, client.WithContext(ctx))
|
|
|
|
if err != nil {
|
2021-11-16 18:17:25 +00:00
|
|
|
return nil, fmt.Errorf("transport error: %w", err)
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
var (
|
|
|
|
res = new(AnnounceSpaceRes)
|
|
|
|
procPrm processResponseV2Prm
|
|
|
|
procRes processResponseV2Res
|
|
|
|
)
|
2021-11-09 08:07:49 +00:00
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
procPrm.callOpts = callOptions
|
|
|
|
procPrm.resp = resp
|
|
|
|
|
|
|
|
procRes.statusRes = res
|
|
|
|
|
|
|
|
// process response in general
|
|
|
|
if c.processResponseV2(&procRes, procPrm) {
|
|
|
|
if procRes.cliErr != nil {
|
|
|
|
return nil, procRes.cliErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 18:17:25 +00:00
|
|
|
return res, nil
|
2021-11-09 08:07:49 +00:00
|
|
|
}
|