2020-08-03 11:48:33 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-28 20:48:23 +00:00
|
|
|
"crypto/ecdsa"
|
2022-05-18 07:48:30 +00:00
|
|
|
"crypto/rand"
|
2024-04-11 15:01:05 +00:00
|
|
|
"encoding/json"
|
2023-10-09 12:34:51 +00:00
|
|
|
"encoding/xml"
|
2024-07-17 14:40:23 +00:00
|
|
|
stderrors "errors"
|
2021-05-20 10:14:17 +00:00
|
|
|
"fmt"
|
2020-08-03 11:48:33 +00:00
|
|
|
"io"
|
2020-10-24 13:09:22 +00:00
|
|
|
"net/url"
|
2024-07-17 14:40:23 +00:00
|
|
|
"sort"
|
2022-08-01 16:52:09 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2022-05-20 15:02:00 +00:00
|
|
|
"time"
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
2024-07-17 14:40:23 +00:00
|
|
|
s3errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/encryption"
|
2023-07-05 14:05:45 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
2023-08-23 11:07:52 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
2023-04-24 16:40:18 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 14:38:08 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2021-10-19 15:08:07 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-08-03 11:48:33 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2022-09-12 13:46:55 +00:00
|
|
|
BucketResolver interface {
|
2024-09-03 14:50:51 +00:00
|
|
|
Resolve(ctx context.Context, zone, name string) (cid.ID, error)
|
2022-09-12 13:46:55 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 12:30:47 +00:00
|
|
|
FeatureSettings interface {
|
|
|
|
ClientCut() bool
|
2023-08-25 10:07:59 +00:00
|
|
|
BufferMaxSizeForPut() uint64
|
2023-10-02 08:52:07 +00:00
|
|
|
MD5Enabled() bool
|
2024-09-03 14:50:51 +00:00
|
|
|
FormContainerZone(ns string) string
|
2023-07-14 12:30:47 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
Layer struct {
|
2024-08-12 11:22:56 +00:00
|
|
|
frostFS FrostFS
|
|
|
|
gateOwner user.ID
|
|
|
|
log *zap.Logger
|
|
|
|
anonKey AnonymousKey
|
|
|
|
resolver BucketResolver
|
|
|
|
cache *Cache
|
|
|
|
treeService TreeService
|
|
|
|
features FeatureSettings
|
|
|
|
gateKey *keys.PrivateKey
|
|
|
|
corsCnrInfo *data.BucketInfo
|
|
|
|
lifecycleCnrInfo *data.BucketInfo
|
2020-10-19 01:04:37 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 09:16:05 +00:00
|
|
|
Config struct {
|
2024-08-12 11:22:56 +00:00
|
|
|
GateOwner user.ID
|
|
|
|
ChainAddress string
|
|
|
|
Cache *Cache
|
|
|
|
AnonKey AnonymousKey
|
|
|
|
Resolver BucketResolver
|
|
|
|
TreeService TreeService
|
|
|
|
Features FeatureSettings
|
|
|
|
GateKey *keys.PrivateKey
|
|
|
|
CORSCnrInfo *data.BucketInfo
|
|
|
|
LifecycleCnrInfo *data.BucketInfo
|
2021-11-22 09:16:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 15:08:07 +00:00
|
|
|
// AnonymousKey contains data for anonymous requests.
|
|
|
|
AnonymousKey struct {
|
|
|
|
Key *keys.PrivateKey
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// GetObjectParams stores object get request parameters.
|
2020-08-03 11:48:33 +00:00
|
|
|
GetObjectParams struct {
|
2021-08-10 10:03:09 +00:00
|
|
|
Range *RangeParams
|
2021-09-10 06:56:56 +00:00
|
|
|
ObjectInfo *data.ObjectInfo
|
2022-06-02 16:56:04 +00:00
|
|
|
BucketInfo *data.BucketInfo
|
2023-07-06 13:37:53 +00:00
|
|
|
Versioned bool
|
2022-08-11 08:48:58 +00:00
|
|
|
Encryption encryption.Params
|
2021-08-10 10:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HeadObjectParams stores object head request parameters.
|
|
|
|
HeadObjectParams struct {
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo *data.BucketInfo
|
2021-08-10 10:03:09 +00:00
|
|
|
Object string
|
|
|
|
VersionID string
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2021-06-24 11:10:00 +00:00
|
|
|
// RangeParams stores range header request parameters.
|
|
|
|
RangeParams struct {
|
|
|
|
Start uint64
|
|
|
|
End uint64
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// PutObjectParams stores object put request parameters.
|
2020-08-03 11:48:33 +00:00
|
|
|
PutObjectParams struct {
|
2023-11-13 08:01:47 +00:00
|
|
|
BktInfo *data.BucketInfo
|
|
|
|
Object string
|
2024-09-12 15:48:00 +00:00
|
|
|
Size *uint64
|
2023-11-13 08:01:47 +00:00
|
|
|
Reader io.Reader
|
|
|
|
Header map[string]string
|
|
|
|
Lock *data.ObjectLock
|
|
|
|
Encryption encryption.Params
|
|
|
|
CopiesNumbers []uint32
|
|
|
|
CompleteMD5Hash string
|
|
|
|
ContentMD5 string
|
|
|
|
ContentSHA256Hash string
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 12:49:20 +00:00
|
|
|
PutCombinedObjectParams struct {
|
|
|
|
BktInfo *data.BucketInfo
|
|
|
|
Object string
|
|
|
|
Size uint64
|
|
|
|
Header map[string]string
|
|
|
|
Lock *data.ObjectLock
|
|
|
|
Encryption encryption.Params
|
|
|
|
}
|
|
|
|
|
2022-03-31 06:24:29 +00:00
|
|
|
DeleteObjectParams struct {
|
2024-07-23 15:12:16 +00:00
|
|
|
BktInfo *data.BucketInfo
|
|
|
|
Objects []*VersionedObject
|
|
|
|
Settings *data.BucketSettings
|
|
|
|
NetworkInfo netmap.NetworkInfo
|
|
|
|
IsMultiple bool
|
2022-03-31 06:24:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 08:02:05 +00:00
|
|
|
// PutSettingsParams stores object copy request parameters.
|
|
|
|
PutSettingsParams struct {
|
|
|
|
BktInfo *data.BucketInfo
|
|
|
|
Settings *data.BucketSettings
|
2021-08-10 08:58:40 +00:00
|
|
|
}
|
|
|
|
|
2021-10-04 14:32:35 +00:00
|
|
|
// PutCORSParams stores PutCORS request parameters.
|
|
|
|
PutCORSParams struct {
|
2023-04-24 23:49:12 +00:00
|
|
|
BktInfo *data.BucketInfo
|
|
|
|
Reader io.Reader
|
|
|
|
CopiesNumbers []uint32
|
2023-10-09 12:34:51 +00:00
|
|
|
NewDecoder func(io.Reader) *xml.Decoder
|
2021-10-04 14:32:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// CopyObjectParams stores object copy request parameters.
|
2020-08-03 11:48:33 +00:00
|
|
|
CopyObjectParams struct {
|
2023-07-06 13:37:53 +00:00
|
|
|
SrcVersioned bool
|
2023-04-24 23:49:12 +00:00
|
|
|
SrcObject *data.ObjectInfo
|
|
|
|
ScrBktInfo *data.BucketInfo
|
|
|
|
DstBktInfo *data.BucketInfo
|
|
|
|
DstObject string
|
2023-10-19 14:22:26 +00:00
|
|
|
DstSize uint64
|
2023-04-24 23:49:12 +00:00
|
|
|
Header map[string]string
|
|
|
|
Range *RangeParams
|
|
|
|
Lock *data.ObjectLock
|
2023-10-19 14:22:26 +00:00
|
|
|
SrcEncryption encryption.Params
|
|
|
|
DstEncryption encryption.Params
|
2023-04-24 23:49:12 +00:00
|
|
|
CopiesNumbers []uint32
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
2024-08-13 15:21:16 +00:00
|
|
|
|
2021-06-23 20:21:15 +00:00
|
|
|
// CreateBucketParams stores bucket create request parameters.
|
|
|
|
CreateBucketParams struct {
|
2022-06-21 15:21:20 +00:00
|
|
|
Name string
|
2023-11-23 07:44:50 +00:00
|
|
|
Namespace string
|
2022-06-21 15:21:20 +00:00
|
|
|
Policy netmap.PlacementPolicy
|
|
|
|
SessionContainerCreation *session.Container
|
|
|
|
LocationConstraint string
|
|
|
|
ObjectLockEnabled bool
|
2021-07-21 11:59:46 +00:00
|
|
|
}
|
2021-06-23 20:25:00 +00:00
|
|
|
// DeleteBucketParams stores delete bucket request parameters.
|
|
|
|
DeleteBucketParams struct {
|
2022-06-22 13:22:28 +00:00
|
|
|
BktInfo *data.BucketInfo
|
|
|
|
SessionToken *session.Container
|
2024-07-19 19:20:40 +00:00
|
|
|
SkipCheck bool
|
2021-06-23 20:25:00 +00:00
|
|
|
}
|
2021-10-04 14:30:38 +00:00
|
|
|
|
2021-07-05 19:18:58 +00:00
|
|
|
// ListObjectVersionsParams stores list objects versions parameters.
|
|
|
|
ListObjectVersionsParams struct {
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo *data.BucketInfo
|
2021-07-05 19:18:58 +00:00
|
|
|
Delimiter string
|
|
|
|
KeyMarker string
|
|
|
|
MaxKeys int
|
|
|
|
Prefix string
|
|
|
|
VersionIDMarker string
|
|
|
|
Encode string
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2021-09-07 06:17:12 +00:00
|
|
|
// VersionedObject stores info about objects to delete.
|
2021-08-10 12:08:15 +00:00
|
|
|
VersionedObject struct {
|
2021-09-07 06:17:12 +00:00
|
|
|
Name string
|
|
|
|
VersionID string
|
|
|
|
DeleteMarkVersion string
|
2022-03-31 06:24:57 +00:00
|
|
|
DeleteMarkerEtag string
|
2021-09-07 06:17:12 +00:00
|
|
|
Error error
|
2021-08-10 12:08:15 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
ObjectPayload struct {
|
|
|
|
r io.Reader
|
|
|
|
params getParams
|
|
|
|
encrypted bool
|
|
|
|
decryptedLen uint64
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
)
|
|
|
|
|
2021-08-17 11:57:24 +00:00
|
|
|
const (
|
2022-05-26 13:11:14 +00:00
|
|
|
tagPrefix = "S3-Tag-"
|
2022-08-01 16:52:09 +00:00
|
|
|
|
|
|
|
AESEncryptionAlgorithm = "AES256"
|
|
|
|
AESKeySize = 32
|
2022-12-20 08:38:58 +00:00
|
|
|
AttributeEncryptionAlgorithm = api.FrostFSSystemMetadataPrefix + "Algorithm"
|
|
|
|
AttributeDecryptedSize = api.FrostFSSystemMetadataPrefix + "Decrypted-Size"
|
|
|
|
AttributeHMACSalt = api.FrostFSSystemMetadataPrefix + "HMAC-Salt"
|
|
|
|
AttributeHMACKey = api.FrostFSSystemMetadataPrefix + "HMAC-Key"
|
2022-08-17 11:18:36 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
AttributeFrostfsCopiesNumber = "frostfs-copies-number" // such format to match X-Amz-Meta-Frostfs-Copies-Number header
|
2021-08-17 11:57:24 +00:00
|
|
|
)
|
2021-08-17 08:04:42 +00:00
|
|
|
|
2023-10-19 14:22:26 +00:00
|
|
|
var EncryptionMetadata = map[string]struct{}{
|
|
|
|
AttributeEncryptionAlgorithm: {},
|
|
|
|
AttributeDecryptedSize: {},
|
|
|
|
AttributeHMACSalt: {},
|
|
|
|
AttributeHMACKey: {},
|
|
|
|
}
|
|
|
|
|
2021-08-10 12:08:15 +00:00
|
|
|
func (t *VersionedObject) String() string {
|
|
|
|
return t.Name + ":" + t.VersionID
|
|
|
|
}
|
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
func (p HeadObjectParams) Versioned() bool {
|
|
|
|
return len(p.VersionID) > 0
|
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
// NewLayer creates an instance of a Layer. It checks credentials
|
2022-04-13 16:56:58 +00:00
|
|
|
// and establishes gRPC connection with the node.
|
2024-06-25 12:57:55 +00:00
|
|
|
func NewLayer(log *zap.Logger, frostFS FrostFS, config *Config) *Layer {
|
|
|
|
return &Layer{
|
2024-08-12 11:22:56 +00:00
|
|
|
frostFS: frostFS,
|
|
|
|
log: log,
|
|
|
|
gateOwner: config.GateOwner,
|
|
|
|
anonKey: config.AnonKey,
|
|
|
|
resolver: config.Resolver,
|
|
|
|
cache: config.Cache,
|
|
|
|
treeService: config.TreeService,
|
|
|
|
features: config.Features,
|
|
|
|
gateKey: config.GateKey,
|
|
|
|
corsCnrInfo: config.CORSCnrInfo,
|
|
|
|
lifecycleCnrInfo: config.LifecycleCnrInfo,
|
2020-11-24 07:01:38 +00:00
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) EphemeralKey() *keys.PublicKey {
|
2021-10-19 15:08:07 +00:00
|
|
|
return n.anonKey.Key.PublicKey()
|
|
|
|
}
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// IsAuthenticatedRequest checks if access box exists in the current request.
|
2022-01-21 09:52:16 +00:00
|
|
|
func IsAuthenticatedRequest(ctx context.Context) bool {
|
2023-08-14 15:34:41 +00:00
|
|
|
_, err := middleware.GetBoxData(ctx)
|
|
|
|
return err == nil
|
2022-01-21 09:52:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 09:12:55 +00:00
|
|
|
// TimeNow returns client time from request or time.Now().
|
|
|
|
func TimeNow(ctx context.Context) time.Time {
|
2023-08-14 15:34:41 +00:00
|
|
|
if now, err := middleware.GetClientTime(ctx); err == nil {
|
2022-11-08 09:12:55 +00:00
|
|
|
return now
|
|
|
|
}
|
|
|
|
|
|
|
|
return time.Now()
|
|
|
|
}
|
|
|
|
|
2023-08-03 12:08:22 +00:00
|
|
|
// BearerOwner returns owner id from BearerToken (context) or from client owner.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) BearerOwner(ctx context.Context) user.ID {
|
2023-08-14 15:34:41 +00:00
|
|
|
if bd, err := middleware.GetBoxData(ctx); err == nil && bd.Gate.BearerToken != nil {
|
2022-06-01 14:00:30 +00:00
|
|
|
return bearer.ResolveIssuer(*bd.Gate.BearerToken)
|
2020-11-27 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 09:57:58 +00:00
|
|
|
var ownerID user.ID
|
|
|
|
user.IDFromKey(&ownerID, (ecdsa.PublicKey)(*n.EphemeralKey()))
|
|
|
|
|
|
|
|
return ownerID
|
2020-11-27 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
2024-03-01 14:11:07 +00:00
|
|
|
// SessionTokenForRead returns session container token.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) SessionTokenForRead(ctx context.Context) *session.Container {
|
2024-03-01 14:11:07 +00:00
|
|
|
if bd, err := middleware.GetBoxData(ctx); err == nil && bd.Gate != nil {
|
|
|
|
return bd.Gate.SessionToken()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) reqLogger(ctx context.Context) *zap.Logger {
|
2023-07-05 14:05:45 +00:00
|
|
|
reqLogger := middleware.GetReqLog(ctx)
|
2023-06-09 13:19:23 +00:00
|
|
|
if reqLogger != nil {
|
|
|
|
return reqLogger
|
|
|
|
}
|
|
|
|
return n.log
|
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) prepareAuthParameters(ctx context.Context, prm *PrmAuth, bktOwner user.ID) {
|
2024-07-15 15:35:54 +00:00
|
|
|
if prm.BearerToken != nil || prm.PrivateKey != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-08-14 15:34:41 +00:00
|
|
|
if bd, err := middleware.GetBoxData(ctx); err == nil && bd.Gate.BearerToken != nil {
|
2022-10-25 09:30:18 +00:00
|
|
|
if bd.Gate.BearerToken.Impersonate() || bktOwner.Equals(bearer.ResolveIssuer(*bd.Gate.BearerToken)) {
|
2022-06-01 17:35:20 +00:00
|
|
|
prm.BearerToken = bd.Gate.BearerToken
|
|
|
|
return
|
|
|
|
}
|
2022-03-01 19:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prm.PrivateKey = &n.anonKey.Key.PrivateKey
|
|
|
|
}
|
|
|
|
|
2021-05-20 10:14:17 +00:00
|
|
|
// GetBucketInfo returns bucket info by name.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) GetBucketInfo(ctx context.Context, name string) (*data.BucketInfo, error) {
|
2020-10-24 13:09:22 +00:00
|
|
|
name, err := url.QueryUnescape(name)
|
|
|
|
if err != nil {
|
2022-06-22 19:40:52 +00:00
|
|
|
return nil, fmt.Errorf("unescape bucket name: %w", err)
|
2020-10-24 13:09:22 +00:00
|
|
|
}
|
|
|
|
|
2023-11-16 12:10:51 +00:00
|
|
|
reqInfo := middleware.GetReqInfo(ctx)
|
2024-09-03 14:50:51 +00:00
|
|
|
zone := n.features.FormContainerZone(reqInfo.Namespace)
|
2023-11-16 12:10:51 +00:00
|
|
|
|
2024-03-01 13:09:33 +00:00
|
|
|
if bktInfo := n.cache.GetBucket(zone, name); bktInfo != nil {
|
2021-08-18 13:48:58 +00:00
|
|
|
return bktInfo, nil
|
|
|
|
}
|
|
|
|
|
2024-09-03 14:50:51 +00:00
|
|
|
containerID, err := n.ResolveBucket(ctx, zone, name)
|
2021-11-22 09:16:05 +00:00
|
|
|
if err != nil {
|
2023-06-09 13:19:23 +00:00
|
|
|
if strings.Contains(err.Error(), "not found") {
|
2023-06-30 09:03:55 +00:00
|
|
|
return nil, fmt.Errorf("%w: %s", errors.GetAPIError(errors.ErrNoSuchBucket), err.Error())
|
2023-06-09 13:19:23 +00:00
|
|
|
}
|
|
|
|
return nil, err
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-01 14:11:07 +00:00
|
|
|
prm := PrmContainer{
|
|
|
|
ContainerID: containerID,
|
|
|
|
SessionToken: n.SessionTokenForRead(ctx),
|
|
|
|
}
|
|
|
|
|
|
|
|
return n.containerInfo(ctx, prm)
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-01 14:07:08 +00:00
|
|
|
// ResolveCID returns container id by name.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) ResolveCID(ctx context.Context, name string) (cid.ID, error) {
|
2024-03-01 14:07:08 +00:00
|
|
|
name, err := url.QueryUnescape(name)
|
|
|
|
if err != nil {
|
|
|
|
return cid.ID{}, fmt.Errorf("unescape bucket name: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqInfo := middleware.GetReqInfo(ctx)
|
2024-09-03 14:50:51 +00:00
|
|
|
zone := n.features.FormContainerZone(reqInfo.Namespace)
|
2024-03-01 14:07:08 +00:00
|
|
|
|
|
|
|
if bktInfo := n.cache.GetBucket(zone, name); bktInfo != nil {
|
|
|
|
return bktInfo.CID, nil
|
|
|
|
}
|
|
|
|
|
2024-09-03 14:50:51 +00:00
|
|
|
return n.ResolveBucket(ctx, zone, name)
|
2024-03-01 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// ListBuckets returns all user containers. The name of the bucket is a container
|
2022-12-20 08:38:58 +00:00
|
|
|
// id. Timestamp is omitted since it is not saved in frostfs container.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) ListBuckets(ctx context.Context) ([]*data.BucketInfo, error) {
|
2020-08-03 11:48:33 +00:00
|
|
|
return n.containerList(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetObject from storage.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) GetObject(ctx context.Context, p *GetObjectParams) (*ObjectPayload, error) {
|
2022-02-08 16:54:04 +00:00
|
|
|
var params getParams
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2023-06-27 12:49:20 +00:00
|
|
|
params.objInfo = p.ObjectInfo
|
2022-06-02 16:56:04 +00:00
|
|
|
params.bktInfo = p.BucketInfo
|
2020-10-19 01:04:37 +00:00
|
|
|
|
2022-08-11 08:48:58 +00:00
|
|
|
var decReader *encryption.Decrypter
|
2022-08-01 16:52:09 +00:00
|
|
|
if p.Encryption.Enabled() {
|
|
|
|
var err error
|
2022-08-11 08:48:58 +00:00
|
|
|
decReader, err = getDecrypter(p)
|
2022-08-01 16:52:09 +00:00
|
|
|
if err != nil {
|
2023-07-06 13:37:53 +00:00
|
|
|
return nil, fmt.Errorf("creating decrypter: %w", err)
|
2022-08-01 16:52:09 +00:00
|
|
|
}
|
2022-08-11 08:48:58 +00:00
|
|
|
params.off = decReader.EncryptedOffset()
|
|
|
|
params.ln = decReader.EncryptedLength()
|
2022-08-01 16:52:09 +00:00
|
|
|
} else {
|
|
|
|
if p.Range != nil {
|
|
|
|
if p.Range.Start > p.Range.End {
|
|
|
|
panic("invalid range")
|
|
|
|
}
|
|
|
|
params.ln = p.Range.End - p.Range.Start + 1
|
|
|
|
params.off = p.Range.Start
|
2022-02-08 16:54:04 +00:00
|
|
|
}
|
2021-06-24 11:10:00 +00:00
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
r, err := n.initObjectPayloadReader(ctx, params)
|
2021-05-20 10:14:17 +00:00
|
|
|
if err != nil {
|
2023-07-06 13:37:53 +00:00
|
|
|
if client.IsErrObjectNotFound(err) {
|
|
|
|
if p.Versioned {
|
|
|
|
err = fmt.Errorf("%w: %s", errors.GetAPIError(errors.ErrNoSuchVersion), err.Error())
|
|
|
|
} else {
|
|
|
|
err = fmt.Errorf("%w: %s", errors.GetAPIError(errors.ErrNoSuchKey), err.Error())
|
|
|
|
}
|
|
|
|
}
|
2022-03-02 16:09:02 +00:00
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
return nil, fmt.Errorf("init object payload reader: %w", err)
|
2022-03-02 16:09:02 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
var decryptedLen uint64
|
2022-08-01 16:52:09 +00:00
|
|
|
if decReader != nil {
|
2023-07-06 13:37:53 +00:00
|
|
|
if err = decReader.SetReader(r); err != nil {
|
|
|
|
return nil, fmt.Errorf("set reader to decrypter: %w", err)
|
2022-08-01 16:52:09 +00:00
|
|
|
}
|
2022-08-11 08:48:58 +00:00
|
|
|
r = io.LimitReader(decReader, int64(decReader.DecryptedLength()))
|
2023-07-06 13:37:53 +00:00
|
|
|
decryptedLen = decReader.DecryptedLength()
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ObjectPayload{
|
|
|
|
r: r,
|
|
|
|
params: params,
|
|
|
|
encrypted: decReader != nil,
|
|
|
|
decryptedLen: decryptedLen,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read implements io.Reader. If you want to use ObjectPayload as io.Reader
|
|
|
|
// you must not use ObjectPayload.StreamTo method and vice versa.
|
|
|
|
func (o *ObjectPayload) Read(p []byte) (int, error) {
|
|
|
|
return o.r.Read(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
// StreamTo reads all payload to provided writer.
|
|
|
|
// If you want to use this method you must not use ObjectPayload.Read and vice versa.
|
|
|
|
func (o *ObjectPayload) StreamTo(w io.Writer) error {
|
|
|
|
bufSize := uint64(32 * 1024) // configure?
|
|
|
|
if o.params.ln != 0 && o.params.ln < bufSize {
|
|
|
|
bufSize = o.params.ln
|
2022-08-01 16:52:09 +00:00
|
|
|
}
|
2022-03-02 16:09:02 +00:00
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
// alloc buffer for copying
|
|
|
|
buf := make([]byte, bufSize) // sync-pool it?
|
|
|
|
|
2022-03-02 16:09:02 +00:00
|
|
|
// copy full payload
|
2023-07-06 13:37:53 +00:00
|
|
|
written, err := io.CopyBuffer(w, o.r, buf)
|
2022-03-02 16:09:02 +00:00
|
|
|
if err != nil {
|
2023-07-06 13:37:53 +00:00
|
|
|
if o.encrypted {
|
|
|
|
return fmt.Errorf("copy object payload written: '%d', decLength: '%d', params.ln: '%d' : %w", written, o.decryptedLen, o.params.ln, err)
|
2022-09-07 12:41:45 +00:00
|
|
|
}
|
|
|
|
return fmt.Errorf("copy object payload written: '%d': %w", written, err)
|
2021-05-20 10:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 08:48:58 +00:00
|
|
|
func getDecrypter(p *GetObjectParams) (*encryption.Decrypter, error) {
|
|
|
|
var encRange *encryption.Range
|
|
|
|
if p.Range != nil {
|
|
|
|
encRange = &encryption.Range{Start: p.Range.Start, End: p.Range.End}
|
|
|
|
}
|
|
|
|
|
|
|
|
header := p.ObjectInfo.Headers[UploadCompletedParts]
|
|
|
|
if len(header) == 0 {
|
|
|
|
return encryption.NewDecrypter(p.Encryption, uint64(p.ObjectInfo.Size), encRange)
|
|
|
|
}
|
|
|
|
|
|
|
|
decryptedObjectSize, err := strconv.ParseUint(p.ObjectInfo.Headers[AttributeDecryptedSize], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("parse decrypted size: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
splits := strings.Split(header, ",")
|
|
|
|
sizes := make([]uint64, len(splits))
|
|
|
|
for i, splitInfo := range splits {
|
|
|
|
part, err := ParseCompletedPartHeader(splitInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("parse completed part: %w", err)
|
|
|
|
}
|
|
|
|
sizes[i] = uint64(part.Size)
|
|
|
|
}
|
|
|
|
|
|
|
|
return encryption.NewMultipartDecrypter(p.Encryption, decryptedObjectSize, sizes, encRange)
|
|
|
|
}
|
|
|
|
|
2020-08-03 11:48:33 +00:00
|
|
|
// GetObjectInfo returns meta information about the object.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) GetObjectInfo(ctx context.Context, p *HeadObjectParams) (*data.ObjectInfo, error) {
|
2022-08-05 00:54:21 +00:00
|
|
|
extendedObjectInfo, err := n.GetExtendedObjectInfo(ctx, p)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return extendedObjectInfo.ObjectInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetExtendedObjectInfo returns meta information and corresponding info from the tree service about the object.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) GetExtendedObjectInfo(ctx context.Context, p *HeadObjectParams) (*data.ExtendedObjectInfo, error) {
|
2022-12-09 13:30:51 +00:00
|
|
|
var objInfo *data.ExtendedObjectInfo
|
|
|
|
var err error
|
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
if p.Versioned() {
|
2022-12-09 13:30:51 +00:00
|
|
|
objInfo, err = n.headVersion(ctx, p.BktInfo, p)
|
2023-07-06 13:37:53 +00:00
|
|
|
} else {
|
|
|
|
objInfo, err = n.headLastVersionIfNotDeleted(ctx, p.BktInfo, p.Object)
|
2022-12-09 13:30:51 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-08-10 12:08:15 +00:00
|
|
|
}
|
|
|
|
|
2023-08-23 11:07:52 +00:00
|
|
|
n.reqLogger(ctx).Debug(logs.GetObject,
|
2022-12-09 13:30:51 +00:00
|
|
|
zap.Stringer("cid", p.BktInfo.CID),
|
|
|
|
zap.Stringer("oid", objInfo.ObjectInfo.ID))
|
|
|
|
|
|
|
|
return objInfo, nil
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CopyObject from one bucket into another bucket.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) CopyObject(ctx context.Context, p *CopyObjectParams) (*data.ExtendedObjectInfo, error) {
|
2023-07-06 13:37:53 +00:00
|
|
|
objPayload, err := n.GetObject(ctx, &GetObjectParams{
|
|
|
|
ObjectInfo: p.SrcObject,
|
|
|
|
Versioned: p.SrcVersioned,
|
|
|
|
Range: p.Range,
|
|
|
|
BucketInfo: p.ScrBktInfo,
|
2023-10-19 14:22:26 +00:00
|
|
|
Encryption: p.SrcEncryption,
|
2023-07-06 13:37:53 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("get object to copy: %w", err)
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
|
|
|
|
return n.PutObject(ctx, &PutObjectParams{
|
2023-04-24 23:49:12 +00:00
|
|
|
BktInfo: p.DstBktInfo,
|
|
|
|
Object: p.DstObject,
|
2024-09-12 15:48:00 +00:00
|
|
|
Size: &p.DstSize,
|
2023-07-06 13:37:53 +00:00
|
|
|
Reader: objPayload,
|
2023-04-24 23:49:12 +00:00
|
|
|
Header: p.Header,
|
2023-10-19 14:22:26 +00:00
|
|
|
Encryption: p.DstEncryption,
|
2023-04-24 23:49:12 +00:00
|
|
|
CopiesNumbers: p.CopiesNumbers,
|
2020-08-03 11:48:33 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-27 09:33:36 +00:00
|
|
|
func getRandomOID() (oid.ID, error) {
|
2022-05-18 07:48:30 +00:00
|
|
|
b := [32]byte{}
|
|
|
|
if _, err := rand.Read(b[:]); err != nil {
|
2022-06-27 09:33:36 +00:00
|
|
|
return oid.ID{}, err
|
2022-05-18 07:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var objID oid.ID
|
|
|
|
objID.SetSHA256(b)
|
2022-06-27 09:33:36 +00:00
|
|
|
return objID, nil
|
2022-05-18 07:48:30 +00:00
|
|
|
}
|
|
|
|
|
2024-07-23 15:12:16 +00:00
|
|
|
func (n *Layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings *data.BucketSettings, obj *VersionedObject,
|
|
|
|
networkInfo netmap.NetworkInfo) *VersionedObject {
|
2022-07-19 14:58:18 +00:00
|
|
|
if len(obj.VersionID) != 0 || settings.Unversioned() {
|
2024-07-17 14:40:23 +00:00
|
|
|
var nodeVersions []*data.NodeVersion
|
|
|
|
if nodeVersions, obj.Error = n.getNodeVersionsToDelete(ctx, bkt, obj); obj.Error != nil {
|
2023-03-30 15:34:58 +00:00
|
|
|
return n.handleNotFoundError(bkt, obj)
|
2022-06-15 12:17:29 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
for _, nodeVersion := range nodeVersions {
|
|
|
|
if obj.DeleteMarkVersion, obj.Error = n.removeOldVersion(ctx, bkt, nodeVersion, obj); obj.Error != nil {
|
|
|
|
if !client.IsErrObjectAlreadyRemoved(obj.Error) && !client.IsErrObjectNotFound(obj.Error) {
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
n.reqLogger(ctx).Debug(logs.CouldntDeleteObjectFromStorageContinueDeleting,
|
|
|
|
zap.Stringer("cid", bkt.CID), zap.String("oid", obj.VersionID), zap.Error(obj.Error))
|
|
|
|
}
|
|
|
|
|
|
|
|
if obj.Error = n.treeService.RemoveVersion(ctx, bkt, nodeVersion.ID); obj.Error != nil {
|
|
|
|
return obj
|
|
|
|
}
|
2022-05-18 07:48:30 +00:00
|
|
|
}
|
2022-05-19 09:17:56 +00:00
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
n.cache.DeleteObjectName(bkt.CID, bkt.Name, obj.Name)
|
2022-06-24 12:39:30 +00:00
|
|
|
return obj
|
|
|
|
}
|
2022-05-19 09:17:56 +00:00
|
|
|
|
2023-04-14 12:36:22 +00:00
|
|
|
lastVersion, err := n.getLastNodeVersion(ctx, bkt, obj)
|
|
|
|
if err != nil {
|
|
|
|
obj.Error = err
|
|
|
|
return n.handleNotFoundError(bkt, obj)
|
|
|
|
}
|
2022-05-31 08:12:53 +00:00
|
|
|
|
2022-07-19 14:58:18 +00:00
|
|
|
if settings.VersioningSuspended() {
|
2022-08-08 22:35:26 +00:00
|
|
|
obj.VersionID = data.UnversionedObjectVersionID
|
2022-01-19 09:02:08 +00:00
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
var nodeVersions []*data.NodeVersion
|
|
|
|
if nodeVersions, obj.Error = n.getNodeVersionsToDelete(ctx, bkt, obj); obj.Error != nil {
|
2023-04-14 12:36:22 +00:00
|
|
|
if !isNotFoundError(obj.Error) {
|
|
|
|
return obj
|
|
|
|
}
|
2022-06-15 12:17:29 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
for _, nodeVersion := range nodeVersions {
|
|
|
|
if nodeVersion.ID == lastVersion.ID && nodeVersion.IsDeleteMarker {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !nodeVersion.IsDeleteMarker {
|
|
|
|
if obj.DeleteMarkVersion, obj.Error = n.removeOldVersion(ctx, bkt, nodeVersion, obj); obj.Error != nil {
|
|
|
|
if !client.IsErrObjectAlreadyRemoved(obj.Error) && !client.IsErrObjectNotFound(obj.Error) {
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
n.reqLogger(ctx).Debug(logs.CouldntDeleteObjectFromStorageContinueDeleting,
|
|
|
|
zap.Stringer("cid", bkt.CID), zap.String("oid", obj.VersionID), zap.Error(obj.Error))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if obj.Error = n.treeService.RemoveVersion(ctx, bkt, nodeVersion.ID); obj.Error != nil {
|
|
|
|
return obj
|
2023-04-14 12:36:22 +00:00
|
|
|
}
|
2021-08-17 11:23:49 +00:00
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2024-01-17 14:26:02 +00:00
|
|
|
if lastVersion.IsDeleteMarker {
|
2023-04-14 12:36:22 +00:00
|
|
|
obj.DeleteMarkVersion = lastVersion.OID.EncodeToString()
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
randOID, err := getRandomOID()
|
|
|
|
if err != nil {
|
|
|
|
obj.Error = fmt.Errorf("couldn't get random oid: %w", err)
|
|
|
|
return obj
|
|
|
|
}
|
2022-07-05 08:04:21 +00:00
|
|
|
|
|
|
|
obj.DeleteMarkVersion = randOID.EncodeToString()
|
2024-01-17 14:26:02 +00:00
|
|
|
now := TimeNow(ctx)
|
2023-04-14 12:36:22 +00:00
|
|
|
newVersion := &data.NodeVersion{
|
2022-06-24 12:39:30 +00:00
|
|
|
BaseNodeVersion: data.BaseNodeVersion{
|
2024-01-17 14:26:02 +00:00
|
|
|
OID: randOID,
|
|
|
|
FilePath: obj.Name,
|
|
|
|
Created: &now,
|
|
|
|
Owner: &n.gateOwner,
|
|
|
|
IsDeleteMarker: true,
|
2024-07-23 15:12:16 +00:00
|
|
|
CreationEpoch: networkInfo.CurrentEpoch(),
|
2022-06-24 12:39:30 +00:00
|
|
|
},
|
2022-07-19 14:58:18 +00:00
|
|
|
IsUnversioned: settings.VersioningSuspended(),
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
if _, obj.Error = n.treeService.AddVersion(ctx, bkt, newVersion); obj.Error != nil {
|
2022-06-24 12:39:30 +00:00
|
|
|
return obj
|
|
|
|
}
|
2022-07-05 06:25:23 +00:00
|
|
|
|
2022-10-03 14:33:49 +00:00
|
|
|
n.cache.DeleteObjectName(bkt.CID, bkt.Name, obj.Name)
|
2022-03-09 10:23:33 +00:00
|
|
|
|
2021-09-07 06:17:12 +00:00
|
|
|
return obj
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) handleNotFoundError(bkt *data.BucketInfo, obj *VersionedObject) *VersionedObject {
|
2023-04-14 12:36:22 +00:00
|
|
|
if isNotFoundError(obj.Error) {
|
2022-07-25 13:00:35 +00:00
|
|
|
obj.Error = nil
|
2023-03-30 15:34:58 +00:00
|
|
|
n.cache.CleanListCacheEntriesContainingObject(obj.Name, bkt.CID)
|
|
|
|
n.cache.DeleteObjectName(bkt.CID, bkt.Name, obj.Name)
|
2022-07-25 13:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
func isNotFoundError(err error) bool {
|
|
|
|
return errors.IsS3Error(err, errors.ErrNoSuchKey) ||
|
|
|
|
errors.IsS3Error(err, errors.ErrNoSuchVersion)
|
|
|
|
}
|
2023-04-24 16:40:18 +00:00
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
func (n *Layer) getNodeVersionsToDelete(ctx context.Context, bkt *data.BucketInfo, obj *VersionedObject) ([]*data.NodeVersion, error) {
|
|
|
|
var versionsToDelete []*data.NodeVersion
|
|
|
|
versions, err := n.treeService.GetVersions(ctx, bkt, obj.Name)
|
|
|
|
if err != nil {
|
|
|
|
if stderrors.Is(err, ErrNodeNotFound) {
|
|
|
|
return nil, fmt.Errorf("%w: %s", s3errors.GetAPIError(s3errors.ErrNoSuchKey), err.Error())
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-05-26 15:29:11 +00:00
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
if len(versions) == 0 {
|
|
|
|
return nil, fmt.Errorf("%w: there isn't tree node with requested version id", s3errors.GetAPIError(s3errors.ErrNoSuchVersion))
|
2023-05-26 15:29:11 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[i].Timestamp < versions[j].Timestamp
|
|
|
|
})
|
2023-04-24 16:40:18 +00:00
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
var matchFn func(nv *data.NodeVersion) bool
|
2023-04-14 12:36:22 +00:00
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
switch {
|
|
|
|
case obj.VersionID == data.UnversionedObjectVersionID:
|
|
|
|
matchFn = func(nv *data.NodeVersion) bool {
|
|
|
|
return nv.IsUnversioned
|
|
|
|
}
|
|
|
|
case len(obj.VersionID) == 0:
|
|
|
|
latest := versions[len(versions)-1]
|
|
|
|
if latest.IsUnversioned {
|
|
|
|
matchFn = func(nv *data.NodeVersion) bool {
|
|
|
|
return nv.IsUnversioned
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
matchFn = func(nv *data.NodeVersion) bool {
|
|
|
|
return nv.ID == latest.ID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
matchFn = func(nv *data.NodeVersion) bool {
|
|
|
|
return nv.OID.EncodeToString() == obj.VersionID
|
|
|
|
}
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 14:40:23 +00:00
|
|
|
var oids []string
|
|
|
|
for _, v := range versions {
|
|
|
|
if matchFn(v) {
|
|
|
|
versionsToDelete = append(versionsToDelete, v)
|
|
|
|
if !v.IsDeleteMarker {
|
|
|
|
oids = append(oids, v.OID.EncodeToString())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(versionsToDelete) == 0 {
|
|
|
|
return nil, fmt.Errorf("%w: there isn't tree node with requested version id", s3errors.GetAPIError(s3errors.ErrNoSuchVersion))
|
|
|
|
}
|
|
|
|
|
|
|
|
n.reqLogger(ctx).Debug(logs.GetTreeNodeToDelete, zap.Stringer("cid", bkt.CID), zap.Strings("oids", oids))
|
|
|
|
|
|
|
|
return versionsToDelete, nil
|
2022-06-24 12:39:30 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) getLastNodeVersion(ctx context.Context, bkt *data.BucketInfo, obj *VersionedObject) (*data.NodeVersion, error) {
|
2024-04-10 06:41:07 +00:00
|
|
|
objVersion := &data.ObjectVersion{
|
2023-04-14 12:36:22 +00:00
|
|
|
BktInfo: bkt,
|
|
|
|
ObjectName: obj.Name,
|
|
|
|
VersionID: "",
|
|
|
|
NoErrorOnDeleteMarker: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
return n.getNodeVersion(ctx, objVersion)
|
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) removeOldVersion(ctx context.Context, bkt *data.BucketInfo, nodeVersion *data.NodeVersion, obj *VersionedObject) (string, error) {
|
2024-01-17 14:26:02 +00:00
|
|
|
if nodeVersion.IsDeleteMarker {
|
2022-06-15 12:17:29 +00:00
|
|
|
return obj.VersionID, nil
|
2022-05-19 09:17:56 +00:00
|
|
|
}
|
|
|
|
|
2024-04-11 15:01:05 +00:00
|
|
|
if nodeVersion.IsCombined {
|
|
|
|
return "", n.removeCombinedObject(ctx, bkt, nodeVersion)
|
|
|
|
}
|
|
|
|
|
2022-06-15 12:17:29 +00:00
|
|
|
return "", n.objectDelete(ctx, bkt, nodeVersion.OID)
|
2022-05-18 06:51:12 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) removeCombinedObject(ctx context.Context, bkt *data.BucketInfo, nodeVersion *data.NodeVersion) error {
|
2024-04-11 15:01:05 +00:00
|
|
|
combinedObj, err := n.objectGet(ctx, bkt, nodeVersion.OID)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("get combined object '%s': %w", nodeVersion.OID.EncodeToString(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var parts []*data.PartInfo
|
2024-07-15 12:47:19 +00:00
|
|
|
if err = json.NewDecoder(combinedObj.Payload).Decode(&parts); err != nil {
|
2024-04-11 15:01:05 +00:00
|
|
|
return fmt.Errorf("unmarshal combined object parts: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, part := range parts {
|
|
|
|
if err = n.objectDelete(ctx, bkt, part.OID); err == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !client.IsErrObjectAlreadyRemoved(err) && !client.IsErrObjectNotFound(err) {
|
|
|
|
return fmt.Errorf("couldn't delete part '%s': %w", part.OID.EncodeToString(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
n.reqLogger(ctx).Warn(logs.CouldntDeletePart, zap.String("cid", bkt.CID.EncodeToString()),
|
|
|
|
zap.String("oid", part.OID.EncodeToString()), zap.Int("part number", part.Number), zap.Error(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return n.objectDelete(ctx, bkt, nodeVersion.OID)
|
|
|
|
}
|
|
|
|
|
2020-08-03 11:48:33 +00:00
|
|
|
// DeleteObjects from the storage.
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) DeleteObjects(ctx context.Context, p *DeleteObjectParams) []*VersionedObject {
|
2022-03-31 06:24:29 +00:00
|
|
|
for i, obj := range p.Objects {
|
2024-07-23 15:12:16 +00:00
|
|
|
p.Objects[i] = n.deleteObject(ctx, p.BktInfo, p.Settings, obj, p.NetworkInfo)
|
2024-02-16 12:43:47 +00:00
|
|
|
if p.IsMultiple && p.Objects[i].Error != nil {
|
|
|
|
n.reqLogger(ctx).Error(logs.CouldntDeleteObject, zap.String("object", obj.String()), zap.Error(p.Objects[i].Error))
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
return p.Objects
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
2021-06-23 20:21:15 +00:00
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*data.BucketInfo, error) {
|
2022-02-15 09:06:00 +00:00
|
|
|
bktInfo, err := n.GetBucketInfo(ctx, p.Name)
|
2021-07-07 14:56:29 +00:00
|
|
|
if err != nil {
|
2021-08-09 08:53:58 +00:00
|
|
|
if errors.IsS3Error(err, errors.ErrNoSuchBucket) {
|
2021-07-07 14:56:29 +00:00
|
|
|
return n.createContainer(ctx, p)
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-06-21 15:21:20 +00:00
|
|
|
if p.SessionContainerCreation != nil && session.IssuedBy(*p.SessionContainerCreation, bktInfo.Owner) {
|
2022-02-15 09:06:00 +00:00
|
|
|
return nil, errors.GetAPIError(errors.ErrBucketAlreadyOwnedByYou)
|
|
|
|
}
|
|
|
|
|
2021-08-09 08:53:58 +00:00
|
|
|
return nil, errors.GetAPIError(errors.ErrBucketAlreadyExists)
|
2021-06-23 20:21:15 +00:00
|
|
|
}
|
2021-06-23 20:25:00 +00:00
|
|
|
|
2024-09-03 14:50:51 +00:00
|
|
|
func (n *Layer) ResolveBucket(ctx context.Context, zone, name string) (cid.ID, error) {
|
2022-04-25 09:57:58 +00:00
|
|
|
var cnrID cid.ID
|
|
|
|
if err := cnrID.DecodeString(name); err != nil {
|
2024-09-03 14:50:51 +00:00
|
|
|
if cnrID, err = n.resolver.Resolve(ctx, zone, name); err != nil {
|
2022-12-09 13:30:51 +00:00
|
|
|
return cid.ID{}, err
|
|
|
|
}
|
|
|
|
|
2023-08-23 11:07:52 +00:00
|
|
|
n.reqLogger(ctx).Info(logs.ResolveBucket, zap.Stringer("cid", cnrID))
|
2021-11-22 09:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 09:08:26 +00:00
|
|
|
return cnrID, nil
|
2021-11-22 09:16:05 +00:00
|
|
|
}
|
|
|
|
|
2024-06-25 12:57:55 +00:00
|
|
|
func (n *Layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error {
|
2024-07-19 19:20:40 +00:00
|
|
|
if !p.SkipCheck {
|
|
|
|
res, _, err := n.getAllObjectsVersions(ctx, commonVersionsListingParams{
|
|
|
|
BktInfo: p.BktInfo,
|
|
|
|
MaxKeys: 1,
|
|
|
|
})
|
2023-10-09 06:57:33 +00:00
|
|
|
|
2024-07-19 19:20:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(res) != 0 {
|
|
|
|
return errors.GetAPIError(errors.ErrBucketNotEmpty)
|
|
|
|
}
|
2021-08-10 12:08:15 +00:00
|
|
|
}
|
|
|
|
|
2023-11-23 07:44:50 +00:00
|
|
|
n.cache.DeleteBucket(p.BktInfo)
|
2024-07-15 15:35:54 +00:00
|
|
|
|
|
|
|
corsObj, err := n.treeService.GetBucketCORS(ctx, p.BktInfo)
|
|
|
|
if err != nil {
|
|
|
|
n.reqLogger(ctx).Error(logs.GetBucketCors, zap.Error(err))
|
|
|
|
}
|
|
|
|
|
2024-08-12 11:22:56 +00:00
|
|
|
lifecycleObj, treeErr := n.treeService.GetBucketLifecycleConfiguration(ctx, p.BktInfo)
|
|
|
|
if treeErr != nil {
|
|
|
|
n.reqLogger(ctx).Error(logs.GetBucketLifecycle, zap.Error(treeErr))
|
|
|
|
}
|
|
|
|
|
2024-07-15 15:35:54 +00:00
|
|
|
err = n.frostFS.DeleteContainer(ctx, p.BktInfo.CID, p.SessionToken)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("delete container: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !corsObj.Container().Equals(p.BktInfo.CID) && !corsObj.Container().Equals(cid.ID{}) {
|
|
|
|
n.deleteCORSObject(ctx, p.BktInfo, corsObj)
|
|
|
|
}
|
|
|
|
|
2024-08-12 11:22:56 +00:00
|
|
|
if treeErr == nil && !lifecycleObj.Container().Equals(p.BktInfo.CID) {
|
|
|
|
n.deleteLifecycleObject(ctx, p.BktInfo, lifecycleObj)
|
|
|
|
}
|
|
|
|
|
2024-07-15 15:35:54 +00:00
|
|
|
return nil
|
2021-08-09 14:29:44 +00:00
|
|
|
}
|
2024-07-23 15:12:16 +00:00
|
|
|
|
2024-09-24 11:46:02 +00:00
|
|
|
func (n *Layer) DeleteContainer(ctx context.Context, p *DeleteBucketParams) error {
|
|
|
|
n.cache.DeleteBucket(p.BktInfo)
|
|
|
|
if err := n.frostFS.DeleteContainer(ctx, p.BktInfo.CID, p.SessionToken); err != nil {
|
|
|
|
return fmt.Errorf("delete container: %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-07-23 15:12:16 +00:00
|
|
|
func (n *Layer) GetNetworkInfo(ctx context.Context) (netmap.NetworkInfo, error) {
|
2024-09-05 12:36:40 +00:00
|
|
|
cachedInfo := n.cache.GetNetworkInfo()
|
|
|
|
if cachedInfo != nil {
|
|
|
|
return *cachedInfo, nil
|
|
|
|
}
|
|
|
|
|
2024-07-23 15:12:16 +00:00
|
|
|
networkInfo, err := n.frostFS.NetworkInfo(ctx)
|
|
|
|
if err != nil {
|
2024-09-05 12:36:40 +00:00
|
|
|
return netmap.NetworkInfo{}, fmt.Errorf("get network info: %w", err)
|
2024-07-23 15:12:16 +00:00
|
|
|
}
|
|
|
|
|
2024-09-05 12:36:40 +00:00
|
|
|
n.cache.PutNetworkInfo(networkInfo)
|
|
|
|
|
2024-07-23 15:12:16 +00:00
|
|
|
return networkInfo, nil
|
|
|
|
}
|