2022-12-20 08:38:58 +00:00
|
|
|
package frostfs
|
2022-03-01 19:02:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
objectv2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
2024-09-27 08:14:45 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/frostfs"
|
2024-09-27 09:18:41 +00:00
|
|
|
frosterr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/errors"
|
2024-10-14 14:03:53 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/util"
|
2024-11-18 12:31:09 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/ape"
|
2023-08-03 12:08:22 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2024-07-22 09:00:17 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2023-08-03 12:08:22 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2022-03-01 19:02:24 +00:00
|
|
|
)
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// FrostFS represents virtual connection to the FrostFS network.
|
2022-03-01 19:02:24 +00:00
|
|
|
// It is used to provide an interface to dependent packages
|
2022-12-20 08:38:58 +00:00
|
|
|
// which work with FrostFS.
|
|
|
|
type FrostFS struct {
|
2022-05-04 10:00:14 +00:00
|
|
|
pool *pool.Pool
|
|
|
|
await pool.WaitParams
|
2023-08-03 12:08:22 +00:00
|
|
|
owner user.ID
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 10:00:14 +00:00
|
|
|
const (
|
|
|
|
defaultPollInterval = time.Second // overrides default value from pool
|
|
|
|
defaultPollTimeout = 120 * time.Second // same as default value from pool
|
|
|
|
)
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// NewFrostFS creates new FrostFS using provided pool.Pool.
|
2023-08-03 12:08:22 +00:00
|
|
|
func NewFrostFS(p *pool.Pool, key *keys.PrivateKey) *FrostFS {
|
2023-08-21 09:04:10 +00:00
|
|
|
await := pool.WaitParams{PollInterval: defaultPollInterval, Timeout: defaultPollTimeout}
|
2022-05-04 10:00:14 +00:00
|
|
|
|
2023-08-03 12:08:22 +00:00
|
|
|
var owner user.ID
|
|
|
|
user.IDFromKey(&owner, key.PrivateKey.PublicKey)
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
return &FrostFS{
|
2022-05-04 10:00:14 +00:00
|
|
|
pool: p,
|
|
|
|
await: await,
|
2023-08-03 12:08:22 +00:00
|
|
|
owner: owner,
|
2022-05-04 10:00:14 +00:00
|
|
|
}
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// TimeToEpoch implements layer.FrostFS interface method.
|
2022-12-20 08:38:58 +00:00
|
|
|
func (x *FrostFS) TimeToEpoch(ctx context.Context, now, futureTime time.Time) (uint64, uint64, error) {
|
2024-10-14 14:03:53 +00:00
|
|
|
if futureTime.Before(now) {
|
2022-03-05 08:53:01 +00:00
|
|
|
return 0, 0, fmt.Errorf("time '%s' must be in the future (after %s)",
|
|
|
|
futureTime.Format(time.RFC3339), now.Format(time.RFC3339))
|
|
|
|
}
|
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
networkInfo, err := x.pool.NetworkInfo(ctx)
|
2022-03-01 19:02:24 +00:00
|
|
|
if err != nil {
|
2023-06-13 14:47:31 +00:00
|
|
|
return 0, 0, handleObjectError("get network info via client", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-10-14 14:03:53 +00:00
|
|
|
epoch, err := util.TimeToEpoch(&networkInfo, now, futureTime)
|
|
|
|
if err != nil {
|
|
|
|
return 0, 0, err
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-10-14 14:03:53 +00:00
|
|
|
return networkInfo.CurrentEpoch(), epoch, nil
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// Container implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) Container(ctx context.Context, layerPrm frostfs.PrmContainer) (*container.Container, error) {
|
2024-03-01 14:11:07 +00:00
|
|
|
prm := pool.PrmContainerGet{
|
|
|
|
ContainerID: layerPrm.ContainerID,
|
|
|
|
Session: layerPrm.SessionToken,
|
|
|
|
}
|
2022-04-07 14:36:44 +00:00
|
|
|
|
|
|
|
res, err := x.pool.GetContainer(ctx, prm)
|
2022-03-01 19:02:24 +00:00
|
|
|
if err != nil {
|
2023-06-13 14:47:31 +00:00
|
|
|
return nil, handleObjectError("read container via connection pool", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-08-24 16:03:48 +00:00
|
|
|
return &res, nil
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// CreateContainer implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) CreateContainer(ctx context.Context, prm frostfs.PrmContainerCreate) (*frostfs.ContainerCreateResult, error) {
|
2022-06-29 14:43:52 +00:00
|
|
|
var cnr container.Container
|
|
|
|
cnr.Init()
|
|
|
|
cnr.SetPlacementPolicy(prm.Policy)
|
|
|
|
cnr.SetOwner(prm.Creator)
|
2022-11-08 09:12:55 +00:00
|
|
|
|
|
|
|
creationTime := prm.CreationTime
|
|
|
|
if creationTime.IsZero() {
|
|
|
|
creationTime = time.Now()
|
|
|
|
}
|
|
|
|
container.SetCreationTime(&cnr, creationTime)
|
2022-03-01 19:02:24 +00:00
|
|
|
|
|
|
|
if prm.Name != "" {
|
2022-06-30 08:58:51 +00:00
|
|
|
var d container.Domain
|
|
|
|
d.SetName(prm.Name)
|
2023-11-23 07:44:50 +00:00
|
|
|
d.SetZone(prm.Zone)
|
2022-06-30 08:58:51 +00:00
|
|
|
|
|
|
|
container.WriteDomain(&cnr, d)
|
2022-06-29 14:43:52 +00:00
|
|
|
container.SetName(&cnr, prm.Name)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 14:43:52 +00:00
|
|
|
for i := range prm.AdditionalAttributes {
|
|
|
|
cnr.SetAttribute(prm.AdditionalAttributes[i][0], prm.AdditionalAttributes[i][1])
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 12:47:21 +00:00
|
|
|
err := pool.SyncContainerWithNetwork(ctx, &cnr, x.pool)
|
|
|
|
if err != nil {
|
2023-08-25 10:06:43 +00:00
|
|
|
return nil, handleObjectError("sync container with the network state", err)
|
2022-05-16 07:46:24 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 12:08:22 +00:00
|
|
|
prmPut := pool.PrmContainerPut{
|
|
|
|
ClientParams: client.PrmContainerPut{
|
|
|
|
Container: &cnr,
|
|
|
|
Session: prm.SessionToken,
|
|
|
|
},
|
|
|
|
WaitParams: &x.await,
|
2022-06-21 15:21:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 19:02:24 +00:00
|
|
|
// send request to save the container
|
2022-04-07 14:36:44 +00:00
|
|
|
idCnr, err := x.pool.PutContainer(ctx, prmPut)
|
2024-09-27 08:14:45 +00:00
|
|
|
return &frostfs.ContainerCreateResult{
|
2023-08-25 10:06:43 +00:00
|
|
|
ContainerID: idCnr,
|
|
|
|
HomomorphicHashDisabled: container.IsHomomorphicHashingDisabled(cnr),
|
|
|
|
}, handleObjectError("save container via connection pool", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-11-18 12:31:09 +00:00
|
|
|
// AddContainerPolicyChain implements frostfs.FrostFS interface method.
|
|
|
|
func (x *FrostFS) AddContainerPolicyChain(ctx context.Context, prm frostfs.PrmAddContainerPolicyChain) error {
|
|
|
|
data, err := prm.Chain.MarshalBinary()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
prmAddAPEChain := pool.PrmAddAPEChain{
|
|
|
|
Target: ape.ChainTarget{
|
|
|
|
TargetType: ape.TargetTypeContainer,
|
|
|
|
Name: prm.ContainerID.EncodeToString(),
|
|
|
|
},
|
|
|
|
Chain: ape.Chain{Raw: data},
|
|
|
|
}
|
|
|
|
|
|
|
|
err = x.pool.AddAPEChain(ctx, prmAddAPEChain)
|
|
|
|
return handleObjectError("add ape chain to container", err)
|
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// UserContainers implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) UserContainers(ctx context.Context, layerPrm frostfs.PrmUserContainers) ([]cid.ID, error) {
|
2024-03-01 14:11:07 +00:00
|
|
|
prm := pool.PrmContainerList{
|
|
|
|
OwnerID: layerPrm.UserID,
|
|
|
|
Session: layerPrm.SessionToken,
|
|
|
|
}
|
2022-04-07 14:36:44 +00:00
|
|
|
|
|
|
|
r, err := x.pool.ListContainers(ctx, prm)
|
2023-06-13 14:47:31 +00:00
|
|
|
return r, handleObjectError("list user containers via connection pool", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// DeleteContainer implements layer.FrostFS interface method.
|
2022-12-20 08:38:58 +00:00
|
|
|
func (x *FrostFS) DeleteContainer(ctx context.Context, id cid.ID, token *session.Container) error {
|
2023-08-21 09:04:10 +00:00
|
|
|
prm := pool.PrmContainerDelete{ContainerID: id, Session: token, WaitParams: &x.await}
|
2022-06-22 13:15:45 +00:00
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
err := x.pool.DeleteContainer(ctx, prm)
|
2023-06-13 14:47:31 +00:00
|
|
|
return handleObjectError("delete container via connection pool", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// CreateObject implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) CreateObject(ctx context.Context, prm frostfs.PrmObjectCreate) (*frostfs.CreateObjectResult, error) {
|
2022-03-01 19:02:24 +00:00
|
|
|
attrNum := len(prm.Attributes) + 1 // + creation time
|
|
|
|
|
2022-09-07 06:59:24 +00:00
|
|
|
if prm.Filepath != "" {
|
2022-03-01 19:02:24 +00:00
|
|
|
attrNum++
|
|
|
|
}
|
|
|
|
|
2022-03-16 09:02:16 +00:00
|
|
|
attrs := make([]object.Attribute, 0, attrNum)
|
2022-03-01 19:02:24 +00:00
|
|
|
var a *object.Attribute
|
|
|
|
|
|
|
|
a = object.NewAttribute()
|
|
|
|
a.SetKey(object.AttributeTimestamp)
|
2022-11-08 09:12:55 +00:00
|
|
|
|
|
|
|
creationTime := prm.CreationTime
|
|
|
|
if creationTime.IsZero() {
|
|
|
|
creationTime = time.Now()
|
|
|
|
}
|
|
|
|
a.SetValue(strconv.FormatInt(creationTime.Unix(), 10))
|
|
|
|
|
2022-03-16 09:02:16 +00:00
|
|
|
attrs = append(attrs, *a)
|
2022-03-01 19:02:24 +00:00
|
|
|
|
|
|
|
for i := range prm.Attributes {
|
|
|
|
a = object.NewAttribute()
|
|
|
|
a.SetKey(prm.Attributes[i][0])
|
|
|
|
a.SetValue(prm.Attributes[i][1])
|
2022-03-16 09:02:16 +00:00
|
|
|
attrs = append(attrs, *a)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 06:59:24 +00:00
|
|
|
if prm.Filepath != "" {
|
2022-03-01 19:02:24 +00:00
|
|
|
a = object.NewAttribute()
|
2022-09-07 06:59:24 +00:00
|
|
|
a.SetKey(object.AttributeFilePath)
|
|
|
|
a.SetValue(prm.Filepath)
|
2022-03-16 09:02:16 +00:00
|
|
|
attrs = append(attrs, *a)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 14:36:30 +00:00
|
|
|
obj := object.New()
|
2022-04-25 09:57:58 +00:00
|
|
|
obj.SetContainerID(prm.Container)
|
2024-03-01 14:11:07 +00:00
|
|
|
obj.SetOwnerID(x.owner)
|
2022-03-04 14:36:30 +00:00
|
|
|
obj.SetAttributes(attrs...)
|
|
|
|
obj.SetPayloadSize(prm.PayloadSize)
|
|
|
|
|
2024-02-20 08:07:28 +00:00
|
|
|
if prm.BearerToken == nil && prm.PrivateKey != nil {
|
|
|
|
var owner user.ID
|
|
|
|
user.IDFromKey(&owner, prm.PrivateKey.PublicKey)
|
2024-03-01 14:11:07 +00:00
|
|
|
obj.SetOwnerID(owner)
|
2024-02-20 08:07:28 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 14:36:30 +00:00
|
|
|
if len(prm.Locks) > 0 {
|
|
|
|
lock := new(object.Lock)
|
|
|
|
lock.WriteMembers(prm.Locks)
|
|
|
|
objectv2.WriteLock(obj.ToV2(), (objectv2.Lock)(*lock))
|
|
|
|
}
|
2022-03-01 19:02:24 +00:00
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
var prmPut pool.PrmObjectPut
|
|
|
|
prmPut.SetHeader(*obj)
|
|
|
|
prmPut.SetPayload(prm.Payload)
|
2023-04-24 23:49:12 +00:00
|
|
|
prmPut.SetCopiesNumberVector(prm.CopiesNumber)
|
2023-07-14 12:30:47 +00:00
|
|
|
prmPut.SetClientCut(prm.ClientCut)
|
2023-08-25 10:06:43 +00:00
|
|
|
prmPut.WithoutHomomorphicHash(prm.WithoutHomomorphicHash)
|
|
|
|
prmPut.SetBufferMaxSize(prm.BufferMaxSize)
|
2022-03-01 19:02:24 +00:00
|
|
|
|
|
|
|
if prm.BearerToken != nil {
|
2022-04-25 09:57:58 +00:00
|
|
|
prmPut.UseBearer(*prm.BearerToken)
|
2022-03-01 19:02:24 +00:00
|
|
|
} else {
|
2022-04-07 14:36:44 +00:00
|
|
|
prmPut.UseKey(prm.PrivateKey)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-23 12:24:44 +00:00
|
|
|
res, err := x.pool.PutObject(ctx, prmPut)
|
|
|
|
if err = handleObjectError("save object via connection pool", err); err != nil {
|
2024-07-22 09:00:17 +00:00
|
|
|
return nil, err
|
2024-07-23 12:24:44 +00:00
|
|
|
}
|
|
|
|
|
2024-09-27 08:14:45 +00:00
|
|
|
return &frostfs.CreateObjectResult{
|
2024-07-22 09:00:17 +00:00
|
|
|
ObjectID: res.ObjectID,
|
|
|
|
CreationEpoch: res.Epoch,
|
|
|
|
}, nil
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// wraps io.ReadCloser and transforms Read errors related to access violation
|
2022-12-20 08:38:58 +00:00
|
|
|
// to frostfs.ErrAccessDenied.
|
2022-03-01 19:02:24 +00:00
|
|
|
type payloadReader struct {
|
|
|
|
io.ReadCloser
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x payloadReader) Read(p []byte) (int, error) {
|
|
|
|
n, err := x.ReadCloser.Read(p)
|
2023-08-16 12:54:47 +00:00
|
|
|
if err != nil && errors.Is(err, io.EOF) {
|
|
|
|
return n, err
|
|
|
|
}
|
2023-06-13 14:47:31 +00:00
|
|
|
return n, handleObjectError("read payload", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// HeadObject implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) HeadObject(ctx context.Context, prm frostfs.PrmObjectHead) (*object.Object, error) {
|
2024-07-15 12:47:19 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(prm.Container)
|
|
|
|
addr.SetObject(prm.Object)
|
|
|
|
|
|
|
|
var prmHead pool.PrmObjectHead
|
|
|
|
prmHead.SetAddress(addr)
|
|
|
|
|
|
|
|
if prm.BearerToken != nil {
|
|
|
|
prmHead.UseBearer(*prm.BearerToken)
|
|
|
|
} else {
|
|
|
|
prmHead.UseKey(prm.PrivateKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := x.pool.HeadObject(ctx, prmHead)
|
|
|
|
if err != nil {
|
|
|
|
return nil, handleObjectError("read object header via connection pool", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// GetObject implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) GetObject(ctx context.Context, prm frostfs.PrmObjectGet) (*frostfs.Object, error) {
|
2022-05-25 17:25:43 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(prm.Container)
|
|
|
|
addr.SetObject(prm.Object)
|
2022-03-01 19:02:24 +00:00
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
var prmGet pool.PrmObjectGet
|
|
|
|
prmGet.SetAddress(addr)
|
2022-03-01 19:02:24 +00:00
|
|
|
|
|
|
|
if prm.BearerToken != nil {
|
2022-04-25 09:57:58 +00:00
|
|
|
prmGet.UseBearer(*prm.BearerToken)
|
2022-03-01 19:02:24 +00:00
|
|
|
} else {
|
2022-04-07 14:36:44 +00:00
|
|
|
prmGet.UseKey(prm.PrivateKey)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-15 12:47:19 +00:00
|
|
|
res, err := x.pool.GetObject(ctx, prmGet)
|
|
|
|
if err != nil {
|
|
|
|
return nil, handleObjectError("init full object reading via connection pool", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-09-27 08:14:45 +00:00
|
|
|
return &frostfs.Object{
|
2024-07-15 12:47:19 +00:00
|
|
|
Header: res.Header,
|
|
|
|
Payload: res.Payload,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// RangeObject implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) RangeObject(ctx context.Context, prm frostfs.PrmObjectRange) (io.ReadCloser, error) {
|
2024-07-15 12:47:19 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(prm.Container)
|
|
|
|
addr.SetObject(prm.Object)
|
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
var prmRange pool.PrmObjectRange
|
|
|
|
prmRange.SetAddress(addr)
|
|
|
|
prmRange.SetOffset(prm.PayloadRange[0])
|
|
|
|
prmRange.SetLength(prm.PayloadRange[1])
|
|
|
|
|
|
|
|
if prm.BearerToken != nil {
|
2022-04-25 09:57:58 +00:00
|
|
|
prmRange.UseBearer(*prm.BearerToken)
|
2022-04-07 14:36:44 +00:00
|
|
|
} else {
|
|
|
|
prmRange.UseKey(prm.PrivateKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := x.pool.ObjectRange(ctx, prmRange)
|
2022-03-01 19:02:24 +00:00
|
|
|
if err != nil {
|
2023-06-13 14:47:31 +00:00
|
|
|
return nil, handleObjectError("init payload range reading via connection pool", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-15 12:47:19 +00:00
|
|
|
return payloadReader{&res}, nil
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// DeleteObject implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) DeleteObject(ctx context.Context, prm frostfs.PrmObjectDelete) error {
|
2022-05-25 17:25:43 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(prm.Container)
|
|
|
|
addr.SetObject(prm.Object)
|
2022-03-01 19:02:24 +00:00
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
var prmDelete pool.PrmObjectDelete
|
|
|
|
prmDelete.SetAddress(addr)
|
2022-03-01 19:02:24 +00:00
|
|
|
|
|
|
|
if prm.BearerToken != nil {
|
2022-04-25 09:57:58 +00:00
|
|
|
prmDelete.UseBearer(*prm.BearerToken)
|
2022-03-01 19:02:24 +00:00
|
|
|
} else {
|
2022-04-07 14:36:44 +00:00
|
|
|
prmDelete.UseKey(prm.PrivateKey)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 14:36:44 +00:00
|
|
|
err := x.pool.DeleteObject(ctx, prmDelete)
|
2023-06-13 14:47:31 +00:00
|
|
|
return handleObjectError("mark object removal via connection pool", err)
|
2022-04-21 08:49:56 +00:00
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// SearchObjects implements layer.FrostFS interface method.
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) SearchObjects(ctx context.Context, prm frostfs.PrmObjectSearch) ([]oid.ID, error) {
|
2023-06-13 09:34:19 +00:00
|
|
|
filters := object.NewSearchFilters()
|
|
|
|
filters.AddRootFilter()
|
|
|
|
|
|
|
|
if prm.ExactAttribute[0] != "" {
|
|
|
|
filters.AddFilter(prm.ExactAttribute[0], prm.ExactAttribute[1], object.MatchStringEqual)
|
|
|
|
}
|
|
|
|
|
|
|
|
if prm.FilePrefix != "" {
|
|
|
|
filters.AddFilter(object.AttributeFileName, prm.FilePrefix, object.MatchCommonPrefix)
|
|
|
|
}
|
|
|
|
|
|
|
|
var prmSearch pool.PrmObjectSearch
|
|
|
|
prmSearch.SetContainerID(prm.Container)
|
|
|
|
prmSearch.SetFilters(filters)
|
|
|
|
|
|
|
|
if prm.BearerToken != nil {
|
|
|
|
prmSearch.UseBearer(*prm.BearerToken)
|
|
|
|
} else {
|
|
|
|
prmSearch.UseKey(prm.PrivateKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := x.pool.SearchObjects(ctx, prmSearch)
|
|
|
|
if err != nil {
|
|
|
|
return nil, handleObjectError("init object search via connection pool", err)
|
|
|
|
}
|
|
|
|
defer res.Close()
|
|
|
|
|
|
|
|
var buf []oid.ID
|
|
|
|
err = res.Iterate(func(id oid.ID) bool {
|
|
|
|
buf = append(buf, id)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
return buf, handleObjectError("read object list", err)
|
|
|
|
}
|
|
|
|
|
2024-07-22 09:00:17 +00:00
|
|
|
// NetworkInfo implements layer.FrostFS interface method.
|
|
|
|
func (x *FrostFS) NetworkInfo(ctx context.Context) (netmap.NetworkInfo, error) {
|
|
|
|
ni, err := x.pool.NetworkInfo(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return ni, handleObjectError("get network info via connection pool", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ni, nil
|
|
|
|
}
|
|
|
|
|
2024-09-27 08:14:45 +00:00
|
|
|
func (x *FrostFS) PatchObject(ctx context.Context, prm frostfs.PrmObjectPatch) (oid.ID, error) {
|
2024-08-13 15:21:16 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(prm.Container)
|
|
|
|
addr.SetObject(prm.Object)
|
|
|
|
|
|
|
|
var prmPatch pool.PrmObjectPatch
|
|
|
|
prmPatch.SetAddress(addr)
|
|
|
|
|
|
|
|
var rng object.Range
|
2024-08-20 09:35:07 +00:00
|
|
|
rng.SetOffset(prm.Offset)
|
|
|
|
rng.SetLength(prm.Length)
|
|
|
|
if prm.Length+prm.Offset > prm.ObjectSize {
|
|
|
|
rng.SetLength(prm.ObjectSize - prm.Offset)
|
2024-08-13 15:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prmPatch.SetRange(&rng)
|
|
|
|
prmPatch.SetPayloadReader(prm.Payload)
|
|
|
|
|
|
|
|
if prm.BearerToken != nil {
|
|
|
|
prmPatch.UseBearer(*prm.BearerToken)
|
|
|
|
} else {
|
|
|
|
prmPatch.UseKey(prm.PrivateKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := x.pool.PatchObject(ctx, prmPatch)
|
|
|
|
if err != nil {
|
|
|
|
return oid.ID{}, handleObjectError("patch object via connection pool", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.ObjectID, nil
|
|
|
|
}
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// ResolverFrostFS represents virtual connection to the FrostFS network.
|
|
|
|
// It implements resolver.FrostFS.
|
|
|
|
type ResolverFrostFS struct {
|
2022-03-25 10:28:39 +00:00
|
|
|
pool *pool.Pool
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// NewResolverFrostFS creates new ResolverFrostFS using provided pool.Pool.
|
|
|
|
func NewResolverFrostFS(p *pool.Pool) *ResolverFrostFS {
|
|
|
|
return &ResolverFrostFS{pool: p}
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// SystemDNS implements resolver.FrostFS interface method.
|
|
|
|
func (x *ResolverFrostFS) SystemDNS(ctx context.Context) (string, error) {
|
2022-04-07 14:36:44 +00:00
|
|
|
networkInfo, err := x.pool.NetworkInfo(ctx)
|
2022-03-01 19:02:24 +00:00
|
|
|
if err != nil {
|
2023-06-13 14:47:31 +00:00
|
|
|
return "", handleObjectError("read network info via client", err)
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 19:31:41 +00:00
|
|
|
domain := networkInfo.RawNetworkParameter("SystemDNS")
|
|
|
|
if domain == nil {
|
2022-03-01 19:02:24 +00:00
|
|
|
return "", errors.New("system DNS parameter not found or empty")
|
|
|
|
}
|
|
|
|
|
2022-06-15 19:31:41 +00:00
|
|
|
return string(domain), nil
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
2022-03-25 10:28:39 +00:00
|
|
|
|
2023-06-13 14:47:31 +00:00
|
|
|
func handleObjectError(msg string, err error) error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-27 09:18:41 +00:00
|
|
|
if reason, ok := frosterr.IsErrObjectAccessDenied(err); ok {
|
2024-09-27 08:14:45 +00:00
|
|
|
return fmt.Errorf("%s: %w: %s", msg, frostfs.ErrAccessDenied, reason)
|
2023-06-13 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
2024-09-27 09:18:41 +00:00
|
|
|
if frosterr.IsTimeoutError(err) {
|
2024-09-27 08:14:45 +00:00
|
|
|
return fmt.Errorf("%s: %w: %s", msg, frostfs.ErrGatewayTimeout, err.Error())
|
2023-06-13 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("%s: %w", msg, err)
|
|
|
|
}
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// PoolStatistic is a mediator which implements authmate.FrostFS through pool.Pool.
|
2022-07-27 14:52:25 +00:00
|
|
|
type PoolStatistic struct {
|
|
|
|
pool *pool.Pool
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewPoolStatistic creates new PoolStatistic using provided pool.Pool.
|
|
|
|
func NewPoolStatistic(p *pool.Pool) *PoolStatistic {
|
|
|
|
return &PoolStatistic{pool: p}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Statistic implements interface method.
|
|
|
|
func (x *PoolStatistic) Statistic() pool.Statistic {
|
|
|
|
return x.pool.Statistic()
|
|
|
|
}
|