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"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
|
|
|
containerSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-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.
|
2022-08-22 11:04:00 +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
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// BalanceOf requests the current balance of a FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func BalanceOf(ctx context.Context, prm BalanceOfPrm) (res BalanceOfRes, err error) {
|
|
|
|
res.cliRes, err = prm.cli.BalanceGet(ctx, 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
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// ListContainers requests a list of FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func ListContainers(ctx context.Context, prm ListContainersPrm) (res ListContainersRes, err error) {
|
|
|
|
res.cliRes, err = prm.cli.ContainerList(ctx, prm.PrmContainerList)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutContainerPrm groups parameters of PutContainer operation.
|
|
|
|
type PutContainerPrm struct {
|
2023-08-10 08:43:17 +00:00
|
|
|
Client *client.Client
|
|
|
|
ClientParams 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
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// PutContainer sends a request to save the container in FrostFS.
|
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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func PutContainer(ctx context.Context, prm PutContainerPrm) (res PutContainerRes, err error) {
|
2023-08-10 08:43:17 +00:00
|
|
|
cliRes, err := prm.Client.ContainerPut(ctx, prm.ClientParams)
|
2022-05-31 17:00:41 +00:00
|
|
|
if err == nil {
|
2022-08-22 11:04:00 +00:00
|
|
|
res.cnr = cliRes.ID()
|
2022-05-31 17:00:41 +00:00
|
|
|
}
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetContainerPrm groups parameters of GetContainer operation.
|
|
|
|
type GetContainerPrm struct {
|
2023-08-10 08:09:36 +00:00
|
|
|
Client *client.Client
|
|
|
|
ClientParams client.PrmContainerGet
|
2022-01-21 16:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetContainer sets identifier of the container to be read.
|
2023-08-10 08:09:36 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use GetContainerPrm.ClientParams.ContainerID instead.
|
2022-01-21 16:53:06 +00:00
|
|
|
func (x *GetContainerPrm) SetContainer(id cid.ID) {
|
2023-08-10 08:09:36 +00:00
|
|
|
x.ClientParams.ContainerID = &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-04-29 16:57:31 +00:00
|
|
|
func (x GetContainerRes) Container() containerSDK.Container {
|
2021-11-06 11:13:04 +00:00
|
|
|
return x.cliRes.Container()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// GetContainer reads a container from FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func GetContainer(ctx context.Context, prm GetContainerPrm) (res GetContainerRes, err error) {
|
2023-08-10 08:09:36 +00:00
|
|
|
res.cliRes, err = prm.Client.ContainerGet(ctx, prm.ClientParams)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-17 10:22:05 +00:00
|
|
|
// IsACLExtendable checks if ACL of the container referenced by the given identifier
|
|
|
|
// can be extended. Client connection MUST BE correctly established in advance.
|
2023-05-24 13:51:57 +00:00
|
|
|
func IsACLExtendable(ctx context.Context, c *client.Client, cnr cid.ID) (bool, error) {
|
2023-08-10 08:09:36 +00:00
|
|
|
prm := GetContainerPrm{
|
|
|
|
Client: c,
|
|
|
|
ClientParams: client.PrmContainerGet{
|
|
|
|
ContainerID: &cnr,
|
|
|
|
},
|
|
|
|
}
|
2022-08-17 10:22:05 +00:00
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
res, err := GetContainer(ctx, prm)
|
2022-08-17 10:22:05 +00:00
|
|
|
if err != nil {
|
2023-02-03 16:29:25 +00:00
|
|
|
return false, fmt.Errorf("get container from the FrostFS: %w", err)
|
2022-08-17 10:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res.Container().BasicACL().Extendable(), nil
|
|
|
|
}
|
|
|
|
|
2021-10-28 14:48:46 +00:00
|
|
|
// DeleteContainerPrm groups parameters of DeleteContainerPrm operation.
|
|
|
|
type DeleteContainerPrm struct {
|
2023-08-10 10:05:12 +00:00
|
|
|
Client *client.Client
|
|
|
|
ClientParams 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{}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// DeleteContainer sends a request to remove a container from FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func DeleteContainer(ctx context.Context, prm DeleteContainerPrm) (res DeleteContainerRes, err error) {
|
2023-08-10 10:05:12 +00:00
|
|
|
_, err = prm.Client.ContainerDelete(ctx, prm.ClientParams)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// EACLPrm groups parameters of EACL operation.
|
|
|
|
type EACLPrm struct {
|
2023-08-18 14:44:17 +00:00
|
|
|
Client *client.Client
|
|
|
|
ClientParams 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.
|
2022-08-22 11:04:00 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// EACL reads eACL table from FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func EACL(ctx context.Context, prm EACLPrm) (res EACLRes, err error) {
|
2023-08-18 14:44:17 +00:00
|
|
|
res.cliRes, err = prm.Client.ContainerEACL(ctx, prm.ClientParams)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEACLPrm groups parameters of SetEACL operation.
|
|
|
|
type SetEACLPrm struct {
|
2023-08-21 16:11:43 +00:00
|
|
|
Client *client.Client
|
|
|
|
ClientParams 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{}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// SetEACL requests to save an eACL table in FrostFS.
|
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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func SetEACL(ctx context.Context, prm SetEACLPrm) (res SetEACLRes, err error) {
|
2023-08-21 16:11:43 +00:00
|
|
|
_, err = prm.Client.ContainerSetEACL(ctx, prm.ClientParams)
|
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
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// NetworkInfo returns structured information about the FrostFS network.
|
2022-08-22 11:04:00 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// NetworkInfo reads information about the FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func NetworkInfo(ctx context.Context, prm NetworkInfoPrm) (res NetworkInfoRes, err error) {
|
|
|
|
res.cliRes, err = prm.cli.NetworkInfo(ctx, 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 {
|
2022-08-22 11:04:00 +00:00
|
|
|
return x.cliRes.NodeInfo()
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// LatestVersion returns the latest FrostFS API version in use.
|
2022-08-22 11:04:00 +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
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// NodeInfo requests information about the remote server from FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func NodeInfo(ctx context.Context, prm NodeInfoPrm) (res NodeInfoRes, err error) {
|
|
|
|
res.cliRes, err = prm.cli.EndpointInfo(ctx, prm.PrmEndpointInfo)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-17 12:37:01 +00:00
|
|
|
// NetMapSnapshotPrm groups parameters of NetMapSnapshot operation.
|
|
|
|
type NetMapSnapshotPrm struct {
|
|
|
|
commonPrm
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetMapSnapshotRes groups the resulting values of NetMapSnapshot operation.
|
|
|
|
type NetMapSnapshotRes struct {
|
|
|
|
cliRes *client.ResNetMapSnapshot
|
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// NetMap returns current local snapshot of the FrostFS network map.
|
2022-09-17 12:37:01 +00:00
|
|
|
func (x NetMapSnapshotRes) NetMap() netmap.NetMap {
|
|
|
|
return x.cliRes.NetMap()
|
|
|
|
}
|
|
|
|
|
|
|
|
// NetMapSnapshot requests current network view of the remote server.
|
|
|
|
//
|
|
|
|
// Returns any error which prevented the operation from completing correctly in error return.
|
2023-05-24 13:51:57 +00:00
|
|
|
func NetMapSnapshot(ctx context.Context, prm NetMapSnapshotPrm) (res NetMapSnapshotRes, err error) {
|
|
|
|
res.cliRes, err = prm.cli.NetMapSnapshot(ctx, client.PrmNetMapSnapshot{})
|
2022-09-17 12:37:01 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-28 14:48:46 +00:00
|
|
|
// 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func CreateSession(ctx context.Context, prm CreateSessionPrm) (res CreateSessionRes, err error) {
|
|
|
|
res.cliRes, err = prm.cli.SessionCreate(ctx, prm.PrmSessionCreate)
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutObjectPrm groups parameters of PutObject operation.
|
|
|
|
type PutObjectPrm struct {
|
|
|
|
commonObjectPrm
|
|
|
|
|
2023-05-15 12:24:29 +00:00
|
|
|
copyNum []uint32
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
hdr *objectSDK.Object
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
rdr io.Reader
|
2022-06-08 07:55:52 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
headerCallback func(*objectSDK.Object)
|
2023-06-29 06:48:32 +00:00
|
|
|
|
|
|
|
prepareLocally bool
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetHeader sets object header.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (x *PutObjectPrm) SetHeader(hdr *objectSDK.Object) {
|
2021-10-28 14:48:46 +00:00
|
|
|
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.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (x *PutObjectPrm) SetHeaderCallback(f func(*objectSDK.Object)) {
|
2022-06-08 07:55:52 +00:00
|
|
|
x.headerCallback = f
|
|
|
|
}
|
|
|
|
|
2023-05-15 12:24:29 +00:00
|
|
|
// SetCopiesNumberByVectors sets ordered list of minimal required object copies numbers
|
|
|
|
// per placement vector.
|
|
|
|
func (x *PutObjectPrm) SetCopiesNumberByVectors(copiesNumbers []uint32) {
|
|
|
|
x.copyNum = copiesNumbers
|
|
|
|
}
|
|
|
|
|
2023-06-29 06:48:32 +00:00
|
|
|
// PrepareLocally generate object header on the client side.
|
|
|
|
// For big object - split locally too.
|
|
|
|
func (x *PutObjectPrm) PrepareLocally() {
|
|
|
|
x.prepareLocally = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *PutObjectPrm) convertToSDKPrm(ctx context.Context) (client.PrmObjectPutInit, error) {
|
|
|
|
var putPrm client.PrmObjectPutInit
|
|
|
|
if !x.prepareLocally && x.sessionToken != nil {
|
|
|
|
putPrm.WithinSession(*x.sessionToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if x.bearerToken != nil {
|
|
|
|
putPrm.WithBearerToken(*x.bearerToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
if x.local {
|
|
|
|
putPrm.MarkLocal()
|
|
|
|
}
|
|
|
|
|
|
|
|
putPrm.WithXHeaders(x.xHeaders...)
|
|
|
|
putPrm.SetCopiesNumberByVectors(x.copyNum)
|
|
|
|
|
|
|
|
if x.prepareLocally {
|
|
|
|
res, err := x.cli.NetworkInfo(ctx, client.PrmNetworkInfo{})
|
|
|
|
if err != nil {
|
|
|
|
return client.PrmObjectPutInit{}, err
|
|
|
|
}
|
|
|
|
putPrm.WithObjectMaxSize(res.Info().MaxObjectSize())
|
|
|
|
putPrm.WithEpochSource(epochSource(res.Info().CurrentEpoch()))
|
|
|
|
putPrm.WithoutHomomorphicHash(res.Info().HomomorphicHashingDisabled())
|
|
|
|
}
|
|
|
|
return putPrm, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-06-29 06:48:32 +00:00
|
|
|
type epochSource uint64
|
|
|
|
|
|
|
|
func (s epochSource) CurrentEpoch() uint64 {
|
|
|
|
return uint64(s)
|
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// PutObject saves the object in FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func PutObject(ctx context.Context, prm PutObjectPrm) (*PutObjectRes, error) {
|
2023-06-29 06:48:32 +00:00
|
|
|
sdkPrm, err := prm.convertToSDKPrm(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("unable to create parameters of object put operation: %w", err)
|
2022-02-25 09:20:49 +00:00
|
|
|
}
|
2023-06-29 06:48:32 +00:00
|
|
|
wrt, err := prm.cli.ObjectPutInit(ctx, sdkPrm)
|
2022-08-29 08:57:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("init object writing: %w", err)
|
|
|
|
}
|
2022-03-03 12:30:20 +00:00
|
|
|
|
2023-06-29 06:44:11 +00:00
|
|
|
if wrt.WriteHeader(ctx, *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 {
|
2023-02-06 10:28:29 +00:00
|
|
|
const defaultBufferSizePut = 3 << 20 // Maximum chunk size is 3 MiB in the SDK.
|
2022-02-25 09:20:49 +00:00
|
|
|
|
|
|
|
if sz == 0 || sz > defaultBufferSizePut {
|
|
|
|
sz = defaultBufferSizePut
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := make([]byte, sz)
|
|
|
|
|
|
|
|
var n int
|
|
|
|
|
|
|
|
for {
|
|
|
|
n, err = prm.rdr.Read(buf)
|
|
|
|
if n > 0 {
|
2023-06-29 06:44:11 +00:00
|
|
|
if !wrt.WritePayloadChunk(ctx, buf[:n]) {
|
2022-02-25 09:20:49 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if errors.Is(err, io.EOF) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("read payload: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-29 06:44:11 +00:00
|
|
|
cliRes, err := wrt.Close(ctx)
|
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-08-22 11:04:00 +00:00
|
|
|
return &PutObjectRes{
|
|
|
|
id: cliRes.StoredObjectID(),
|
|
|
|
}, 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
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// DeleteObject marks an object to be removed from FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func DeleteObject(ctx context.Context, prm DeleteObjectPrm) (*DeleteObjectRes, error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
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
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
cliRes, err := prm.cli.ObjectDelete(ctx, delPrm)
|
2022-02-25 09:20:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("remove object via client: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &DeleteObjectRes{
|
2022-08-22 11:04:00 +00:00
|
|
|
tomb: cliRes.Tombstone(),
|
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
|
2023-07-06 12:36:41 +00:00
|
|
|
headerCallback func(*objectSDK.Object)
|
2022-03-09 10:35:52 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (p *GetObjectPrm) SetHeaderCallback(f func(*objectSDK.Object)) {
|
2022-03-09 10:35:52 +00:00
|
|
|
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 {
|
2023-07-06 12:36:41 +00:00
|
|
|
hdr *objectSDK.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.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (x GetObjectRes) Header() *objectSDK.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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func GetObject(ctx context.Context, prm GetObjectPrm) (*GetObjectRes, error) {
|
2023-08-29 10:25:54 +00:00
|
|
|
cnr := prm.objAddr.Container()
|
|
|
|
obj := prm.objAddr.Object()
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2023-08-29 10:25:54 +00:00
|
|
|
getPrm := client.PrmObjectGet{
|
|
|
|
XHeaders: prm.xHeaders,
|
|
|
|
BearerToken: prm.bearerToken,
|
|
|
|
Session: prm.sessionToken,
|
|
|
|
Raw: prm.raw,
|
|
|
|
Local: prm.local,
|
|
|
|
ContainerID: &cnr,
|
|
|
|
ObjectID: &obj,
|
2022-02-25 09:20:49 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
rdr, err := prm.cli.ObjectGetInit(ctx, getPrm)
|
2022-02-25 09:20:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("init object reading on client: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
var hdr objectSDK.Object
|
2022-02-25 09:20:49 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// SetMainOnlyFlag sets flag to get only main fields of an object header in terms of FrostFS 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 {
|
2023-07-06 12:36:41 +00:00
|
|
|
hdr *objectSDK.Object
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Header returns the requested object header.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (x HeadObjectRes) Header() *objectSDK.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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func HeadObject(ctx context.Context, prm HeadObjectPrm) (*HeadObjectRes, error) {
|
2023-08-29 10:25:54 +00:00
|
|
|
cnr := prm.objAddr.Container()
|
|
|
|
obj := prm.objAddr.Object()
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2023-08-29 10:25:54 +00:00
|
|
|
headPrm := client.PrmObjectHead{
|
|
|
|
XHeaders: prm.xHeaders,
|
|
|
|
BearerToken: prm.bearerToken,
|
|
|
|
Session: prm.sessionToken,
|
|
|
|
Raw: prm.raw,
|
|
|
|
Local: prm.local,
|
|
|
|
ContainerID: &cnr,
|
|
|
|
ObjectID: &obj,
|
2022-02-25 09:20:49 +00:00
|
|
|
}
|
2021-10-28 14:48:46 +00:00
|
|
|
|
2023-08-29 10:25:54 +00:00
|
|
|
res, err := prm.cli.ObjectHead(ctx, headPrm)
|
2022-02-25 09:20:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("read object header via client: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
var hdr objectSDK.Object
|
2022-02-25 09:20:49 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
filters objectSDK.SearchFilters
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetFilters sets search filters.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (x *SearchObjectsPrm) SetFilters(filters objectSDK.SearchFilters) {
|
2021-10-28 14:48:46 +00:00
|
|
|
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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func SearchObjects(ctx context.Context, prm SearchObjectsPrm) (*SearchObjectsRes, error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
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
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
rdr, err := prm.cli.ObjectSearchInit(ctx, cliPrm)
|
2022-02-25 09:20:49 +00:00
|
|
|
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
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
rngs []*objectSDK.Range
|
2021-10-28 14:48:46 +00:00
|
|
|
|
|
|
|
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.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (x *HashPayloadRangesPrm) SetRanges(rngs []*objectSDK.Range) {
|
2021-10-28 14:48:46 +00:00
|
|
|
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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func HashPayloadRanges(ctx context.Context, prm HashPayloadRangesPrm) (*HashPayloadRangesRes, error) {
|
2022-02-25 09:20:49 +00:00
|
|
|
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
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
res, err := prm.cli.ObjectHash(ctx, cliPrm)
|
2022-02-25 09:20:49 +00:00
|
|
|
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
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
rng *objectSDK.Range
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetRange sets payload range to read.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (x *PayloadRangePrm) SetRange(rng *objectSDK.Range) {
|
2021-10-28 14:48:46 +00:00
|
|
|
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{}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// PayloadRange reads object payload range from FrostFS 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.
|
2023-05-24 13:51:57 +00:00
|
|
|
func PayloadRange(ctx context.Context, prm PayloadRangePrm) (*PayloadRangeRes, error) {
|
2023-08-29 10:25:54 +00:00
|
|
|
cnr := prm.objAddr.Container()
|
|
|
|
obj := prm.objAddr.Object()
|
|
|
|
|
|
|
|
rangePrm := client.PrmObjectRange{
|
|
|
|
XHeaders: prm.xHeaders,
|
|
|
|
BearerToken: prm.bearerToken,
|
|
|
|
Session: prm.sessionToken,
|
|
|
|
Raw: prm.raw,
|
|
|
|
Local: prm.local,
|
|
|
|
ContainerID: &cnr,
|
|
|
|
ObjectID: &obj,
|
|
|
|
Offset: prm.rng.GetOffset(),
|
|
|
|
Length: prm.rng.GetLength(),
|
|
|
|
}
|
|
|
|
|
|
|
|
rdr, err := prm.cli.ObjectRangeInit(ctx, rangePrm)
|
2022-02-25 09:20:49 +00:00
|
|
|
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
|
|
|
}
|
2022-04-29 16:57:31 +00:00
|
|
|
|
|
|
|
// SyncContainerPrm groups parameters of SyncContainerSettings operation.
|
|
|
|
type SyncContainerPrm struct {
|
|
|
|
commonPrm
|
|
|
|
c *containerSDK.Container
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetContainer sets a container that is required to be synced.
|
|
|
|
func (s *SyncContainerPrm) SetContainer(c *containerSDK.Container) {
|
|
|
|
s.c = c
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncContainerRes groups resulting values of SyncContainerSettings
|
|
|
|
// operation.
|
|
|
|
type SyncContainerRes struct{}
|
|
|
|
|
2023-02-03 16:29:25 +00:00
|
|
|
// SyncContainerSettings reads global network config from FrostFS and
|
2022-04-29 16:57:31 +00:00
|
|
|
// syncs container settings with it.
|
|
|
|
//
|
|
|
|
// Interrupts on any writer error.
|
|
|
|
//
|
|
|
|
// Panics if a container passed as a parameter is nil.
|
2023-05-24 13:51:57 +00:00
|
|
|
func SyncContainerSettings(ctx context.Context, prm SyncContainerPrm) (*SyncContainerRes, error) {
|
2022-04-29 16:57:31 +00:00
|
|
|
if prm.c == nil {
|
|
|
|
panic("sync container settings with the network: nil container")
|
|
|
|
}
|
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
err := client.SyncContainerWithNetwork(ctx, prm.c, prm.cli)
|
2022-04-29 16:57:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return new(SyncContainerRes), nil
|
|
|
|
}
|