2022-05-20 08:26:35 +00:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-05-20 15:02:00 +00:00
|
|
|
"errors"
|
2022-05-20 08:26:35 +00:00
|
|
|
"sort"
|
2022-05-20 15:02:00 +00:00
|
|
|
"strings"
|
2022-05-20 08:26:35 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TreeServiceMock struct {
|
|
|
|
settings map[string]*data.BucketSettings
|
2022-05-20 15:02:00 +00:00
|
|
|
versions map[string]map[string][]*data.NodeVersion
|
|
|
|
system map[string]map[string]*data.BaseNodeVersion
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 06:58:33 +00:00
|
|
|
func (t *TreeServiceMock) GetObjectTagging(ctx context.Context, cnrID *cid.ID, objVersion *data.NodeVersion) (map[string]string, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) PutObjectTagging(ctx context.Context, cnrID *cid.ID, objVersion *data.NodeVersion, tagSet map[string]string) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) DeleteObjectTagging(ctx context.Context, cnrID *cid.ID, objVersion *data.NodeVersion) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-05-25 01:58:25 +00:00
|
|
|
func (t *TreeServiceMock) GetBucketTagging(ctx context.Context, cnrID *cid.ID) (map[string]string, error) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) PutBucketTagging(ctx context.Context, cnrID *cid.ID, tagSet map[string]string) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) DeleteBucketTagging(ctx context.Context, cnrID *cid.ID) error {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
var ErrNodeNotFound = errors.New("not found")
|
|
|
|
|
2022-05-20 08:26:35 +00:00
|
|
|
func NewTreeService() *TreeServiceMock {
|
|
|
|
return &TreeServiceMock{
|
|
|
|
settings: make(map[string]*data.BucketSettings),
|
2022-05-20 15:02:00 +00:00
|
|
|
versions: make(map[string]map[string][]*data.NodeVersion),
|
|
|
|
system: make(map[string]map[string]*data.BaseNodeVersion),
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) PutSettingsNode(_ context.Context, id *cid.ID, settings *data.BucketSettings) error {
|
|
|
|
t.settings[id.EncodeToString()] = settings
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) GetSettingsNode(_ context.Context, id *cid.ID) (*data.BucketSettings, error) {
|
|
|
|
settings, ok := t.settings[id.EncodeToString()]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return settings, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) GetNotificationConfigurationNode(ctx context.Context, cnrID *cid.ID) (*oid.ID, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) PutNotificationConfigurationNode(ctx context.Context, cnrID *cid.ID, objID *oid.ID) (*oid.ID, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) GetBucketCORS(ctx context.Context, cnrID *cid.ID) (*oid.ID, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) PutBucketCORS(ctx context.Context, cnrID *cid.ID, objID *oid.ID) (*oid.ID, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) DeleteBucketCORS(ctx context.Context, cnrID *cid.ID) (*oid.ID, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
func (t *TreeServiceMock) GetVersions(_ context.Context, cnrID *cid.ID, objectName string) ([]*data.NodeVersion, error) {
|
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
return versions, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
func (t *TreeServiceMock) GetLatestVersion(ctx context.Context, cnrID *cid.ID, objectName string) (*data.NodeVersion, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[i].ID < versions[j].ID
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(versions) != 0 {
|
|
|
|
return versions[len(versions)-1], nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
func (t *TreeServiceMock) GetLatestVersionsByPrefix(_ context.Context, cnrID *cid.ID, prefix string) ([]oid.ID, error) {
|
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrNodeNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
var result []oid.ID
|
|
|
|
|
|
|
|
for key, versions := range cnrVersionsMap {
|
|
|
|
if !strings.HasPrefix(key, prefix) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[i].ID < versions[j].ID
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(versions) != 0 {
|
|
|
|
result = append(result, versions[len(versions)-1].OID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
func (t *TreeServiceMock) GetUnversioned(ctx context.Context, cnrID *cid.ID, objectName string) (*data.NodeVersion, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
func (t *TreeServiceMock) AddVersion(_ context.Context, cnrID *cid.ID, objectName string, newVersion *data.NodeVersion) error {
|
2022-05-20 08:26:35 +00:00
|
|
|
cnrVersionsMap, ok := t.versions[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
t.versions[cnrID.EncodeToString()] = map[string][]*data.NodeVersion{
|
2022-05-20 08:26:35 +00:00
|
|
|
objectName: {newVersion},
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
versions, ok := cnrVersionsMap[objectName]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
cnrVersionsMap[objectName] = []*data.NodeVersion{newVersion}
|
2022-05-20 08:26:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(versions, func(i, j int) bool {
|
|
|
|
return versions[i].ID < versions[j].ID
|
|
|
|
})
|
|
|
|
|
|
|
|
if len(versions) != 0 {
|
|
|
|
newVersion.ID = versions[len(versions)-1].ID + 1
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
result := versions
|
|
|
|
|
|
|
|
if newVersion.IsUnversioned {
|
|
|
|
result = make([]*data.NodeVersion, 0, len(versions))
|
|
|
|
for _, node := range versions {
|
|
|
|
if !node.IsUnversioned {
|
|
|
|
result = append(result, node)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrVersionsMap[objectName] = append(result, newVersion)
|
2022-05-20 08:26:35 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) RemoveVersion(ctx context.Context, cnrID *cid.ID, nodeID uint64) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
func (t *TreeServiceMock) AddSystemVersion(_ context.Context, cnrID *cid.ID, objectName string, newVersion *data.BaseNodeVersion) error {
|
2022-05-20 08:26:35 +00:00
|
|
|
cnrSystemMap, ok := t.system[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
t.system[cnrID.EncodeToString()] = map[string]*data.BaseNodeVersion{
|
2022-05-20 08:26:35 +00:00
|
|
|
objectName: newVersion,
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrSystemMap[objectName] = newVersion
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
func (t *TreeServiceMock) GetSystemVersion(_ context.Context, cnrID *cid.ID, objectName string) (*data.BaseNodeVersion, error) {
|
2022-05-20 08:26:35 +00:00
|
|
|
cnrSystemMap, ok := t.system[cnrID.EncodeToString()]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sysVersion, ok := cnrSystemMap[objectName]
|
|
|
|
if !ok {
|
2022-05-20 15:02:00 +00:00
|
|
|
return nil, ErrNodeNotFound
|
2022-05-20 08:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sysVersion, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) RemoveSystemVersion(ctx context.Context, cnrID *cid.ID, nodeID uint64) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
2022-05-20 15:02:00 +00:00
|
|
|
|
|
|
|
func (t *TreeServiceMock) GetAllVersionsByPrefix(ctx context.Context, cnrID *cid.ID, prefix string) ([]*data.NodeVersion, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
2022-05-24 08:41:10 +00:00
|
|
|
|
|
|
|
func (t *TreeServiceMock) CreateMultipart(ctx context.Context, cnrID *cid.ID, info *data.MultipartInfo) error {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TreeServiceMock) GetMultipartUploadsByPrefix(ctx context.Context, cnrID *cid.ID, prefix string) ([]*data.MultipartInfo, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|