2023-12-27 14:18:15 +00:00
|
|
|
package ape
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
2024-03-11 14:55:50 +00:00
|
|
|
"errors"
|
2023-12-27 14:18:15 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
|
2024-05-08 07:02:54 +00:00
|
|
|
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
2024-05-29 08:11:45 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
2023-12-27 14:18:15 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2024-03-15 12:16:52 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2023-12-27 14:18:15 +00:00
|
|
|
nativeschema "git.frostfs.info/TrueCloudLab/policy-engine/schema/native"
|
|
|
|
)
|
|
|
|
|
2024-03-11 14:55:50 +00:00
|
|
|
var errFailedToCastToRequestContext = errors.New("failed cast to RequestContext")
|
|
|
|
|
2023-12-27 14:18:15 +00:00
|
|
|
type Service struct {
|
|
|
|
apeChecker Checker
|
|
|
|
|
|
|
|
next objectSvc.ServiceServer
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ objectSvc.ServiceServer = (*Service)(nil)
|
|
|
|
|
|
|
|
type HeaderProvider interface {
|
2024-05-08 07:02:54 +00:00
|
|
|
GetHeader(ctx context.Context, cnr cid.ID, oid oid.ID, local bool) (*objectSDK.Object, error)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type storageEngineHeaderProvider struct {
|
|
|
|
storageEngine *engine.StorageEngine
|
2024-05-08 07:02:54 +00:00
|
|
|
getSvc *getsvc.Service
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
2024-05-08 07:02:54 +00:00
|
|
|
func (p storageEngineHeaderProvider) GetHeader(ctx context.Context, cnr cid.ID, objID oid.ID, local bool) (*objectSDK.Object, error) {
|
2023-12-27 14:18:15 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cnr)
|
|
|
|
addr.SetObject(objID)
|
2024-05-08 07:02:54 +00:00
|
|
|
if local {
|
|
|
|
return engine.Head(ctx, p.storageEngine, addr)
|
|
|
|
}
|
|
|
|
w := getsvc.NewSimpleObjectWriter()
|
|
|
|
var headPrm getsvc.HeadPrm
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
headPrm.SetHeaderWriter(w)
|
|
|
|
headPrm.SetCommonParameters(&util.CommonPrm{}) // default values are ok
|
|
|
|
if err := p.getSvc.Head(ctx, headPrm); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return w.Object(), nil
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
2024-05-08 07:02:54 +00:00
|
|
|
func NewStorageEngineHeaderProvider(e *engine.StorageEngine, s *getsvc.Service) HeaderProvider {
|
2023-12-27 14:18:15 +00:00
|
|
|
return storageEngineHeaderProvider{
|
|
|
|
storageEngine: e,
|
2024-05-08 07:02:54 +00:00
|
|
|
getSvc: s,
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-23 06:08:11 +00:00
|
|
|
func NewService(apeChecker Checker, next objectSvc.ServiceServer) *Service {
|
2023-12-27 14:18:15 +00:00
|
|
|
return &Service{
|
|
|
|
apeChecker: apeChecker,
|
|
|
|
next: next,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type getStreamBasicChecker struct {
|
|
|
|
objectSvc.GetObjectStream
|
|
|
|
|
|
|
|
apeChecker Checker
|
|
|
|
|
2024-02-14 11:14:07 +00:00
|
|
|
namespace string
|
|
|
|
|
2023-12-27 14:18:15 +00:00
|
|
|
senderKey []byte
|
|
|
|
|
2024-03-15 12:16:52 +00:00
|
|
|
containerOwner user.ID
|
|
|
|
|
2023-12-27 14:18:15 +00:00
|
|
|
role string
|
2024-02-14 11:14:07 +00:00
|
|
|
|
|
|
|
softAPECheck bool
|
2024-05-29 08:11:45 +00:00
|
|
|
|
|
|
|
bearerToken *bearer.Token
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *getStreamBasicChecker) Send(resp *objectV2.GetResponse) error {
|
|
|
|
if partInit, ok := resp.GetBody().GetObjectPart().(*objectV2.GetObjectPartInit); ok {
|
|
|
|
cnrID, objID, err := getAddressParamsSDK(partInit.GetHeader().GetContainerID(), partInit.GetObjectID())
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prm := Prm{
|
2024-03-15 12:16:52 +00:00
|
|
|
Namespace: g.namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Object: objID,
|
|
|
|
Header: partInit.GetHeader(),
|
|
|
|
Method: nativeschema.MethodGetObject,
|
|
|
|
SenderKey: hex.EncodeToString(g.senderKey),
|
|
|
|
ContainerOwner: g.containerOwner,
|
|
|
|
Role: g.role,
|
|
|
|
SoftAPECheck: g.softAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
BearerToken: g.bearerToken,
|
2024-07-12 09:02:20 +00:00
|
|
|
XHeaders: resp.GetMetaHeader().GetXHeaders(),
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := g.apeChecker.CheckAPE(g.Context(), prm); err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return g.GetObjectStream.Send(resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func requestContext(ctx context.Context) (*objectSvc.RequestContext, error) {
|
|
|
|
untyped := ctx.Value(objectSvc.RequestContextKey)
|
|
|
|
if untyped == nil {
|
|
|
|
return nil, fmt.Errorf("no key %s in context", objectSvc.RequestContextKey)
|
|
|
|
}
|
|
|
|
rc, ok := untyped.(*objectSvc.RequestContext)
|
|
|
|
if !ok {
|
2024-03-11 14:55:50 +00:00
|
|
|
return nil, errFailedToCastToRequestContext
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
return rc, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Service) Get(request *objectV2.GetRequest, stream objectSvc.GetObjectStream) error {
|
|
|
|
reqCtx, err := requestContext(stream.Context())
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c.next.Get(request, &getStreamBasicChecker{
|
|
|
|
GetObjectStream: stream,
|
|
|
|
apeChecker: c.apeChecker,
|
2024-02-14 11:14:07 +00:00
|
|
|
namespace: reqCtx.Namespace,
|
|
|
|
senderKey: reqCtx.SenderKey,
|
2024-07-02 10:02:26 +00:00
|
|
|
containerOwner: reqCtx.ContainerOwner,
|
2024-02-14 11:14:07 +00:00
|
|
|
role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
softAPECheck: reqCtx.SoftAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
bearerToken: reqCtx.BearerToken,
|
2023-12-27 14:18:15 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type putStreamBasicChecker struct {
|
|
|
|
apeChecker Checker
|
|
|
|
|
|
|
|
next objectSvc.PutObjectStream
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *putStreamBasicChecker) Send(ctx context.Context, request *objectV2.PutRequest) error {
|
|
|
|
if partInit, ok := request.GetBody().GetObjectPart().(*objectV2.PutObjectPartInit); ok {
|
|
|
|
reqCtx, err := requestContext(ctx)
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cnrID, objID, err := getAddressParamsSDK(partInit.GetHeader().GetContainerID(), partInit.GetObjectID())
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prm := Prm{
|
2024-03-15 12:16:52 +00:00
|
|
|
Namespace: reqCtx.Namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Object: objID,
|
|
|
|
Header: partInit.GetHeader(),
|
|
|
|
Method: nativeschema.MethodPutObject,
|
|
|
|
SenderKey: hex.EncodeToString(reqCtx.SenderKey),
|
|
|
|
ContainerOwner: reqCtx.ContainerOwner,
|
|
|
|
Role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
SoftAPECheck: reqCtx.SoftAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
BearerToken: reqCtx.BearerToken,
|
2024-07-12 09:02:20 +00:00
|
|
|
XHeaders: request.GetMetaHeader().GetXHeaders(),
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.apeChecker.CheckAPE(ctx, prm); err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.next.Send(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p putStreamBasicChecker) CloseAndRecv(ctx context.Context) (*objectV2.PutResponse, error) {
|
|
|
|
return p.next.CloseAndRecv(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Service) Put() (objectSvc.PutObjectStream, error) {
|
|
|
|
streamer, err := c.next.Put()
|
|
|
|
|
|
|
|
return &putStreamBasicChecker{
|
|
|
|
apeChecker: c.apeChecker,
|
|
|
|
next: streamer,
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:38:01 +00:00
|
|
|
type patchStreamBasicChecker struct {
|
|
|
|
apeChecker Checker
|
|
|
|
|
|
|
|
next objectSvc.PatchObjectStream
|
|
|
|
|
|
|
|
nonFirstSend bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *patchStreamBasicChecker) Send(ctx context.Context, request *objectV2.PatchRequest) error {
|
|
|
|
if !p.nonFirstSend {
|
|
|
|
p.nonFirstSend = true
|
|
|
|
|
|
|
|
reqCtx, err := requestContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return toStatusErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrID, objID, err := getAddressParamsSDK(request.GetBody().GetAddress().GetContainerID(), request.GetBody().GetAddress().GetObjectID())
|
|
|
|
if err != nil {
|
|
|
|
return toStatusErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
prm := Prm{
|
|
|
|
Namespace: reqCtx.Namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Object: objID,
|
|
|
|
Method: nativeschema.MethodPatchObject,
|
|
|
|
SenderKey: hex.EncodeToString(reqCtx.SenderKey),
|
|
|
|
ContainerOwner: reqCtx.ContainerOwner,
|
|
|
|
Role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
SoftAPECheck: reqCtx.SoftAPECheck,
|
|
|
|
BearerToken: reqCtx.BearerToken,
|
|
|
|
XHeaders: request.GetMetaHeader().GetXHeaders(),
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.apeChecker.CheckAPE(ctx, prm); err != nil {
|
|
|
|
return toStatusErr(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.next.Send(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p patchStreamBasicChecker) CloseAndRecv(ctx context.Context) (*objectV2.PatchResponse, error) {
|
|
|
|
return p.next.CloseAndRecv(ctx)
|
|
|
|
}
|
|
|
|
|
2024-08-12 14:11:10 +00:00
|
|
|
func (c *Service) Patch() (objectSvc.PatchObjectStream, error) {
|
2024-08-14 11:38:01 +00:00
|
|
|
streamer, err := c.next.Patch()
|
|
|
|
|
|
|
|
return &patchStreamBasicChecker{
|
|
|
|
apeChecker: c.apeChecker,
|
|
|
|
next: streamer,
|
|
|
|
}, err
|
2024-08-12 10:01:57 +00:00
|
|
|
}
|
|
|
|
|
2023-12-27 14:18:15 +00:00
|
|
|
func (c *Service) Head(ctx context.Context, request *objectV2.HeadRequest) (*objectV2.HeadResponse, error) {
|
|
|
|
cnrID, objID, err := getAddressParamsSDK(request.GetBody().GetAddress().GetContainerID(), request.GetBody().GetAddress().GetObjectID())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
reqCtx, err := requestContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := c.next.Head(ctx, request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
header := new(objectV2.Header)
|
|
|
|
switch headerPart := resp.GetBody().GetHeaderPart().(type) {
|
|
|
|
case *objectV2.ShortHeader:
|
|
|
|
cidV2 := new(refs.ContainerID)
|
|
|
|
cnrID.WriteToV2(cidV2)
|
|
|
|
header.SetContainerID(cidV2)
|
|
|
|
header.SetVersion(headerPart.GetVersion())
|
|
|
|
header.SetCreationEpoch(headerPart.GetCreationEpoch())
|
|
|
|
header.SetOwnerID(headerPart.GetOwnerID())
|
|
|
|
header.SetObjectType(headerPart.GetObjectType())
|
|
|
|
header.SetHomomorphicHash(header.GetHomomorphicHash())
|
|
|
|
header.SetPayloadLength(headerPart.GetPayloadLength())
|
|
|
|
header.SetPayloadHash(headerPart.GetPayloadHash())
|
|
|
|
case *objectV2.HeaderWithSignature:
|
|
|
|
header = headerPart.GetHeader()
|
|
|
|
default:
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err = c.apeChecker.CheckAPE(ctx, Prm{
|
2024-03-15 12:16:52 +00:00
|
|
|
Namespace: reqCtx.Namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Object: objID,
|
|
|
|
Header: header,
|
|
|
|
Method: nativeschema.MethodHeadObject,
|
|
|
|
Role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
SenderKey: hex.EncodeToString(reqCtx.SenderKey),
|
|
|
|
ContainerOwner: reqCtx.ContainerOwner,
|
|
|
|
SoftAPECheck: reqCtx.SoftAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
BearerToken: reqCtx.BearerToken,
|
2024-07-12 09:02:20 +00:00
|
|
|
XHeaders: request.GetMetaHeader().GetXHeaders(),
|
2023-12-27 14:18:15 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-03-12 14:08:09 +00:00
|
|
|
return nil, toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Service) Search(request *objectV2.SearchRequest, stream objectSvc.SearchStream) error {
|
|
|
|
var cnrID cid.ID
|
|
|
|
if cnrV2 := request.GetBody().GetContainerID(); cnrV2 != nil {
|
|
|
|
if err := cnrID.ReadFromV2(*cnrV2); err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reqCtx, err := requestContext(stream.Context())
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.apeChecker.CheckAPE(stream.Context(), Prm{
|
2024-03-15 12:16:52 +00:00
|
|
|
Namespace: reqCtx.Namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Method: nativeschema.MethodSearchObject,
|
|
|
|
Role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
SenderKey: hex.EncodeToString(reqCtx.SenderKey),
|
|
|
|
ContainerOwner: reqCtx.ContainerOwner,
|
|
|
|
SoftAPECheck: reqCtx.SoftAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
BearerToken: reqCtx.BearerToken,
|
2024-07-12 09:02:20 +00:00
|
|
|
XHeaders: request.GetMetaHeader().GetXHeaders(),
|
2023-12-27 14:18:15 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c.next.Search(request, stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Service) Delete(ctx context.Context, request *objectV2.DeleteRequest) (*objectV2.DeleteResponse, error) {
|
|
|
|
cnrID, objID, err := getAddressParamsSDK(request.GetBody().GetAddress().GetContainerID(), request.GetBody().GetAddress().GetObjectID())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
reqCtx, err := requestContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = c.apeChecker.CheckAPE(ctx, Prm{
|
2024-03-15 12:16:52 +00:00
|
|
|
Namespace: reqCtx.Namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Object: objID,
|
|
|
|
Method: nativeschema.MethodDeleteObject,
|
|
|
|
Role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
SenderKey: hex.EncodeToString(reqCtx.SenderKey),
|
|
|
|
ContainerOwner: reqCtx.ContainerOwner,
|
|
|
|
SoftAPECheck: reqCtx.SoftAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
BearerToken: reqCtx.BearerToken,
|
2024-07-12 09:02:20 +00:00
|
|
|
XHeaders: request.GetMetaHeader().GetXHeaders(),
|
2023-12-27 14:18:15 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-03-12 14:08:09 +00:00
|
|
|
return nil, toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := c.next.Delete(ctx, request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Service) GetRange(request *objectV2.GetRangeRequest, stream objectSvc.GetObjectRangeStream) error {
|
|
|
|
cnrID, objID, err := getAddressParamsSDK(request.GetBody().GetAddress().GetContainerID(), request.GetBody().GetAddress().GetObjectID())
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reqCtx, err := requestContext(stream.Context())
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.apeChecker.CheckAPE(stream.Context(), Prm{
|
2024-03-15 12:16:52 +00:00
|
|
|
Namespace: reqCtx.Namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Object: objID,
|
|
|
|
Method: nativeschema.MethodRangeObject,
|
|
|
|
Role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
SenderKey: hex.EncodeToString(reqCtx.SenderKey),
|
|
|
|
ContainerOwner: reqCtx.ContainerOwner,
|
|
|
|
SoftAPECheck: reqCtx.SoftAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
BearerToken: reqCtx.BearerToken,
|
2024-07-12 09:02:20 +00:00
|
|
|
XHeaders: request.GetMetaHeader().GetXHeaders(),
|
2023-12-27 14:18:15 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c.next.GetRange(request, stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Service) GetRangeHash(ctx context.Context, request *objectV2.GetRangeHashRequest) (*objectV2.GetRangeHashResponse, error) {
|
|
|
|
cnrID, objID, err := getAddressParamsSDK(request.GetBody().GetAddress().GetContainerID(), request.GetBody().GetAddress().GetObjectID())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
reqCtx, err := requestContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
prm := Prm{
|
2024-03-15 12:16:52 +00:00
|
|
|
Namespace: reqCtx.Namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Object: objID,
|
|
|
|
Method: nativeschema.MethodHashObject,
|
|
|
|
Role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
SenderKey: hex.EncodeToString(reqCtx.SenderKey),
|
|
|
|
ContainerOwner: reqCtx.ContainerOwner,
|
|
|
|
SoftAPECheck: reqCtx.SoftAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
BearerToken: reqCtx.BearerToken,
|
2024-07-12 09:02:20 +00:00
|
|
|
XHeaders: request.GetMetaHeader().GetXHeaders(),
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := c.next.GetRangeHash(ctx, request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = c.apeChecker.CheckAPE(ctx, prm); err != nil {
|
2024-03-12 14:08:09 +00:00
|
|
|
return nil, toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Service) PutSingle(ctx context.Context, request *objectV2.PutSingleRequest) (*objectV2.PutSingleResponse, error) {
|
|
|
|
cnrID, objID, err := getAddressParamsSDK(request.GetBody().GetObject().GetHeader().GetContainerID(), request.GetBody().GetObject().GetObjectID())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
reqCtx, err := requestContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
prm := Prm{
|
2024-03-15 12:16:52 +00:00
|
|
|
Namespace: reqCtx.Namespace,
|
|
|
|
Container: cnrID,
|
|
|
|
Object: objID,
|
|
|
|
Header: request.GetBody().GetObject().GetHeader(),
|
|
|
|
Method: nativeschema.MethodPutObject,
|
|
|
|
Role: nativeSchemaRole(reqCtx.Role),
|
|
|
|
SenderKey: hex.EncodeToString(reqCtx.SenderKey),
|
|
|
|
ContainerOwner: reqCtx.ContainerOwner,
|
|
|
|
SoftAPECheck: reqCtx.SoftAPECheck,
|
2024-05-29 08:11:45 +00:00
|
|
|
BearerToken: reqCtx.BearerToken,
|
2024-07-12 09:02:20 +00:00
|
|
|
XHeaders: request.GetMetaHeader().GetXHeaders(),
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = c.apeChecker.CheckAPE(ctx, prm); err != nil {
|
2024-01-18 11:35:52 +00:00
|
|
|
return nil, toStatusErr(err)
|
2023-12-27 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c.next.PutSingle(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getAddressParamsSDK(cidV2 *refs.ContainerID, objV2 *refs.ObjectID) (cnrID cid.ID, objID *oid.ID, err error) {
|
|
|
|
if cidV2 != nil {
|
|
|
|
if err = cnrID.ReadFromV2(*cidV2); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if objV2 != nil {
|
|
|
|
objID = new(oid.ID)
|
|
|
|
if err = objID.ReadFromV2(*objV2); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|