[#438] Drop layer/neofs package

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-06-06 14:09:09 +03:00 committed by Alex Vanin
parent 40d8972fc6
commit f00ca1b6c4
10 changed files with 53 additions and 71 deletions

View file

@ -16,9 +16,7 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api"
"github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/data"
"github.com/nspcc-dev/neofs-s3-gw/api/layer" "github.com/nspcc-dev/neofs-s3-gw/api/layer"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-s3-gw/api/resolver" "github.com/nspcc-dev/neofs-s3-gw/api/resolver"
"github.com/nspcc-dev/neofs-s3-gw/internal/neofstest"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
"github.com/nspcc-dev/neofs-sdk-go/user" "github.com/nspcc-dev/neofs-sdk-go/user"
@ -28,14 +26,14 @@ import (
type handlerContext struct { type handlerContext struct {
h *handler h *handler
tp *neofstest.TestNeoFS tp *layer.TestNeoFS
} }
func (hc *handlerContext) Handler() *handler { func (hc *handlerContext) Handler() *handler {
return hc.h return hc.h
} }
func (hc *handlerContext) MockedPool() *neofstest.TestNeoFS { func (hc *handlerContext) MockedPool() *layer.TestNeoFS {
return hc.tp return hc.tp
} }
@ -48,7 +46,7 @@ func prepareHandlerContext(t *testing.T) *handlerContext {
require.NoError(t, err) require.NoError(t, err)
l := zap.NewNop() l := zap.NewNop()
tp := neofstest.NewTestNeoFS() tp := layer.NewTestNeoFS()
testResolver := &resolver.BucketResolver{Name: "test_resolver"} testResolver := &resolver.BucketResolver{Name: "test_resolver"}
testResolver.SetResolveFunc(func(_ context.Context, name string) (*cid.ID, error) { testResolver.SetResolveFunc(func(_ context.Context, name string) (*cid.ID, error) {
@ -74,14 +72,14 @@ func prepareHandlerContext(t *testing.T) *handlerContext {
} }
func createTestBucket(ctx context.Context, t *testing.T, h *handlerContext, bktName string) { func createTestBucket(ctx context.Context, t *testing.T, h *handlerContext, bktName string) {
_, err := h.MockedPool().CreateContainer(ctx, neofs.PrmContainerCreate{ _, err := h.MockedPool().CreateContainer(ctx, layer.PrmContainerCreate{
Name: bktName, Name: bktName,
}) })
require.NoError(t, err) require.NoError(t, err)
} }
func createTestBucketWithLock(ctx context.Context, t *testing.T, h *handlerContext, bktName string, conf *data.ObjectLockConfiguration) *data.BucketInfo { func createTestBucketWithLock(ctx context.Context, t *testing.T, h *handlerContext, bktName string, conf *data.ObjectLockConfiguration) *data.BucketInfo {
cnrID, err := h.MockedPool().CreateContainer(ctx, neofs.PrmContainerCreate{ cnrID, err := h.MockedPool().CreateContainer(ctx, layer.PrmContainerCreate{
Name: bktName, Name: bktName,
AdditionalAttributes: [][2]string{{layer.AttributeLockEnabled, "true"}}, AdditionalAttributes: [][2]string{{layer.AttributeLockEnabled, "true"}},
}) })

View file

@ -8,7 +8,6 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api"
"github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/data"
"github.com/nspcc-dev/neofs-s3-gw/api/errors" "github.com/nspcc-dev/neofs-s3-gw/api/errors"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-sdk-go/acl" "github.com/nspcc-dev/neofs-sdk-go/acl"
"github.com/nspcc-dev/neofs-sdk-go/client" "github.com/nspcc-dev/neofs-sdk-go/client"
"github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container"
@ -147,7 +146,7 @@ func (n *layer) createContainer(ctx context.Context, p *CreateBucketParams) (*da
}) })
} }
idCnr, err := n.neoFS.CreateContainer(ctx, neofs.PrmContainerCreate{ idCnr, err := n.neoFS.CreateContainer(ctx, PrmContainerCreate{
Creator: bktInfo.Owner, Creator: bktInfo.Owner,
Policy: *p.Policy, Policy: *p.Policy,
Name: p.Name, Name: p.Name,

View file

@ -15,7 +15,6 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/api/cache" "github.com/nspcc-dev/neofs-s3-gw/api/cache"
"github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/data"
"github.com/nspcc-dev/neofs-s3-gw/api/errors" "github.com/nspcc-dev/neofs-s3-gw/api/errors"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-s3-gw/api/resolver" "github.com/nspcc-dev/neofs-s3-gw/api/resolver"
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox" "github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
"github.com/nspcc-dev/neofs-sdk-go/bearer" "github.com/nspcc-dev/neofs-sdk-go/bearer"
@ -41,7 +40,7 @@ type (
MsgHandlerFunc func(context.Context, *nats.Msg) error MsgHandlerFunc func(context.Context, *nats.Msg) error
layer struct { layer struct {
neoFS neofs.NeoFS neoFS NeoFS
log *zap.Logger log *zap.Logger
anonKey AnonymousKey anonKey AnonymousKey
resolver *resolver.BucketResolver resolver *resolver.BucketResolver
@ -271,7 +270,7 @@ func DefaultCachesConfigs() *CachesConfig {
// NewLayer creates an instance of a layer. It checks credentials // NewLayer creates an instance of a layer. It checks credentials
// and establishes gRPC connection with the node. // and establishes gRPC connection with the node.
func NewLayer(log *zap.Logger, neoFS neofs.NeoFS, config *Config) Client { func NewLayer(log *zap.Logger, neoFS NeoFS, config *Config) Client {
return &layer{ return &layer{
neoFS: neoFS, neoFS: neoFS,
log: log, log: log,
@ -324,7 +323,7 @@ func (n *layer) Owner(ctx context.Context) user.ID {
return ownerID return ownerID
} }
func (n *layer) prepareAuthParameters(ctx context.Context, prm *neofs.PrmAuth, bktOwner user.ID) { func (n *layer) prepareAuthParameters(ctx context.Context, prm *PrmAuth, bktOwner user.ID) {
if bd, ok := ctx.Value(api.BoxData).(*accessbox.Box); ok && bd != nil && bd.Gate != nil && bd.Gate.BearerToken != nil { if bd, ok := ctx.Value(api.BoxData).(*accessbox.Box); ok && bd != nil && bd.Gate != nil && bd.Gate.BearerToken != nil {
if bktOwner.Equals(bearer.ResolveIssuer(*bd.Gate.BearerToken)) { if bktOwner.Equals(bearer.ResolveIssuer(*bd.Gate.BearerToken)) {
prm.BearerToken = bd.Gate.BearerToken prm.BearerToken = bd.Gate.BearerToken

View file

@ -1,4 +1,4 @@
package neofs package layer
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package neofstest package layer
import ( import (
"bytes" "bytes"
@ -12,7 +12,6 @@ import (
"time" "time"
objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object" objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-sdk-go/checksum" "github.com/nspcc-dev/neofs-sdk-go/checksum"
"github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
@ -21,10 +20,8 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/user" "github.com/nspcc-dev/neofs-sdk-go/user"
) )
const objectSystemAttributeName = "S3-System-name"
type TestNeoFS struct { type TestNeoFS struct {
neofs.NeoFS NeoFS
objects map[string]*object.Object objects map[string]*object.Object
containers map[string]*container.Container containers map[string]*container.Container
@ -68,7 +65,7 @@ func (t *TestNeoFS) ContainerID(name string) (*cid.ID, error) {
return nil, fmt.Errorf("not found") return nil, fmt.Errorf("not found")
} }
func (t *TestNeoFS) CreateContainer(_ context.Context, prm neofs.PrmContainerCreate) (*cid.ID, error) { func (t *TestNeoFS) CreateContainer(_ context.Context, prm PrmContainerCreate) (*cid.ID, error) {
opts := []container.Option{ opts := []container.Option{
container.WithOwnerID(&prm.Creator), container.WithOwnerID(&prm.Creator),
container.WithPolicy(&prm.Policy), container.WithPolicy(&prm.Policy),
@ -126,7 +123,7 @@ func (t *TestNeoFS) UserContainers(_ context.Context, _ user.ID) ([]cid.ID, erro
return res, nil return res, nil
} }
func (t *TestNeoFS) SelectObjects(_ context.Context, prm neofs.PrmObjectSelect) ([]oid.ID, error) { func (t *TestNeoFS) SelectObjects(_ context.Context, prm PrmObjectSelect) ([]oid.ID, error) {
filters := object.NewSearchFilters() filters := object.NewSearchFilters()
filters.AddRootFilter() filters.AddRootFilter()
@ -168,7 +165,7 @@ func (t *TestNeoFS) SelectObjects(_ context.Context, prm neofs.PrmObjectSelect)
return res, nil return res, nil
} }
func (t *TestNeoFS) ReadObject(_ context.Context, prm neofs.PrmObjectRead) (*neofs.ObjectPart, error) { func (t *TestNeoFS) ReadObject(_ context.Context, prm PrmObjectRead) (*ObjectPart, error) {
var addr oid.Address var addr oid.Address
addr.SetContainer(prm.Container) addr.SetContainer(prm.Container)
addr.SetObject(prm.Object) addr.SetObject(prm.Object)
@ -176,7 +173,7 @@ func (t *TestNeoFS) ReadObject(_ context.Context, prm neofs.PrmObjectRead) (*neo
sAddr := addr.EncodeToString() sAddr := addr.EncodeToString()
if obj, ok := t.objects[sAddr]; ok { if obj, ok := t.objects[sAddr]; ok {
return &neofs.ObjectPart{ return &ObjectPart{
Head: obj, Head: obj,
Payload: io.NopCloser(bytes.NewReader(obj.Payload())), Payload: io.NopCloser(bytes.NewReader(obj.Payload())),
}, nil }, nil
@ -185,7 +182,7 @@ func (t *TestNeoFS) ReadObject(_ context.Context, prm neofs.PrmObjectRead) (*neo
return nil, fmt.Errorf("object not found %s", addr) return nil, fmt.Errorf("object not found %s", addr)
} }
func (t *TestNeoFS) CreateObject(_ context.Context, prm neofs.PrmObjectCreate) (*oid.ID, error) { func (t *TestNeoFS) CreateObject(_ context.Context, prm PrmObjectCreate) (*oid.ID, error) {
b := make([]byte, 32) b := make([]byte, 32)
if _, err := io.ReadFull(rand.Reader, b); err != nil { if _, err := io.ReadFull(rand.Reader, b); err != nil {
return nil, err return nil, err
@ -243,7 +240,7 @@ func (t *TestNeoFS) CreateObject(_ context.Context, prm neofs.PrmObjectCreate) (
return &objID, nil return &objID, nil
} }
func (t *TestNeoFS) DeleteObject(_ context.Context, prm neofs.PrmObjectDelete) error { func (t *TestNeoFS) DeleteObject(_ context.Context, prm PrmObjectDelete) error {
var addr oid.Address var addr oid.Address
addr.SetContainer(prm.Container) addr.SetContainer(prm.Container)
addr.SetObject(prm.Object) addr.SetObject(prm.Object)
@ -266,10 +263,3 @@ func isMatched(attributes []object.Attribute, filter object.SearchFilter) bool {
return false return false
} }
func newAddress(cnr cid.ID, obj oid.ID) oid.Address {
var addr oid.Address
addr.SetContainer(cnr)
addr.SetObject(obj)
return addr
}

View file

@ -15,7 +15,6 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/api/cache" "github.com/nspcc-dev/neofs-s3-gw/api/cache"
"github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/data"
apiErrors "github.com/nspcc-dev/neofs-s3-gw/api/errors" apiErrors "github.com/nspcc-dev/neofs-s3-gw/api/errors"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-s3-gw/internal/misc" "github.com/nspcc-dev/neofs-s3-gw/internal/misc"
"github.com/nspcc-dev/neofs-sdk-go/client" "github.com/nspcc-dev/neofs-sdk-go/client"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
@ -79,7 +78,7 @@ func (n *layer) objectSearchByName(ctx context.Context, bktInfo *data.BucketInfo
// objectSearch returns all available objects by search params. // objectSearch returns all available objects by search params.
func (n *layer) objectSearch(ctx context.Context, p *findParams) ([]oid.ID, error) { func (n *layer) objectSearch(ctx context.Context, p *findParams) ([]oid.ID, error) {
prm := neofs.PrmObjectSelect{ prm := PrmObjectSelect{
Container: p.bkt.CID, Container: p.bkt.CID,
ExactAttribute: p.attr, ExactAttribute: p.attr,
FilePrefix: p.prefix, FilePrefix: p.prefix,
@ -101,7 +100,7 @@ func newAddress(cnr cid.ID, obj oid.ID) oid.Address {
// objectHead returns all object's headers. // objectHead returns all object's headers.
func (n *layer) objectHead(ctx context.Context, bktInfo *data.BucketInfo, idObj oid.ID) (*object.Object, error) { func (n *layer) objectHead(ctx context.Context, bktInfo *data.BucketInfo, idObj oid.ID) (*object.Object, error) {
prm := neofs.PrmObjectRead{ prm := PrmObjectRead{
Container: bktInfo.CID, Container: bktInfo.CID,
Object: idObj, Object: idObj,
WithHeader: true, WithHeader: true,
@ -120,7 +119,7 @@ func (n *layer) objectHead(ctx context.Context, bktInfo *data.BucketInfo, idObj
// initializes payload reader of the NeoFS object. // initializes payload reader of the NeoFS object.
// Zero range corresponds to full payload (panics if only offset is set). // Zero range corresponds to full payload (panics if only offset is set).
func (n *layer) initObjectPayloadReader(ctx context.Context, p getParams) (io.Reader, error) { func (n *layer) initObjectPayloadReader(ctx context.Context, p getParams) (io.Reader, error) {
prm := neofs.PrmObjectRead{ prm := PrmObjectRead{
Container: p.objInfo.CID, Container: p.objInfo.CID,
Object: p.objInfo.ID, Object: p.objInfo.ID,
WithPayload: true, WithPayload: true,
@ -139,7 +138,7 @@ func (n *layer) initObjectPayloadReader(ctx context.Context, p getParams) (io.Re
// objectGet returns an object with payload in the object. // objectGet returns an object with payload in the object.
func (n *layer) objectGet(ctx context.Context, bktInfo *data.BucketInfo, objID oid.ID) (*object.Object, error) { func (n *layer) objectGet(ctx context.Context, bktInfo *data.BucketInfo, objID oid.ID) (*object.Object, error) {
prm := neofs.PrmObjectRead{ prm := PrmObjectRead{
Container: bktInfo.CID, Container: bktInfo.CID,
Object: objID, Object: objID,
WithHeader: true, WithHeader: true,
@ -178,7 +177,7 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Object
} }
} }
prm := neofs.PrmObjectCreate{ prm := PrmObjectCreate{
Container: p.BktInfo.CID, Container: p.BktInfo.CID,
Creator: own, Creator: own,
PayloadSize: uint64(p.Size), PayloadSize: uint64(p.Size),
@ -439,7 +438,7 @@ func (n *layer) headVersion(ctx context.Context, bkt *data.BucketInfo, p *HeadOb
// objectDelete puts tombstone object into neofs. // objectDelete puts tombstone object into neofs.
func (n *layer) objectDelete(ctx context.Context, bktInfo *data.BucketInfo, idObj oid.ID) error { func (n *layer) objectDelete(ctx context.Context, bktInfo *data.BucketInfo, idObj oid.ID) error {
prm := neofs.PrmObjectDelete{ prm := PrmObjectDelete{
Container: bktInfo.CID, Container: bktInfo.CID,
Object: idObj, Object: idObj,
} }
@ -453,7 +452,7 @@ func (n *layer) objectDelete(ctx context.Context, bktInfo *data.BucketInfo, idOb
// objectPutAndHash prepare auth parameters and invoke neofs.CreateObject. // objectPutAndHash prepare auth parameters and invoke neofs.CreateObject.
// Returns object ID and payload sha256 hash. // Returns object ID and payload sha256 hash.
func (n *layer) objectPutAndHash(ctx context.Context, prm neofs.PrmObjectCreate, bktInfo *data.BucketInfo) (*oid.ID, []byte, error) { func (n *layer) objectPutAndHash(ctx context.Context, prm PrmObjectCreate, bktInfo *data.BucketInfo) (*oid.ID, []byte, error) {
n.prepareAuthParameters(ctx, &prm.PrmAuth, bktInfo.Owner) n.prepareAuthParameters(ctx, &prm.PrmAuth, bktInfo.Owner)
hash := sha256.New() hash := sha256.New()
prm.Payload = wrapReader(prm.Payload, 64*1024, func(buf []byte) { prm.Payload = wrapReader(prm.Payload, 64*1024, func(buf []byte) {
@ -705,7 +704,7 @@ func (n *layer) transformNeofsError(ctx context.Context, err error) error {
return nil return nil
} }
if errors.Is(err, neofs.ErrAccessDenied) { if errors.Is(err, ErrAccessDenied) {
n.log.Debug("error was transformed", zap.String("request_id", api.GetRequestID(ctx)), zap.Error(err)) n.log.Debug("error was transformed", zap.String("request_id", api.GetRequestID(ctx)), zap.Error(err))
return apiErrors.GetAPIError(apiErrors.ErrAccessDenied) return apiErrors.GetAPIError(apiErrors.ErrAccessDenied)
} }

View file

@ -12,7 +12,6 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/data"
"github.com/nspcc-dev/neofs-s3-gw/api/errors" "github.com/nspcc-dev/neofs-s3-gw/api/errors"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-s3-gw/internal/misc" "github.com/nspcc-dev/neofs-s3-gw/internal/misc"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
"go.uber.org/zap" "go.uber.org/zap"
@ -85,7 +84,7 @@ func (n *layer) putSystemObjectIntoNeoFS(ctx context.Context, p *PutSystemObject
idsToDeleteArr := updateCRDT2PSetHeaders(p.Metadata, versions, false) // false means "last write wins" idsToDeleteArr := updateCRDT2PSetHeaders(p.Metadata, versions, false) // false means "last write wins"
// note that updateCRDT2PSetHeaders modifies p.Metadata and must be called further processing // note that updateCRDT2PSetHeaders modifies p.Metadata and must be called further processing
prm := neofs.PrmObjectCreate{ prm := PrmObjectCreate{
Container: p.BktInfo.CID, Container: p.BktInfo.CID,
Creator: p.BktInfo.Owner, Creator: p.BktInfo.Owner,
Attributes: make([][2]string, 2, 2+len(p.Metadata)), Attributes: make([][2]string, 2, 2+len(p.Metadata)),

View file

@ -10,9 +10,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api"
"github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/data"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox" "github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
"github.com/nspcc-dev/neofs-s3-gw/internal/neofstest"
bearertest "github.com/nspcc-dev/neofs-sdk-go/bearer/test" bearertest "github.com/nspcc-dev/neofs-sdk-go/bearer/test"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
@ -134,7 +132,7 @@ type testContext struct {
layer Client layer Client
bktInfo *data.BucketInfo bktInfo *data.BucketInfo
obj string obj string
testNeoFS *neofstest.TestNeoFS testNeoFS *TestNeoFS
} }
func prepareContext(t *testing.T, cachesConfig ...*CachesConfig) *testContext { func prepareContext(t *testing.T, cachesConfig ...*CachesConfig) *testContext {
@ -150,10 +148,10 @@ func prepareContext(t *testing.T, cachesConfig ...*CachesConfig) *testContext {
GateKey: key.PublicKey(), GateKey: key.PublicKey(),
}, },
}) })
tp := neofstest.NewTestNeoFS() tp := NewTestNeoFS()
bktName := "testbucket1" bktName := "testbucket1"
bktID, err := tp.CreateContainer(ctx, neofs.PrmContainerCreate{ bktID, err := tp.CreateContainer(ctx, PrmContainerCreate{
Name: bktName, Name: bktName,
}) })
require.NoError(t, err) require.NoError(t, err)

View file

@ -13,7 +13,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object" objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs" "github.com/nspcc-dev/neofs-s3-gw/api/layer"
"github.com/nspcc-dev/neofs-s3-gw/authmate" "github.com/nspcc-dev/neofs-s3-gw/authmate"
"github.com/nspcc-dev/neofs-s3-gw/creds/tokens" "github.com/nspcc-dev/neofs-s3-gw/creds/tokens"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
@ -119,7 +119,7 @@ func (x *NeoFS) Container(ctx context.Context, idCnr cid.ID) (*container.Contain
} }
// CreateContainer implements neofs.NeoFS interface method. // CreateContainer implements neofs.NeoFS interface method.
func (x *NeoFS) CreateContainer(ctx context.Context, prm neofs.PrmContainerCreate) (*cid.ID, error) { func (x *NeoFS) CreateContainer(ctx context.Context, prm layer.PrmContainerCreate) (*cid.ID, error) {
// fill container structure // fill container structure
cnrOptions := []container.Option{ cnrOptions := []container.Option{
container.WithPolicy(&prm.Policy), container.WithPolicy(&prm.Policy),
@ -222,7 +222,7 @@ func (x *NeoFS) DeleteContainer(ctx context.Context, id cid.ID, token *session.C
} }
// CreateObject implements neofs.NeoFS interface method. // CreateObject implements neofs.NeoFS interface method.
func (x *NeoFS) CreateObject(ctx context.Context, prm neofs.PrmObjectCreate) (*oid.ID, error) { func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (*oid.ID, error) {
attrNum := len(prm.Attributes) + 1 // + creation time attrNum := len(prm.Attributes) + 1 // + creation time
if prm.Filename != "" { if prm.Filename != "" {
@ -282,7 +282,7 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm neofs.PrmObjectCreate) (*o
} }
// SelectObjects implements neofs.NeoFS interface method. // SelectObjects implements neofs.NeoFS interface method.
func (x *NeoFS) SelectObjects(ctx context.Context, prm neofs.PrmObjectSelect) ([]oid.ID, error) { func (x *NeoFS) SelectObjects(ctx context.Context, prm layer.PrmObjectSelect) ([]oid.ID, error) {
filters := object.NewSearchFilters() filters := object.NewSearchFilters()
filters.AddRootFilter() filters.AddRootFilter()
@ -319,7 +319,7 @@ func (x *NeoFS) SelectObjects(ctx context.Context, prm neofs.PrmObjectSelect) ([
}) })
if err != nil { if err != nil {
if reason, ok := isErrAccessDenied(err); ok { if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", neofs.ErrAccessDenied, reason) return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
} }
return nil, fmt.Errorf("read object list: %w", err) return nil, fmt.Errorf("read object list: %w", err)
@ -338,7 +338,7 @@ func (x payloadReader) Read(p []byte) (int, error) {
n, err := x.ReadCloser.Read(p) n, err := x.ReadCloser.Read(p)
if err != nil { if err != nil {
if reason, ok := isErrAccessDenied(err); ok { if reason, ok := isErrAccessDenied(err); ok {
return n, fmt.Errorf("%w: %s", neofs.ErrAccessDenied, reason) return n, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
} }
} }
@ -346,7 +346,7 @@ func (x payloadReader) Read(p []byte) (int, error) {
} }
// ReadObject implements neofs.NeoFS interface method. // ReadObject implements neofs.NeoFS interface method.
func (x *NeoFS) ReadObject(ctx context.Context, prm neofs.PrmObjectRead) (*neofs.ObjectPart, error) { func (x *NeoFS) ReadObject(ctx context.Context, prm layer.PrmObjectRead) (*layer.ObjectPart, error) {
var addr oid.Address var addr oid.Address
addr.SetContainer(prm.Container) addr.SetContainer(prm.Container)
addr.SetObject(prm.Object) addr.SetObject(prm.Object)
@ -365,7 +365,7 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm neofs.PrmObjectRead) (*neofs
res, err := x.pool.GetObject(ctx, prmGet) res, err := x.pool.GetObject(ctx, prmGet)
if err != nil { if err != nil {
if reason, ok := isErrAccessDenied(err); ok { if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", neofs.ErrAccessDenied, reason) return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
} }
return nil, fmt.Errorf("init full object reading via connection pool: %w", err) return nil, fmt.Errorf("init full object reading via connection pool: %w", err)
@ -380,7 +380,7 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm neofs.PrmObjectRead) (*neofs
res.Header.SetPayload(payload) res.Header.SetPayload(payload)
return &neofs.ObjectPart{ return &layer.ObjectPart{
Head: &res.Header, Head: &res.Header,
}, nil }, nil
} }
@ -397,26 +397,26 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm neofs.PrmObjectRead) (*neofs
hdr, err := x.pool.HeadObject(ctx, prmHead) hdr, err := x.pool.HeadObject(ctx, prmHead)
if err != nil { if err != nil {
if reason, ok := isErrAccessDenied(err); ok { if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", neofs.ErrAccessDenied, reason) return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
} }
return nil, fmt.Errorf("read object header via connection pool: %w", err) return nil, fmt.Errorf("read object header via connection pool: %w", err)
} }
return &neofs.ObjectPart{ return &layer.ObjectPart{
Head: hdr, Head: hdr,
}, nil }, nil
} else if prm.PayloadRange[0]+prm.PayloadRange[1] == 0 { } else if prm.PayloadRange[0]+prm.PayloadRange[1] == 0 {
res, err := x.pool.GetObject(ctx, prmGet) res, err := x.pool.GetObject(ctx, prmGet)
if err != nil { if err != nil {
if reason, ok := isErrAccessDenied(err); ok { if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", neofs.ErrAccessDenied, reason) return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
} }
return nil, fmt.Errorf("init full payload range reading via connection pool: %w", err) return nil, fmt.Errorf("init full payload range reading via connection pool: %w", err)
} }
return &neofs.ObjectPart{ return &layer.ObjectPart{
Payload: res.Payload, Payload: res.Payload,
}, nil }, nil
} }
@ -435,19 +435,19 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm neofs.PrmObjectRead) (*neofs
res, err := x.pool.ObjectRange(ctx, prmRange) res, err := x.pool.ObjectRange(ctx, prmRange)
if err != nil { if err != nil {
if reason, ok := isErrAccessDenied(err); ok { if reason, ok := isErrAccessDenied(err); ok {
return nil, fmt.Errorf("%w: %s", neofs.ErrAccessDenied, reason) return nil, fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
} }
return nil, fmt.Errorf("init payload range reading via connection pool: %w", err) return nil, fmt.Errorf("init payload range reading via connection pool: %w", err)
} }
return &neofs.ObjectPart{ return &layer.ObjectPart{
Payload: payloadReader{res}, Payload: payloadReader{res},
}, nil }, nil
} }
// DeleteObject implements neofs.NeoFS interface method. // DeleteObject implements neofs.NeoFS interface method.
func (x *NeoFS) DeleteObject(ctx context.Context, prm neofs.PrmObjectDelete) error { func (x *NeoFS) DeleteObject(ctx context.Context, prm layer.PrmObjectDelete) error {
var addr oid.Address var addr oid.Address
addr.SetContainer(prm.Container) addr.SetContainer(prm.Container)
addr.SetObject(prm.Object) addr.SetObject(prm.Object)
@ -464,7 +464,7 @@ func (x *NeoFS) DeleteObject(ctx context.Context, prm neofs.PrmObjectDelete) err
err := x.pool.DeleteObject(ctx, prmDelete) err := x.pool.DeleteObject(ctx, prmDelete)
if err != nil { if err != nil {
if reason, ok := isErrAccessDenied(err); ok { if reason, ok := isErrAccessDenied(err); ok {
return fmt.Errorf("%w: %s", neofs.ErrAccessDenied, reason) return fmt.Errorf("%w: %s", layer.ErrAccessDenied, reason)
} }
return fmt.Errorf("mark object removal via connection pool: %w", err) return fmt.Errorf("mark object removal via connection pool: %w", err)
@ -547,7 +547,7 @@ func (x *AuthmateNeoFS) TimeToEpoch(ctx context.Context, futureTime time.Time) (
// CreateContainer implements authmate.NeoFS interface method. // CreateContainer implements authmate.NeoFS interface method.
func (x *AuthmateNeoFS) CreateContainer(ctx context.Context, prm authmate.PrmContainerCreate) (*cid.ID, error) { func (x *AuthmateNeoFS) CreateContainer(ctx context.Context, prm authmate.PrmContainerCreate) (*cid.ID, error) {
return x.neoFS.CreateContainer(ctx, neofs.PrmContainerCreate{ return x.neoFS.CreateContainer(ctx, layer.PrmContainerCreate{
Creator: prm.Owner, Creator: prm.Owner,
Policy: prm.Policy, Policy: prm.Policy,
Name: prm.FriendlyName, Name: prm.FriendlyName,
@ -557,7 +557,7 @@ func (x *AuthmateNeoFS) CreateContainer(ctx context.Context, prm authmate.PrmCon
// ReadObjectPayload implements authmate.NeoFS interface method. // ReadObjectPayload implements authmate.NeoFS interface method.
func (x *AuthmateNeoFS) ReadObjectPayload(ctx context.Context, addr oid.Address) ([]byte, error) { func (x *AuthmateNeoFS) ReadObjectPayload(ctx context.Context, addr oid.Address) ([]byte, error) {
res, err := x.neoFS.ReadObject(ctx, neofs.PrmObjectRead{ res, err := x.neoFS.ReadObject(ctx, layer.PrmObjectRead{
Container: addr.Container(), Container: addr.Container(),
Object: addr.Object(), Object: addr.Object(),
WithPayload: true, WithPayload: true,
@ -573,7 +573,7 @@ func (x *AuthmateNeoFS) ReadObjectPayload(ctx context.Context, addr oid.Address)
// CreateObject implements authmate.NeoFS interface method. // CreateObject implements authmate.NeoFS interface method.
func (x *AuthmateNeoFS) CreateObject(ctx context.Context, prm tokens.PrmObjectCreate) (*oid.ID, error) { func (x *AuthmateNeoFS) CreateObject(ctx context.Context, prm tokens.PrmObjectCreate) (*oid.ID, error) {
return x.neoFS.CreateObject(ctx, neofs.PrmObjectCreate{ return x.neoFS.CreateObject(ctx, layer.PrmObjectCreate{
Creator: prm.Creator, Creator: prm.Creator,
Container: prm.Container, Container: prm.Container,
Filename: prm.Filename, Filename: prm.Filename,

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs" "github.com/nspcc-dev/neofs-s3-gw/api/layer"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -17,9 +17,9 @@ func TestErrorChecking(t *testing.T) {
var wrappedError error var wrappedError error
if fetchedReason, ok := isErrAccessDenied(err); ok { if fetchedReason, ok := isErrAccessDenied(err); ok {
wrappedError = fmt.Errorf("%w: %s", neofs.ErrAccessDenied, fetchedReason) wrappedError = fmt.Errorf("%w: %s", layer.ErrAccessDenied, fetchedReason)
} }
require.ErrorIs(t, wrappedError, neofs.ErrAccessDenied) require.ErrorIs(t, wrappedError, layer.ErrAccessDenied)
require.Contains(t, wrappedError.Error(), reason) require.Contains(t, wrappedError.Error(), reason)
} }