2021-10-28 14:48:46 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2022-02-25 09:20:49 +00:00
|
|
|
"bytes"
|
2021-10-28 14:48:46 +00:00
|
|
|
"context"
|
2022-02-25 09:20:49 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-10-28 14:48:46 +00:00
|
|
|
"io"
|
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/accounting"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
|
|
|
"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/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
2021-10-28 14:48:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// BalanceOfPrm groups parameters of BalanceOf operation.
|
|
|
|
type BalanceOfPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmBalanceGet
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// BalanceOfRes groups the resulting values of BalanceOf operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type BalanceOfRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes *client.ResBalanceGet
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Balance returns the current balance.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x BalanceOfRes) Balance() *accounting.Decimal {
|
2021-11-06 11:13:04 +00:00
|
|
|
return x.cliRes.Amount()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// BalanceOf requests the current balance of a NeoFS user.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func BalanceOf(prm BalanceOfPrm) (res BalanceOfRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
res.cliRes, err = prm.cli.BalanceGet(context.Background(), prm.PrmBalanceGet)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListContainersPrm groups parameters of ListContainers operation.
|
|
|
|
type ListContainersPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmContainerList
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ListContainersRes groups the resulting values of ListContainers operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type ListContainersRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes *client.ResContainerList
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IDList returns list of identifiers of user's containers.
|
2022-03-15 11:16:46 +00:00
|
|
|
func (x ListContainersRes) IDList() []cid.ID {
|
2022-01-21 16:53:06 +00:00
|
|
|
return x.cliRes.Containers()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ListContainers requests a list of NeoFS user's containers.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func ListContainers(prm ListContainersPrm) (res ListContainersRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
res.cliRes, err = prm.cli.ContainerList(context.Background(), prm.PrmContainerList)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutContainerPrm groups parameters of PutContainer operation.
|
|
|
|
type PutContainerPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmContainerPut
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// PutContainerRes groups the resulting values of PutContainer operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type PutContainerRes struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr cid.ID
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns identifier of the created container.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (x PutContainerRes) ID() cid.ID {
|
|
|
|
return x.cnr
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// PutContainer sends a request to save the container in NeoFS.
|
2021-10-28 14:48:46 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Operation is asynchronous and not guaranteed even in the absence of errors.
|
2021-10-28 14:48:46 +00:00
|
|
|
// The required time is also not predictable.
|
|
|
|
//
|
|
|
|
// Success can be verified by reading by identifier.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func PutContainer(prm PutContainerPrm) (res PutContainerRes, err error) {
|
2022-05-31 17:00:41 +00:00
|
|
|
cliRes, err := prm.cli.ContainerPut(context.Background(), prm.PrmContainerPut)
|
|
|
|
if err == nil {
|
|
|
|
cnr := cliRes.ID()
|
|
|
|
if cnr == nil {
|
|
|
|
err = errors.New("missing container ID in response")
|
|
|
|
} else {
|
|
|
|
res.cnr = *cnr
|
|
|
|
}
|
|
|
|
}
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetContainerPrm groups parameters of GetContainer operation.
|
|
|
|
type GetContainerPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
cliPrm client.PrmContainerGet
|
2022-01-21 16:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetContainer sets identifier of the container to be read.
|
|
|
|
func (x *GetContainerPrm) SetContainer(id cid.ID) {
|
|
|
|
x.cliPrm.SetContainer(id)
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// GetContainerRes groups the resulting values of GetContainer operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type GetContainerRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes *client.ResContainerGet
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Container returns structured of the requested container.
|
2022-06-28 07:01:05 +00:00
|
|
|
func (x GetContainerRes) Container() container.Container {
|
2021-11-06 11:13:04 +00:00
|
|
|
return x.cliRes.Container()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// GetContainer reads a container from NeoFS by ID.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func GetContainer(prm GetContainerPrm) (res GetContainerRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
res.cliRes, err = prm.cli.ContainerGet(context.Background(), prm.cliPrm)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteContainerPrm groups parameters of DeleteContainerPrm operation.
|
|
|
|
type DeleteContainerPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmContainerDelete
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteContainerRes groups the resulting values of DeleteContainer operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type DeleteContainerRes struct{}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteContainer sends a request to remove a container from NeoFS by ID.
|
2021-10-28 14:48:46 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Operation is asynchronous and not guaranteed even in the absence of errors.
|
2021-10-28 14:48:46 +00:00
|
|
|
// The required time is also not predictable.
|
|
|
|
//
|
|
|
|
// Success can be verified by reading by identifier.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func DeleteContainer(prm DeleteContainerPrm) (res DeleteContainerRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
_, err = prm.cli.ContainerDelete(context.Background(), prm.PrmContainerDelete)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// EACLPrm groups parameters of EACL operation.
|
|
|
|
type EACLPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmContainerEACL
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// EACLRes groups the resulting values of EACL operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type EACLRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes *client.ResContainerEACL
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EACL returns requested eACL table.
|
|
|
|
func (x EACLRes) EACL() *eacl.Table {
|
2021-11-06 11:13:04 +00:00
|
|
|
return x.cliRes.Table()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EACL reads eACL table from NeoFS by container ID.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func EACL(prm EACLPrm) (res EACLRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
res.cliRes, err = prm.cli.ContainerEACL(context.Background(), prm.PrmContainerEACL)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEACLPrm groups parameters of SetEACL operation.
|
|
|
|
type SetEACLPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmContainerSetEACL
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetEACLRes groups the resulting values of SetEACL operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type SetEACLRes struct{}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetEACL requests to save an eACL table in NeoFS.
|
2021-10-28 14:48:46 +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 container identifier.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func SetEACL(prm SetEACLPrm) (res SetEACLRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
_, err = prm.cli.ContainerSetEACL(context.Background(), prm.PrmContainerSetEACL)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetworkInfoPrm groups parameters of NetworkInfo operation.
|
|
|
|
type NetworkInfoPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmNetworkInfo
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// NetworkInfoRes groups the resulting values of NetworkInfo operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type NetworkInfoRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes *client.ResNetworkInfo
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NetworkInfo returns structured information about the NeoFS network.
|
|
|
|
func (x NetworkInfoRes) NetworkInfo() *netmap.NetworkInfo {
|
2021-11-06 11:13:04 +00:00
|
|
|
return x.cliRes.Info()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NetworkInfo reads information about the NeoFS network.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func NetworkInfo(prm NetworkInfoPrm) (res NetworkInfoRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
res.cliRes, err = prm.cli.NetworkInfo(context.Background(), prm.PrmNetworkInfo)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeInfoPrm groups parameters of NodeInfo operation.
|
|
|
|
type NodeInfoPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmEndpointInfo
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// NodeInfoRes groups the resulting values of NodeInfo operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type NodeInfoRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes *client.ResEndpointInfo
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NodeInfo returns information about the node from netmap.
|
2022-06-08 23:18:26 +00:00
|
|
|
func (x NodeInfoRes) NodeInfo() netmap.NodeInfo {
|
|
|
|
return *x.cliRes.NodeInfo()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// LatestVersion returns the latest NeoFS API version in use.
|
2021-11-10 07:08:33 +00:00
|
|
|
func (x NodeInfoRes) LatestVersion() *version.Version {
|
2022-01-21 16:53:06 +00:00
|
|
|
return x.cliRes.LatestVersion()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NodeInfo requests information about the remote server from NeoFS netmap.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func NodeInfo(prm NodeInfoPrm) (res NodeInfoRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
res.cliRes, err = prm.cli.EndpointInfo(context.Background(), prm.PrmEndpointInfo)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateSessionPrm groups parameters of CreateSession operation.
|
|
|
|
type CreateSessionPrm struct {
|
|
|
|
commonPrm
|
2022-02-25 09:20:49 +00:00
|
|
|
client.PrmSessionCreate
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// CreateSessionRes groups the resulting values of CreateSession operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type CreateSessionRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes *client.ResSessionCreate
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns session identifier.
|
|
|
|
func (x CreateSessionRes) ID() []byte {
|
|
|
|
return x.cliRes.ID()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SessionKey returns public session key in a binary format.
|
|
|
|
func (x CreateSessionRes) SessionKey() []byte {
|
2022-01-21 16:53:06 +00:00
|
|
|
return x.cliRes.PublicKey()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// CreateSession opens a new unlimited session with the remote node.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
func CreateSession(prm CreateSessionPrm) (res CreateSessionRes, err error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
res.cliRes, err = prm.cli.SessionCreate(context.Background(), prm.PrmSessionCreate)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutObjectPrm groups parameters of PutObject operation.
|
|
|
|
type PutObjectPrm struct {
|
|
|
|
commonObjectPrm
|
|
|
|
|
|
|
|
hdr *object.Object
|
|
|
|
|
|
|
|
rdr io.Reader
|
2022-06-08 07:55:52 +00:00
|
|
|
|
|
|
|
headerCallback func(*object.Object)
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetHeader sets object header.
|
|
|
|
func (x *PutObjectPrm) SetHeader(hdr *object.Object) {
|
|
|
|
x.hdr = hdr
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPayloadReader sets reader of the object payload.
|
|
|
|
func (x *PutObjectPrm) SetPayloadReader(rdr io.Reader) {
|
|
|
|
x.rdr = rdr
|
|
|
|
}
|
|
|
|
|
2022-06-08 07:55:52 +00:00
|
|
|
// SetHeaderCallback sets callback which is called on the object after the header is received
|
|
|
|
// but before the payload is written.
|
|
|
|
func (x *PutObjectPrm) SetHeaderCallback(f func(*object.Object)) {
|
|
|
|
x.headerCallback = f
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// PutObjectRes groups the resulting values of PutObject operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type PutObjectRes struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
id oid.ID
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns identifier of the created object.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (x PutObjectRes) ID() oid.ID {
|
2022-02-25 09:20:49 +00:00
|
|
|
return x.id
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PutObject saves the object in NeoFS network.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2022-02-25 09:20:49 +00:00
|
|
|
func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
|
|
|
|
var putPrm client.PrmObjectPutInit
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
wrt, err := prm.cli.ObjectPutInit(context.Background(), putPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("init object writing: %w", err)
|
|
|
|
}
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.sessionToken != nil {
|
|
|
|
wrt.WithinSession(*prm.sessionToken)
|
|
|
|
}
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.bearerToken != nil {
|
|
|
|
wrt.WithBearerToken(*prm.bearerToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.local {
|
|
|
|
wrt.MarkLocal()
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
wrt.WithXHeaders(prm.xHeaders...)
|
2022-03-03 12:30:20 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if wrt.WriteHeader(*prm.hdr) {
|
2022-06-08 07:55:52 +00:00
|
|
|
if prm.headerCallback != nil {
|
|
|
|
prm.headerCallback(prm.hdr)
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
sz := prm.hdr.PayloadSize()
|
|
|
|
|
|
|
|
if data := prm.hdr.Payload(); len(data) > 0 {
|
|
|
|
if prm.rdr != nil {
|
|
|
|
prm.rdr = io.MultiReader(bytes.NewReader(data), prm.rdr)
|
|
|
|
} else {
|
|
|
|
prm.rdr = bytes.NewReader(data)
|
|
|
|
sz = uint64(len(data))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.rdr != nil {
|
|
|
|
// TODO: (neofs-node#1198) explore better values or configure it
|
|
|
|
const defaultBufferSizePut = 4096
|
|
|
|
|
|
|
|
if sz == 0 || sz > defaultBufferSizePut {
|
|
|
|
sz = defaultBufferSizePut
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := make([]byte, sz)
|
|
|
|
|
|
|
|
var n int
|
|
|
|
|
|
|
|
for {
|
|
|
|
n, err = prm.rdr.Read(buf)
|
|
|
|
if n > 0 {
|
|
|
|
if !wrt.WritePayloadChunk(buf[:n]) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if errors.Is(err, io.EOF) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("read payload: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cliRes, err := wrt.Close()
|
2022-02-25 09:20:49 +00:00
|
|
|
if err != nil { // here err already carries both status and client errors
|
|
|
|
return nil, fmt.Errorf("client failure: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var res PutObjectRes
|
2022-02-25 09:20:49 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
if !cliRes.ReadStoredObjectID(&res.id) {
|
2022-02-25 09:20:49 +00:00
|
|
|
return nil, errors.New("missing ID of the stored object")
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
return &res, nil
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteObjectPrm groups parameters of DeleteObject operation.
|
|
|
|
type DeleteObjectPrm struct {
|
|
|
|
commonObjectPrm
|
|
|
|
objectAddressPrm
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteObjectRes groups the resulting values of DeleteObject operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type DeleteObjectRes struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
tomb oid.ID
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
// Tombstone returns the ID of the created object with tombstone.
|
|
|
|
func (x DeleteObjectRes) Tombstone() oid.ID {
|
|
|
|
return x.tomb
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DeleteObject marks an object to be removed from NeoFS through tombstone placement.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2022-02-25 09:20:49 +00:00
|
|
|
func DeleteObject(prm DeleteObjectPrm) (*DeleteObjectRes, error) {
|
|
|
|
var delPrm client.PrmObjectDelete
|
2022-05-31 17:00:41 +00:00
|
|
|
delPrm.FromContainer(prm.objAddr.Container())
|
|
|
|
delPrm.ByID(prm.objAddr.Object())
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.sessionToken != nil {
|
|
|
|
delPrm.WithinSession(*prm.sessionToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.bearerToken != nil {
|
|
|
|
delPrm.WithBearerToken(*prm.bearerToken)
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
delPrm.WithXHeaders(prm.xHeaders...)
|
2022-03-03 12:30:20 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes, err := prm.cli.ObjectDelete(context.Background(), delPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("remove object via client: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var id oid.ID
|
2022-02-25 09:20:49 +00:00
|
|
|
|
|
|
|
if !cliRes.ReadTombstoneID(&id) {
|
|
|
|
return nil, errors.New("object removed but tombstone ID is missing")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &DeleteObjectRes{
|
2022-05-31 17:00:41 +00:00
|
|
|
tomb: id,
|
2022-02-25 09:20:49 +00:00
|
|
|
}, nil
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetObjectPrm groups parameters of GetObject operation.
|
|
|
|
type GetObjectPrm struct {
|
|
|
|
commonObjectPrm
|
|
|
|
objectAddressPrm
|
|
|
|
rawPrm
|
|
|
|
payloadWriterPrm
|
2022-03-09 10:35:52 +00:00
|
|
|
headerCallback func(*object.Object)
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetHeaderCallback sets callback which is called on the object after the header is received
|
2022-03-09 10:35:52 +00:00
|
|
|
// but before the payload is written.
|
|
|
|
func (p *GetObjectPrm) SetHeaderCallback(f func(*object.Object)) {
|
|
|
|
p.headerCallback = f
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// GetObjectRes groups the resulting values of GetObject operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type GetObjectRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
hdr *object.Object
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Header returns the header of the request object.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x GetObjectRes) Header() *object.Object {
|
2022-02-25 09:20:49 +00:00
|
|
|
return x.hdr
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// GetObject reads an object by address.
|
2021-10-28 14:48:46 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Interrupts on any writer error. If successful, payload is written to the writer.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-11-03 17:13:16 +00:00
|
|
|
// For raw reading, returns *object.SplitInfoError error if object is virtual.
|
2022-02-25 09:20:49 +00:00
|
|
|
func GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
|
|
|
|
var getPrm client.PrmObjectGet
|
2022-05-31 17:00:41 +00:00
|
|
|
getPrm.FromContainer(prm.objAddr.Container())
|
|
|
|
getPrm.ByID(prm.objAddr.Object())
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.sessionToken != nil {
|
|
|
|
getPrm.WithinSession(*prm.sessionToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.bearerToken != nil {
|
|
|
|
getPrm.WithBearerToken(*prm.bearerToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.raw {
|
|
|
|
getPrm.MarkRaw()
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.local {
|
|
|
|
getPrm.MarkLocal()
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
getPrm.WithXHeaders(prm.xHeaders...)
|
2022-03-03 12:30:20 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
rdr, err := prm.cli.ObjectGetInit(context.Background(), getPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("init object reading on client: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var hdr object.Object
|
|
|
|
|
|
|
|
if !rdr.ReadHeader(&hdr) {
|
|
|
|
_, err = rdr.Close()
|
|
|
|
return nil, fmt.Errorf("read object header: %w", err)
|
|
|
|
}
|
2022-03-09 10:35:52 +00:00
|
|
|
if prm.headerCallback != nil {
|
|
|
|
prm.headerCallback(&hdr)
|
|
|
|
}
|
2022-02-25 09:20:49 +00:00
|
|
|
|
2022-03-21 10:20:34 +00:00
|
|
|
_, err = io.Copy(prm.wrt, rdr)
|
2022-02-25 09:20:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("copy payload: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &GetObjectRes{
|
|
|
|
hdr: &hdr,
|
|
|
|
}, nil
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HeadObjectPrm groups parameters of HeadObject operation.
|
|
|
|
type HeadObjectPrm struct {
|
|
|
|
commonObjectPrm
|
|
|
|
objectAddressPrm
|
|
|
|
rawPrm
|
|
|
|
|
|
|
|
mainOnly bool
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetMainOnlyFlag sets flag to get only main fields of an object header in terms of NeoFS API.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x *HeadObjectPrm) SetMainOnlyFlag(v bool) {
|
|
|
|
x.mainOnly = v
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// HeadObjectRes groups the resulting values of HeadObject operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type HeadObjectRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
hdr *object.Object
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Header returns the requested object header.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x HeadObjectRes) Header() *object.Object {
|
2022-02-25 09:20:49 +00:00
|
|
|
return x.hdr
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// HeadObject reads an object header by address.
|
2021-10-28 14:48:46 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
// For raw reading, returns *object.SplitInfoError error if object is virtual.
|
2022-02-25 09:20:49 +00:00
|
|
|
func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
|
|
|
|
var cliPrm client.PrmObjectHead
|
2022-05-31 17:00:41 +00:00
|
|
|
cliPrm.FromContainer(prm.objAddr.Container())
|
|
|
|
cliPrm.ByID(prm.objAddr.Object())
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-03-03 08:10:55 +00:00
|
|
|
if prm.sessionToken != nil {
|
|
|
|
cliPrm.WithinSession(*prm.sessionToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.bearerToken != nil {
|
|
|
|
cliPrm.WithBearerToken(*prm.bearerToken)
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.raw {
|
|
|
|
cliPrm.MarkRaw()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.local {
|
|
|
|
cliPrm.MarkLocal()
|
|
|
|
}
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
cliPrm.WithXHeaders(prm.xHeaders...)
|
2022-03-03 12:30:20 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
res, err := prm.cli.ObjectHead(context.Background(), cliPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("read object header via client: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var hdr object.Object
|
|
|
|
|
|
|
|
if !res.ReadHeader(&hdr) {
|
|
|
|
return nil, fmt.Errorf("missing header in response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &HeadObjectRes{
|
|
|
|
hdr: &hdr,
|
|
|
|
}, nil
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SearchObjectsPrm groups parameters of SearchObjects operation.
|
|
|
|
type SearchObjectsPrm struct {
|
|
|
|
commonObjectPrm
|
|
|
|
containerIDPrm
|
|
|
|
|
|
|
|
filters object.SearchFilters
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetFilters sets search filters.
|
|
|
|
func (x *SearchObjectsPrm) SetFilters(filters object.SearchFilters) {
|
|
|
|
x.filters = filters
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SearchObjectsRes groups the resulting values of SearchObjects operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type SearchObjectsRes struct {
|
2022-05-31 17:00:41 +00:00
|
|
|
ids []oid.ID
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IDList returns identifiers of the matched objects.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (x SearchObjectsRes) IDList() []oid.ID {
|
2022-02-25 09:20:49 +00:00
|
|
|
return x.ids
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SearchObjects selects objects from the container which match the filters.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2022-02-25 09:20:49 +00:00
|
|
|
func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) {
|
|
|
|
var cliPrm client.PrmObjectSearch
|
2022-05-31 17:00:41 +00:00
|
|
|
cliPrm.InContainer(prm.cnrID)
|
2022-02-25 09:20:49 +00:00
|
|
|
cliPrm.SetFilters(prm.filters)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.sessionToken != nil {
|
|
|
|
cliPrm.WithinSession(*prm.sessionToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.bearerToken != nil {
|
|
|
|
cliPrm.WithBearerToken(*prm.bearerToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.local {
|
|
|
|
cliPrm.MarkLocal()
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
cliPrm.WithXHeaders(prm.xHeaders...)
|
2022-03-03 12:30:20 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
rdr, err := prm.cli.ObjectSearchInit(context.Background(), cliPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("init object search: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
buf := make([]oid.ID, 10)
|
|
|
|
var list []oid.ID
|
2022-02-25 09:20:49 +00:00
|
|
|
var n int
|
|
|
|
var ok bool
|
|
|
|
|
|
|
|
for {
|
|
|
|
n, ok = rdr.Read(buf)
|
|
|
|
for i := 0; i < n; i++ {
|
2022-03-28 13:57:15 +00:00
|
|
|
list = append(list, buf[i])
|
2022-02-25 09:20:49 +00:00
|
|
|
}
|
2022-03-03 08:12:22 +00:00
|
|
|
if !ok {
|
|
|
|
break
|
|
|
|
}
|
2022-02-25 09:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = rdr.Close()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("read object list: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &SearchObjectsRes{
|
|
|
|
ids: list,
|
|
|
|
}, nil
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HashPayloadRangesPrm groups parameters of HashPayloadRanges operation.
|
|
|
|
type HashPayloadRangesPrm struct {
|
|
|
|
commonObjectPrm
|
|
|
|
objectAddressPrm
|
|
|
|
|
|
|
|
tz bool
|
|
|
|
|
|
|
|
rngs []*object.Range
|
|
|
|
|
|
|
|
salt []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// TZ sets flag to request Tillich-Zemor hashes.
|
|
|
|
func (x *HashPayloadRangesPrm) TZ() {
|
|
|
|
x.tz = true
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetRanges sets a list of payload ranges to hash.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x *HashPayloadRangesPrm) SetRanges(rngs []*object.Range) {
|
|
|
|
x.rngs = rngs
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSalt sets data for each range to be XOR'ed with.
|
|
|
|
func (x *HashPayloadRangesPrm) SetSalt(salt []byte) {
|
|
|
|
x.salt = salt
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// HashPayloadRangesRes groups the resulting values of HashPayloadRanges operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type HashPayloadRangesRes struct {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliRes *client.ResObjectHash
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// HashList returns a list of hashes of the payload ranges keeping order.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x HashPayloadRangesRes) HashList() [][]byte {
|
2022-02-25 09:20:49 +00:00
|
|
|
return x.cliRes.Checksums()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HashPayloadRanges requests hashes (by default SHA256) of the object payload ranges.
|
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-10-28 14:48:46 +00:00
|
|
|
// Returns an error if number of received hashes differs with the number of requested ranges.
|
2022-02-25 09:20:49 +00:00
|
|
|
func HashPayloadRanges(prm HashPayloadRangesPrm) (*HashPayloadRangesRes, error) {
|
|
|
|
var cliPrm client.PrmObjectHash
|
2022-05-31 17:00:41 +00:00
|
|
|
cliPrm.FromContainer(prm.objAddr.Container())
|
|
|
|
cliPrm.ByID(prm.objAddr.Object())
|
2022-02-25 09:20:49 +00:00
|
|
|
|
|
|
|
if prm.local {
|
|
|
|
cliPrm.MarkLocal()
|
|
|
|
}
|
|
|
|
|
|
|
|
cliPrm.UseSalt(prm.salt)
|
|
|
|
|
|
|
|
rngs := make([]uint64, 2*len(prm.rngs))
|
|
|
|
|
|
|
|
for i := range prm.rngs {
|
|
|
|
rngs[2*i] = prm.rngs[i].GetOffset()
|
|
|
|
rngs[2*i+1] = prm.rngs[i].GetLength()
|
|
|
|
}
|
|
|
|
|
|
|
|
cliPrm.SetRangeList(rngs...)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
if prm.tz {
|
2022-02-25 09:20:49 +00:00
|
|
|
cliPrm.TillichZemorAlgo()
|
2021-11-06 11:13:04 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.sessionToken != nil {
|
|
|
|
cliPrm.WithinSession(*prm.sessionToken)
|
|
|
|
}
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.bearerToken != nil {
|
|
|
|
cliPrm.WithBearerToken(*prm.bearerToken)
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
cliPrm.WithXHeaders(prm.xHeaders...)
|
2022-03-03 12:30:20 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
res, err := prm.cli.ObjectHash(context.Background(), cliPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("read payload hashes via client: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &HashPayloadRangesRes{
|
|
|
|
cliRes: res,
|
|
|
|
}, nil
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PayloadRangePrm groups parameters of PayloadRange operation.
|
|
|
|
type PayloadRangePrm struct {
|
|
|
|
commonObjectPrm
|
|
|
|
objectAddressPrm
|
|
|
|
rawPrm
|
|
|
|
payloadWriterPrm
|
|
|
|
|
|
|
|
rng *object.Range
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRange sets payload range to read.
|
|
|
|
func (x *PayloadRangePrm) SetRange(rng *object.Range) {
|
|
|
|
x.rng = rng
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// PayloadRangeRes groups the resulting values of PayloadRange operation.
|
2021-10-28 14:48:46 +00:00
|
|
|
type PayloadRangeRes struct{}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// PayloadRange reads object payload range from NeoFS and writes it to the specified writer.
|
2021-10-28 14:48:46 +00:00
|
|
|
//
|
|
|
|
// Interrupts on any writer error.
|
2021-11-03 17:13:16 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2021-11-03 17:13:16 +00:00
|
|
|
// For raw reading, returns *object.SplitInfoError error if object is virtual.
|
2022-02-25 09:20:49 +00:00
|
|
|
func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) {
|
|
|
|
var cliPrm client.PrmObjectRange
|
2022-05-31 17:00:41 +00:00
|
|
|
cliPrm.FromContainer(prm.objAddr.Container())
|
|
|
|
cliPrm.ByID(prm.objAddr.Object())
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2022-03-03 08:10:55 +00:00
|
|
|
if prm.sessionToken != nil {
|
|
|
|
cliPrm.WithinSession(*prm.sessionToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.bearerToken != nil {
|
|
|
|
cliPrm.WithBearerToken(*prm.bearerToken)
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
if prm.raw {
|
|
|
|
cliPrm.MarkRaw()
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.local {
|
|
|
|
cliPrm.MarkLocal()
|
|
|
|
}
|
|
|
|
|
|
|
|
cliPrm.SetOffset(prm.rng.GetOffset())
|
|
|
|
cliPrm.SetLength(prm.rng.GetLength())
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
cliPrm.WithXHeaders(prm.xHeaders...)
|
2022-03-03 12:30:20 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
rdr, err := prm.cli.ObjectRangeInit(context.Background(), cliPrm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("init payload reading: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-03-21 10:20:34 +00:00
|
|
|
_, err = io.Copy(prm.wrt, rdr)
|
2022-02-25 09:20:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("copy payload: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return new(PayloadRangeRes), nil
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|