2020-08-03 11:48:33 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
2021-08-10 12:08:15 +00:00
|
|
|
"bytes"
|
2020-08-03 11:48:33 +00:00
|
|
|
"context"
|
2021-05-28 20:48:23 +00:00
|
|
|
"crypto/ecdsa"
|
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"
|
2021-06-25 12:54:25 +00:00
|
|
|
"sort"
|
2021-08-09 14:29:44 +00:00
|
|
|
"strconv"
|
2021-08-10 12:08:15 +00:00
|
|
|
"strings"
|
2020-08-03 15:08:55 +00:00
|
|
|
"time"
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2021-07-21 11:59:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
2021-05-26 16:48:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2021-06-04 13:01:42 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
2021-06-23 20:21:15 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
2020-10-19 01:04:37 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-11-27 12:36:15 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
2021-05-18 11:10:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api"
|
2021-08-10 11:19:26 +00:00
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/cache"
|
2021-08-09 08:53:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/errors"
|
2021-06-21 10:54:57 +00:00
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
|
2021-05-28 08:46:13 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
|
2020-08-03 11:48:33 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
layer struct {
|
2021-08-10 12:23:55 +00:00
|
|
|
pool pool.Pool
|
|
|
|
log *zap.Logger
|
|
|
|
listObjCache ObjectsListCache
|
2021-08-10 11:19:26 +00:00
|
|
|
objCache cache.ObjectsCache
|
2020-10-19 01:04:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 09:58:09 +00:00
|
|
|
// CacheConfig contains params for caches.
|
|
|
|
CacheConfig struct {
|
|
|
|
Lifetime time.Duration
|
|
|
|
Size int
|
|
|
|
ListObjectsLifetime time.Duration
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// Params stores basic API parameters.
|
2020-10-19 01:04:37 +00:00
|
|
|
Params struct {
|
2021-05-28 20:48:23 +00:00
|
|
|
Pool pool.Pool
|
|
|
|
Logger *zap.Logger
|
|
|
|
Timeout time.Duration
|
|
|
|
Key *ecdsa.PrivateKey
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
ObjectInfo *ObjectInfo
|
|
|
|
//Bucket string
|
|
|
|
//Object string
|
|
|
|
Offset int64
|
|
|
|
Length int64
|
|
|
|
Writer io.Writer
|
|
|
|
VersionID string
|
|
|
|
}
|
|
|
|
|
|
|
|
// HeadObjectParams stores object head request parameters.
|
|
|
|
HeadObjectParams struct {
|
|
|
|
Bucket string
|
|
|
|
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 {
|
|
|
|
Bucket string
|
|
|
|
Object string
|
|
|
|
Size int64
|
|
|
|
Reader io.Reader
|
|
|
|
Header map[string]string
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:29:44 +00:00
|
|
|
// PutVersioningParams stores object copy request parameters.
|
|
|
|
PutVersioningParams struct {
|
2021-08-10 08:58:40 +00:00
|
|
|
Bucket string
|
|
|
|
Settings *BucketSettings
|
|
|
|
}
|
|
|
|
|
|
|
|
// BucketSettings stores settings such as versioning.
|
|
|
|
BucketSettings struct {
|
2021-08-09 14:29:44 +00:00
|
|
|
VersioningEnabled bool
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// CopyObjectParams stores object copy request parameters.
|
2020-08-03 11:48:33 +00:00
|
|
|
CopyObjectParams struct {
|
2021-08-10 10:03:09 +00:00
|
|
|
SrcObject *ObjectInfo
|
2020-08-03 11:48:33 +00:00
|
|
|
DstBucket string
|
|
|
|
DstObject string
|
2021-07-01 07:45:55 +00:00
|
|
|
SrcSize int64
|
2020-08-19 23:31:04 +00:00
|
|
|
Header map[string]string
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
2021-06-23 20:21:15 +00:00
|
|
|
// CreateBucketParams stores bucket create request parameters.
|
|
|
|
CreateBucketParams struct {
|
2021-07-26 10:30:51 +00:00
|
|
|
Name string
|
|
|
|
ACL uint32
|
|
|
|
Policy *netmap.PlacementPolicy
|
2021-07-21 11:59:46 +00:00
|
|
|
EACL *eacl.Table
|
2021-07-26 10:30:51 +00:00
|
|
|
BoxData *accessbox.Box
|
2021-06-23 20:21:15 +00:00
|
|
|
}
|
2021-07-21 11:59:46 +00:00
|
|
|
// PutBucketACLParams stores put bucket acl request parameters.
|
|
|
|
PutBucketACLParams struct {
|
|
|
|
Name string
|
|
|
|
EACL *eacl.Table
|
|
|
|
}
|
2021-06-23 20:25:00 +00:00
|
|
|
// DeleteBucketParams stores delete bucket request parameters.
|
|
|
|
DeleteBucketParams struct {
|
|
|
|
Name string
|
|
|
|
}
|
2021-07-05 19:18:58 +00:00
|
|
|
// ListObjectVersionsParams stores list objects versions parameters.
|
|
|
|
ListObjectVersionsParams struct {
|
|
|
|
Bucket string
|
|
|
|
Delimiter string
|
|
|
|
KeyMarker string
|
|
|
|
MaxKeys int
|
|
|
|
Prefix string
|
|
|
|
VersionIDMarker string
|
|
|
|
Encode string
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2021-08-10 12:08:15 +00:00
|
|
|
// VersionedObject stores object name and version.
|
|
|
|
VersionedObject struct {
|
|
|
|
Name string
|
|
|
|
VersionID string
|
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
objectVersions struct {
|
|
|
|
objects []*ObjectInfo
|
|
|
|
addList []string
|
|
|
|
delList []string
|
|
|
|
isSorted bool
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// NeoFS provides basic NeoFS interface.
|
2020-08-03 15:08:55 +00:00
|
|
|
NeoFS interface {
|
2020-10-19 01:04:37 +00:00
|
|
|
Get(ctx context.Context, address *object.Address) (*object.Object, error)
|
2020-08-03 15:08:55 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// Client provides S3 API client interface.
|
2020-08-03 11:48:33 +00:00
|
|
|
Client interface {
|
2020-08-03 15:08:55 +00:00
|
|
|
NeoFS
|
|
|
|
|
2021-08-09 14:29:44 +00:00
|
|
|
PutBucketVersioning(ctx context.Context, p *PutVersioningParams) (*ObjectInfo, error)
|
2021-08-10 08:58:40 +00:00
|
|
|
GetBucketVersioning(ctx context.Context, name string) (*BucketSettings, error)
|
2021-08-09 14:29:44 +00:00
|
|
|
|
2020-10-23 00:12:37 +00:00
|
|
|
ListBuckets(ctx context.Context) ([]*BucketInfo, error)
|
2020-08-03 11:48:33 +00:00
|
|
|
GetBucketInfo(ctx context.Context, name string) (*BucketInfo, error)
|
2021-07-21 11:59:46 +00:00
|
|
|
GetBucketACL(ctx context.Context, name string) (*BucketACL, error)
|
|
|
|
PutBucketACL(ctx context.Context, p *PutBucketACLParams) error
|
2021-06-23 20:21:15 +00:00
|
|
|
CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error)
|
2021-06-23 20:25:00 +00:00
|
|
|
DeleteBucket(ctx context.Context, p *DeleteBucketParams) error
|
2020-08-03 11:48:33 +00:00
|
|
|
|
|
|
|
GetObject(ctx context.Context, p *GetObjectParams) error
|
2021-08-10 10:03:09 +00:00
|
|
|
GetObjectInfo(ctx context.Context, p *HeadObjectParams) (*ObjectInfo, error)
|
2020-08-03 11:48:33 +00:00
|
|
|
|
|
|
|
PutObject(ctx context.Context, p *PutObjectParams) (*ObjectInfo, error)
|
|
|
|
|
|
|
|
CopyObject(ctx context.Context, p *CopyObjectParams) (*ObjectInfo, error)
|
|
|
|
|
2021-07-18 13:40:19 +00:00
|
|
|
ListObjectsV1(ctx context.Context, p *ListObjectsParamsV1) (*ListObjectsInfoV1, error)
|
|
|
|
ListObjectsV2(ctx context.Context, p *ListObjectsParamsV2) (*ListObjectsInfoV2, error)
|
2021-07-05 19:18:58 +00:00
|
|
|
ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error)
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2021-08-10 12:08:15 +00:00
|
|
|
DeleteObjects(ctx context.Context, bucket string, objects []*VersionedObject) []error
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
func (v *objectVersions) appendVersion(oi *ObjectInfo) {
|
|
|
|
addVers := append(splitVersions(oi.Headers[versionsAddAttr]), oi.Version())
|
|
|
|
delVers := splitVersions(oi.Headers[versionsDelAttr])
|
|
|
|
v.objects = append(v.objects, oi)
|
|
|
|
for _, add := range addVers {
|
|
|
|
if !contains(v.addList, add) {
|
|
|
|
v.addList = append(v.addList, add)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, del := range delVers {
|
|
|
|
if !contains(v.delList, del) {
|
|
|
|
v.delList = append(v.delList, del)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v.isSorted = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *objectVersions) sort() {
|
|
|
|
if !v.isSorted {
|
|
|
|
sortVersions(v.objects)
|
|
|
|
v.isSorted = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *objectVersions) getLast() *ObjectInfo {
|
|
|
|
if len(v.objects) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
v.sort()
|
|
|
|
existedVersions := getExistedVersions(v)
|
|
|
|
for i := len(v.objects) - 1; i >= 0; i-- {
|
|
|
|
if contains(existedVersions, v.objects[i].Version()) {
|
|
|
|
delMarkHeader := v.objects[i].Headers[versionsDeleteMarkAttr]
|
|
|
|
if delMarkHeader == "" {
|
|
|
|
return v.objects[i]
|
|
|
|
}
|
|
|
|
if delMarkHeader == "*" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *objectVersions) getAddHeader() string {
|
|
|
|
return strings.Join(v.addList, ",")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *objectVersions) getDelHeader() string {
|
|
|
|
return strings.Join(v.delList, ",")
|
|
|
|
}
|
|
|
|
|
2021-07-05 19:18:58 +00:00
|
|
|
const (
|
2021-08-13 14:13:14 +00:00
|
|
|
unversionedObjectVersionID = "null"
|
|
|
|
bktVersionSettingsObject = ".s3-versioning-settings"
|
|
|
|
objectSystemAttributeName = "S3-System-name"
|
|
|
|
attrVersionsIgnore = "S3-Versions-ignore"
|
|
|
|
attrSettingsVersioningEnabled = "S3-Settings-Versioning-enabled"
|
2021-07-05 19:18:58 +00:00
|
|
|
)
|
2021-07-01 10:54:51 +00:00
|
|
|
|
2021-08-10 12:08:15 +00:00
|
|
|
func (t *VersionedObject) String() string {
|
|
|
|
return t.Name + ":" + t.VersionID
|
|
|
|
}
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// NewLayer creates instance of layer. It checks credentials
|
2020-08-03 11:48:33 +00:00
|
|
|
// and establishes gRPC connection with node.
|
2021-08-16 09:58:09 +00:00
|
|
|
func NewLayer(log *zap.Logger, conns pool.Pool, config *CacheConfig) Client {
|
2020-08-03 11:48:33 +00:00
|
|
|
return &layer{
|
2021-08-10 12:23:55 +00:00
|
|
|
pool: conns,
|
|
|
|
log: log,
|
2021-08-16 09:58:09 +00:00
|
|
|
listObjCache: newListObjectsCache(config.ListObjectsLifetime),
|
|
|
|
objCache: cache.New(config.Size, config.Lifetime),
|
2020-11-24 07:01:38 +00:00
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 12:36:15 +00:00
|
|
|
// Owner returns owner id from BearerToken (context) or from client owner.
|
|
|
|
func (n *layer) Owner(ctx context.Context) *owner.ID {
|
2021-07-16 12:35:07 +00:00
|
|
|
if data, ok := ctx.Value(api.BoxData).(*accessbox.Box); ok && data != nil && data.Gate != nil {
|
|
|
|
return data.Gate.BearerToken.Issuer()
|
2020-11-27 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 20:48:23 +00:00
|
|
|
return n.pool.OwnerID()
|
2020-11-27 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 13:59:51 +00:00
|
|
|
// BearerOpt returns client.WithBearer call option with token from context or with nil token.
|
|
|
|
func (n *layer) BearerOpt(ctx context.Context) client.CallOption {
|
2021-07-16 12:35:07 +00:00
|
|
|
if data, ok := ctx.Value(api.BoxData).(*accessbox.Box); ok && data != nil && data.Gate != nil {
|
|
|
|
return client.WithBearer(data.Gate.BearerToken)
|
2021-06-15 13:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return client.WithBearer(nil)
|
|
|
|
}
|
|
|
|
|
2021-06-21 10:54:57 +00:00
|
|
|
// SessionOpt returns client.WithSession call option with token from context or with nil token.
|
|
|
|
func (n *layer) SessionOpt(ctx context.Context) client.CallOption {
|
2021-07-16 12:35:07 +00:00
|
|
|
if data, ok := ctx.Value(api.BoxData).(*accessbox.Box); ok && data != nil && data.Gate != nil {
|
|
|
|
return client.WithSession(data.Gate.SessionToken)
|
2021-06-21 10:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return client.WithSession(nil)
|
|
|
|
}
|
|
|
|
|
2021-05-13 19:25:32 +00:00
|
|
|
// Get NeoFS Object by refs.Address (should be used by auth.Center).
|
2020-10-19 01:04:37 +00:00
|
|
|
func (n *layer) Get(ctx context.Context, address *object.Address) (*object.Object, error) {
|
2021-05-26 16:48:27 +00:00
|
|
|
ops := new(client.GetObjectParams).WithAddress(address)
|
2021-06-15 13:59:51 +00:00
|
|
|
return n.pool.GetObject(ctx, ops, n.BearerOpt(ctx))
|
2020-08-03 15:08:55 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 10:14:17 +00:00
|
|
|
// GetBucketInfo returns bucket info by name.
|
2020-08-03 11:48:33 +00:00
|
|
|
func (n *layer) GetBucketInfo(ctx context.Context, name string) (*BucketInfo, error) {
|
2020-10-24 13:09:22 +00:00
|
|
|
name, err := url.QueryUnescape(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-06-11 11:52:03 +00:00
|
|
|
containerID := new(cid.ID)
|
|
|
|
if err := containerID.Parse(name); err != nil {
|
2021-06-13 11:32:13 +00:00
|
|
|
list, err := n.containerList(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for _, bkt := range list {
|
|
|
|
if bkt.Name == name {
|
|
|
|
return bkt, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-09 08:53:58 +00:00
|
|
|
return nil, errors.GetAPIError(errors.ErrNoSuchBucket)
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 11:52:03 +00:00
|
|
|
return n.containerInfo(ctx, containerID)
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2021-07-21 11:59:46 +00:00
|
|
|
// GetBucketACL returns bucket acl info by name.
|
|
|
|
func (n *layer) GetBucketACL(ctx context.Context, name string) (*BucketACL, error) {
|
|
|
|
inf, err := n.GetBucketInfo(ctx, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
eacl, err := n.GetContainerEACL(ctx, inf.CID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &BucketACL{
|
|
|
|
Info: inf,
|
|
|
|
EACL: eacl,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutBucketACL put bucket acl by name.
|
|
|
|
func (n *layer) PutBucketACL(ctx context.Context, param *PutBucketACLParams) error {
|
|
|
|
inf, err := n.GetBucketInfo(ctx, param.Name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return n.setContainerEACLTable(ctx, inf.CID, param.EACL)
|
|
|
|
}
|
|
|
|
|
2020-08-03 11:48:33 +00:00
|
|
|
// ListBuckets returns all user containers. Name of the bucket is a container
|
|
|
|
// id. Timestamp is omitted since it is not saved in neofs container.
|
2020-10-23 00:12:37 +00:00
|
|
|
func (n *layer) ListBuckets(ctx context.Context) ([]*BucketInfo, error) {
|
2020-08-03 11:48:33 +00:00
|
|
|
return n.containerList(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetObject from storage.
|
|
|
|
func (n *layer) GetObject(ctx context.Context, p *GetObjectParams) error {
|
2021-08-10 10:03:09 +00:00
|
|
|
var err error
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2021-08-10 10:03:09 +00:00
|
|
|
//if bkt, err = n.GetBucketInfo(ctx, p.Bucket); err != nil {
|
|
|
|
// return fmt.Errorf("couldn't find bucket: %s : %w", p.Bucket, err)
|
|
|
|
//} else if oid, err = n.objectFindID(ctx, &findParams{cid: bkt.CID, val: p.Object}); err != nil {
|
|
|
|
// return fmt.Errorf("search of the object failed: cid: %s, val: %s : %w", bkt.CID, p.Object, err)
|
|
|
|
//}
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2020-10-19 01:04:37 +00:00
|
|
|
addr := object.NewAddress()
|
2021-08-10 10:03:09 +00:00
|
|
|
addr.SetObjectID(p.ObjectInfo.ID())
|
|
|
|
addr.SetContainerID(p.ObjectInfo.CID())
|
2020-10-19 01:04:37 +00:00
|
|
|
|
2021-06-24 11:10:00 +00:00
|
|
|
params := &getParams{
|
|
|
|
Writer: p.Writer,
|
2020-11-24 07:01:38 +00:00
|
|
|
address: addr,
|
2021-06-24 11:10:00 +00:00
|
|
|
offset: p.Offset,
|
|
|
|
length: p.Length,
|
|
|
|
}
|
2020-10-19 01:04:37 +00:00
|
|
|
|
2021-06-24 11:10:00 +00:00
|
|
|
if p.Range != nil {
|
|
|
|
objRange := object.NewRange()
|
|
|
|
objRange.SetOffset(p.Range.Start)
|
|
|
|
// Range header is inclusive
|
|
|
|
objRange.SetLength(p.Range.End - p.Range.Start + 1)
|
|
|
|
params.Range = objRange
|
|
|
|
_, err = n.objectRange(ctx, params)
|
|
|
|
} else {
|
|
|
|
_, err = n.objectGet(ctx, params)
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2021-05-20 10:14:17 +00:00
|
|
|
if err != nil {
|
2021-08-10 11:19:26 +00:00
|
|
|
n.objCache.Delete(addr)
|
2021-08-10 10:03:09 +00:00
|
|
|
return fmt.Errorf("couldn't get object, cid: %s : %w", p.ObjectInfo.CID(), err)
|
2021-05-20 10:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetObjectInfo returns meta information about the object.
|
2021-08-10 10:03:09 +00:00
|
|
|
func (n *layer) GetObjectInfo(ctx context.Context, p *HeadObjectParams) (*ObjectInfo, error) {
|
|
|
|
bkt, err := n.GetBucketInfo(ctx, p.Bucket)
|
2021-08-09 14:29:44 +00:00
|
|
|
if err != nil {
|
2020-11-27 12:36:15 +00:00
|
|
|
n.log.Error("could not fetch bucket info", zap.Error(err))
|
2020-08-03 11:48:33 +00:00
|
|
|
return nil, err
|
2021-08-09 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 10:03:09 +00:00
|
|
|
if len(p.VersionID) == 0 {
|
2021-08-13 14:13:14 +00:00
|
|
|
return n.headLastVersionIfNotDeleted(ctx, bkt, p.Object)
|
2021-08-10 10:03:09 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 12:08:15 +00:00
|
|
|
return n.headVersion(ctx, bkt, p.VersionID)
|
2021-08-09 14:29:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 08:19:09 +00:00
|
|
|
func (n *layer) getSettingsObjectInfo(ctx context.Context, bkt *BucketInfo) (*ObjectInfo, error) {
|
2021-08-13 14:13:14 +00:00
|
|
|
oid, err := n.objectFindID(ctx, &findParams{cid: bkt.CID, attr: objectSystemAttributeName, val: bktVersionSettingsObject})
|
2021-08-09 14:29:44 +00:00
|
|
|
if err != nil {
|
2020-08-03 11:48:33 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-10-19 01:04:37 +00:00
|
|
|
addr := object.NewAddress()
|
|
|
|
addr.SetObjectID(oid)
|
2020-10-24 13:09:22 +00:00
|
|
|
addr.SetContainerID(bkt.CID)
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2021-08-10 11:19:26 +00:00
|
|
|
/* todo: now we get an address via request to NeoFS and try to find the object with the address in cache
|
|
|
|
but it will be resolved after implementation of local cache with nicenames and address of objects
|
|
|
|
for get/head requests */
|
2021-08-09 14:29:44 +00:00
|
|
|
meta := n.objCache.Get(addr)
|
2021-08-10 11:19:26 +00:00
|
|
|
if meta == nil {
|
2021-08-10 10:03:09 +00:00
|
|
|
meta, err = n.objectHead(ctx, bkt.CID, oid)
|
2021-08-10 11:19:26 +00:00
|
|
|
if err != nil {
|
|
|
|
n.log.Error("could not fetch object head", zap.Error(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err = n.objCache.Put(addr, *meta); err != nil {
|
|
|
|
n.log.Error("couldn't cache an object", zap.Error(err))
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
2021-08-10 10:03:09 +00:00
|
|
|
|
2021-06-29 09:59:33 +00:00
|
|
|
return objectInfoFromMeta(bkt, meta, "", ""), nil
|
2020-10-19 01:04:37 +00:00
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
|
2020-10-19 01:04:37 +00:00
|
|
|
// PutObject into storage.
|
|
|
|
func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*ObjectInfo, error) {
|
2021-08-10 12:08:15 +00:00
|
|
|
bkt, err := n.GetBucketInfo(ctx, p.Bucket)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return n.objectPut(ctx, bkt, p)
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CopyObject from one bucket into another bucket.
|
|
|
|
func (n *layer) CopyObject(ctx context.Context, p *CopyObjectParams) (*ObjectInfo, error) {
|
|
|
|
pr, pw := io.Pipe()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
err := n.GetObject(ctx, &GetObjectParams{
|
2021-08-10 10:03:09 +00:00
|
|
|
ObjectInfo: p.SrcObject,
|
|
|
|
Writer: pw,
|
2020-08-03 11:48:33 +00:00
|
|
|
})
|
|
|
|
|
2020-10-24 13:09:22 +00:00
|
|
|
if err = pw.CloseWithError(err); err != nil {
|
|
|
|
n.log.Error("could not get object", zap.Error(err))
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
return n.PutObject(ctx, &PutObjectParams{
|
|
|
|
Bucket: p.DstBucket,
|
|
|
|
Object: p.DstObject,
|
2021-07-01 07:45:55 +00:00
|
|
|
Size: p.SrcSize,
|
2020-08-03 11:48:33 +00:00
|
|
|
Reader: pr,
|
2021-07-01 07:45:55 +00:00
|
|
|
Header: p.Header,
|
2020-08-03 11:48:33 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-08-20 19:41:52 +00:00
|
|
|
// DeleteObject removes all objects with passed nice name.
|
2021-08-10 12:08:15 +00:00
|
|
|
func (n *layer) deleteObject(ctx context.Context, bkt *BucketInfo, obj *VersionedObject) error {
|
2020-10-19 01:04:37 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
ids []*object.ID
|
|
|
|
)
|
|
|
|
|
2021-08-10 12:08:15 +00:00
|
|
|
versioningEnabled := n.isVersioningEnabled(ctx, bkt)
|
2021-08-11 10:02:13 +00:00
|
|
|
if !versioningEnabled && obj.VersionID != unversionedObjectVersionID && obj.VersionID != "" {
|
2021-08-10 12:08:15 +00:00
|
|
|
return errors.GetAPIError(errors.ErrInvalidVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
if versioningEnabled {
|
2021-08-13 14:13:14 +00:00
|
|
|
p := &PutObjectParams{
|
|
|
|
Object: obj.Name,
|
|
|
|
Reader: bytes.NewReader(nil),
|
|
|
|
Header: map[string]string{versionsDeleteMarkAttr: obj.VersionID},
|
|
|
|
}
|
2021-08-10 12:08:15 +00:00
|
|
|
if len(obj.VersionID) != 0 {
|
2021-08-13 14:13:14 +00:00
|
|
|
id, err := n.checkVersionsExists(ctx, bkt, obj)
|
2021-08-10 12:08:15 +00:00
|
|
|
if err != nil {
|
2021-08-13 14:13:14 +00:00
|
|
|
return err
|
2021-08-10 12:08:15 +00:00
|
|
|
}
|
2021-08-13 14:13:14 +00:00
|
|
|
ids = []*object.ID{id}
|
2021-08-10 12:08:15 +00:00
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
p.Header[versionsDelAttr] = obj.VersionID
|
2021-08-10 12:08:15 +00:00
|
|
|
} else {
|
2021-08-13 14:13:14 +00:00
|
|
|
p.Header[versionsDeleteMarkAttr] = "*"
|
|
|
|
}
|
|
|
|
if _, err = n.objectPut(ctx, bkt, p); err != nil {
|
|
|
|
return &errors.DeleteError{Err: err, Object: obj.String()}
|
2020-08-22 02:41:58 +00:00
|
|
|
}
|
2021-08-10 12:08:15 +00:00
|
|
|
} else {
|
|
|
|
ids, err = n.objectSearch(ctx, &findParams{cid: bkt.CID, val: obj.Name})
|
|
|
|
if err != nil {
|
|
|
|
return &errors.DeleteError{Err: err, Object: obj.String()}
|
2020-08-22 02:41:58 +00:00
|
|
|
}
|
2020-08-20 19:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, id := range ids {
|
2021-08-10 12:08:15 +00:00
|
|
|
if err = n.objectDelete(ctx, bkt.CID, id); err != nil {
|
|
|
|
return &errors.DeleteError{Err: err, Object: obj.String()}
|
2020-08-20 19:41:52 +00:00
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-20 19:41:52 +00:00
|
|
|
return nil
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
func (n *layer) checkVersionsExists(ctx context.Context, bkt *BucketInfo, obj *VersionedObject) (*object.ID, error) {
|
|
|
|
id := object.NewID()
|
|
|
|
if err := id.Parse(obj.VersionID); err != nil {
|
|
|
|
return nil, &errors.DeleteError{Err: errors.GetAPIError(errors.ErrInvalidVersion), Object: obj.String()}
|
|
|
|
}
|
|
|
|
|
|
|
|
versions, err := n.headVersions(ctx, bkt, obj.Name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, &errors.DeleteError{Err: err, Object: obj.String()}
|
|
|
|
}
|
|
|
|
if !contains(getExistedVersions(versions), obj.VersionID) {
|
|
|
|
return nil, &errors.DeleteError{Err: errors.GetAPIError(errors.ErrInvalidVersion), Object: obj.String()}
|
|
|
|
}
|
|
|
|
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
|
2020-08-03 11:48:33 +00:00
|
|
|
// DeleteObjects from the storage.
|
2021-08-10 12:08:15 +00:00
|
|
|
func (n *layer) DeleteObjects(ctx context.Context, bucket string, objects []*VersionedObject) []error {
|
2020-08-03 11:48:33 +00:00
|
|
|
var errs = make([]error, 0, len(objects))
|
|
|
|
|
2021-08-10 12:08:15 +00:00
|
|
|
bkt, err := n.GetBucketInfo(ctx, bucket)
|
|
|
|
if err != nil {
|
|
|
|
return append(errs, err)
|
|
|
|
}
|
|
|
|
|
2020-08-03 11:48:33 +00:00
|
|
|
for i := range objects {
|
2021-08-10 12:08:15 +00:00
|
|
|
if err := n.deleteObject(ctx, bkt, objects[i]); err != nil {
|
2020-08-22 02:41:58 +00:00
|
|
|
errs = append(errs, err)
|
|
|
|
}
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 02:41:58 +00:00
|
|
|
return errs
|
2020-08-03 11:48:33 +00:00
|
|
|
}
|
2021-06-23 20:21:15 +00:00
|
|
|
|
|
|
|
func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) {
|
2021-07-07 14:56:29 +00:00
|
|
|
_, err := n.GetBucketInfo(ctx, p.Name)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
func (n *layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error {
|
|
|
|
bucketInfo, err := n.GetBucketInfo(ctx, p.Name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-10 12:08:15 +00:00
|
|
|
ids, err := n.objectSearch(ctx, &findParams{cid: bucketInfo.CID})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(ids) != 0 {
|
2021-08-11 10:02:13 +00:00
|
|
|
return errors.GetAPIError(errors.ErrBucketNotEmpty)
|
2021-08-10 12:08:15 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 20:25:00 +00:00
|
|
|
return n.deleteContainer(ctx, bucketInfo.CID)
|
|
|
|
}
|
2021-07-05 19:18:58 +00:00
|
|
|
|
|
|
|
func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error) {
|
2021-08-13 14:13:14 +00:00
|
|
|
res := ListObjectVersionsInfo{}
|
|
|
|
versions := make(map[string]*objectVersions)
|
2021-07-05 19:18:58 +00:00
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
bkt, err := n.GetBucketInfo(ctx, p.Bucket)
|
|
|
|
if err != nil {
|
2021-07-05 19:18:58 +00:00
|
|
|
return nil, err
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
ids, err := n.objectSearch(ctx, &findParams{cid: bkt.CID})
|
|
|
|
if err != nil {
|
2021-07-05 19:18:58 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, id := range ids {
|
2021-08-10 10:03:09 +00:00
|
|
|
meta, err := n.objectHead(ctx, bkt.CID, id)
|
2021-07-05 19:18:58 +00:00
|
|
|
if err != nil {
|
|
|
|
n.log.Warn("could not fetch object meta", zap.Error(err))
|
|
|
|
continue
|
|
|
|
}
|
2021-08-13 14:13:14 +00:00
|
|
|
if oi := objectInfoFromMeta(bkt, meta, p.Prefix, p.Delimiter); oi != nil {
|
|
|
|
if oi.Name <= p.KeyMarker {
|
2021-07-05 19:18:58 +00:00
|
|
|
continue
|
|
|
|
}
|
2021-08-13 14:13:14 +00:00
|
|
|
if isSystem(oi) {
|
|
|
|
continue
|
2021-08-11 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
if objVersions, ok := versions[oi.Name]; ok {
|
|
|
|
objVersions.appendVersion(oi)
|
|
|
|
versions[oi.Name] = objVersions
|
2021-08-11 10:02:13 +00:00
|
|
|
} else {
|
2021-08-13 14:13:14 +00:00
|
|
|
objVersion := &objectVersions{}
|
|
|
|
objVersion.appendVersion(oi)
|
|
|
|
versions[oi.Name] = objVersion
|
2021-07-05 19:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
for _, v := range versions {
|
|
|
|
existed, deleted := triageVersions(v)
|
|
|
|
res.Version = append(res.Version, existed...)
|
|
|
|
res.DeleteMarker = append(res.DeleteMarker, deleted...)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(res.Version, func(i, j int) bool {
|
|
|
|
return res.Version[i].Object.Name < res.Version[j].Object.Name
|
|
|
|
})
|
|
|
|
sort.Slice(res.DeleteMarker, func(i, j int) bool {
|
|
|
|
return res.DeleteMarker[i].Object.Name < res.DeleteMarker[j].Object.Name
|
|
|
|
})
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortVersions(versions []*ObjectInfo) {
|
2021-07-05 19:18:58 +00:00
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
2021-08-13 14:13:14 +00:00
|
|
|
return less(versions[i], versions[j])
|
2021-07-05 19:18:58 +00:00
|
|
|
})
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
2021-07-05 19:18:58 +00:00
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
func triageVersions(objectVersions *objectVersions) ([]*ObjectVersionInfo, []*ObjectVersionInfo) {
|
|
|
|
if objectVersions == nil || len(objectVersions.objects) == 0 {
|
|
|
|
return nil, nil
|
2021-08-11 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
sortVersions(objectVersions.objects)
|
|
|
|
|
|
|
|
var resVersion []*ObjectVersionInfo
|
|
|
|
var resDelMarkVersions []*ObjectVersionInfo
|
2021-08-11 10:02:13 +00:00
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
isLatest := true
|
|
|
|
for i := len(objectVersions.objects) - 1; i >= 0; i-- {
|
|
|
|
version := objectVersions.objects[i]
|
|
|
|
if contains(objectVersions.delList, version.Version()) {
|
|
|
|
continue
|
2021-08-11 10:02:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
ovi := &ObjectVersionInfo{Object: version, IsLatest: isLatest}
|
|
|
|
isLatest = false
|
2021-07-05 19:18:58 +00:00
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
if len(version.Headers[versionsDeleteMarkAttr]) == 0 {
|
|
|
|
resVersion = append(resVersion, ovi)
|
|
|
|
} else {
|
|
|
|
resDelMarkVersions = append(resDelMarkVersions, ovi)
|
|
|
|
}
|
|
|
|
}
|
2021-07-05 19:18:58 +00:00
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
return resVersion, resDelMarkVersions
|
2021-08-11 10:02:13 +00:00
|
|
|
}
|
2021-07-05 19:18:58 +00:00
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
func less(ov1, ov2 *ObjectInfo) bool {
|
2021-08-11 10:02:13 +00:00
|
|
|
if ov1.CreationEpoch == ov2.CreationEpoch {
|
2021-08-13 14:13:14 +00:00
|
|
|
return ov1.Version() < ov2.Version()
|
2021-07-05 19:18:58 +00:00
|
|
|
}
|
2021-08-11 10:02:13 +00:00
|
|
|
return ov1.CreationEpoch < ov2.CreationEpoch
|
|
|
|
}
|
2021-07-05 19:18:58 +00:00
|
|
|
|
2021-08-11 10:02:13 +00:00
|
|
|
func contains(list []string, elem string) bool {
|
|
|
|
for _, item := range list {
|
|
|
|
if elem == item {
|
|
|
|
return true
|
2021-07-05 19:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-11 10:02:13 +00:00
|
|
|
return false
|
2021-07-05 19:18:58 +00:00
|
|
|
}
|
2021-08-09 14:29:44 +00:00
|
|
|
|
|
|
|
func (n *layer) PutBucketVersioning(ctx context.Context, p *PutVersioningParams) (*ObjectInfo, error) {
|
|
|
|
bucketInfo, err := n.GetBucketInfo(ctx, p.Bucket)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-08-10 08:19:09 +00:00
|
|
|
objectInfo, err := n.getSettingsObjectInfo(ctx, bucketInfo)
|
2021-08-09 14:29:44 +00:00
|
|
|
if err != nil {
|
|
|
|
n.log.Warn("couldn't get bucket version settings object, new one will be created",
|
|
|
|
zap.String("bucket_name", bucketInfo.Name),
|
|
|
|
zap.Stringer("cid", bucketInfo.CID),
|
|
|
|
zap.Error(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes := make([]*object.Attribute, 0, 3)
|
|
|
|
|
|
|
|
filename := object.NewAttribute()
|
2021-08-13 14:13:14 +00:00
|
|
|
filename.SetKey(objectSystemAttributeName)
|
2021-08-09 14:29:44 +00:00
|
|
|
filename.SetValue(bktVersionSettingsObject)
|
|
|
|
|
|
|
|
createdAt := object.NewAttribute()
|
|
|
|
createdAt.SetKey(object.AttributeTimestamp)
|
|
|
|
createdAt.SetValue(strconv.FormatInt(time.Now().UTC().Unix(), 10))
|
|
|
|
|
|
|
|
versioningIgnore := object.NewAttribute()
|
2021-08-13 14:13:14 +00:00
|
|
|
versioningIgnore.SetKey(attrVersionsIgnore)
|
2021-08-09 14:29:44 +00:00
|
|
|
versioningIgnore.SetValue(strconv.FormatBool(true))
|
|
|
|
|
|
|
|
settingsVersioningEnabled := object.NewAttribute()
|
2021-08-13 14:13:14 +00:00
|
|
|
settingsVersioningEnabled.SetKey(attrSettingsVersioningEnabled)
|
2021-08-10 08:58:40 +00:00
|
|
|
settingsVersioningEnabled.SetValue(strconv.FormatBool(p.Settings.VersioningEnabled))
|
2021-08-09 14:29:44 +00:00
|
|
|
|
|
|
|
attributes = append(attributes, filename, createdAt, versioningIgnore, settingsVersioningEnabled)
|
|
|
|
|
|
|
|
raw := object.NewRaw()
|
|
|
|
raw.SetOwnerID(bucketInfo.Owner)
|
|
|
|
raw.SetContainerID(bucketInfo.CID)
|
|
|
|
raw.SetAttributes(attributes...)
|
|
|
|
|
|
|
|
ops := new(client.PutObjectParams).WithObject(raw.Object())
|
|
|
|
oid, err := n.pool.PutObject(ctx, ops, n.BearerOpt(ctx))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-08-10 10:03:09 +00:00
|
|
|
meta, err := n.objectHead(ctx, bucketInfo.CID, oid)
|
2021-08-09 14:29:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if objectInfo != nil {
|
2021-08-10 12:08:15 +00:00
|
|
|
if err = n.objectDelete(ctx, bucketInfo.CID, objectInfo.ID()); err != nil {
|
2021-08-09 14:29:44 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return objectInfoFromMeta(bucketInfo, meta, "", ""), nil
|
|
|
|
}
|
|
|
|
|
2021-08-10 08:58:40 +00:00
|
|
|
func (n *layer) GetBucketVersioning(ctx context.Context, bucketName string) (*BucketSettings, error) {
|
2021-08-10 08:19:09 +00:00
|
|
|
bktInfo, err := n.GetBucketInfo(ctx, bucketName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-10 08:58:40 +00:00
|
|
|
|
|
|
|
return n.getBucketSettings(ctx, bktInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *layer) getBucketSettings(ctx context.Context, bktInfo *BucketInfo) (*BucketSettings, error) {
|
|
|
|
objInfo, err := n.getSettingsObjectInfo(ctx, bktInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return objectInfoToBucketSettings(objInfo), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func objectInfoToBucketSettings(info *ObjectInfo) *BucketSettings {
|
|
|
|
res := &BucketSettings{}
|
|
|
|
|
|
|
|
enabled, ok := info.Headers["S3-Settings-Versioning-enabled"]
|
|
|
|
if ok {
|
|
|
|
if parsed, err := strconv.ParseBool(enabled); err == nil {
|
|
|
|
res.VersioningEnabled = parsed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
2021-08-09 14:29:44 +00:00
|
|
|
}
|