2023-08-31 11:37:03 +03:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2023-10-04 14:50:37 +03:00
|
|
|
"fmt"
|
2023-08-31 11:37:03 +03:00
|
|
|
"io"
|
|
|
|
"net/url"
|
2023-10-04 14:50:37 +03:00
|
|
|
"strings"
|
2023-08-31 11:37:03 +03:00
|
|
|
|
2023-10-04 14:50:37 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/cache"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/data"
|
2023-11-28 11:29:08 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/handler/middleware"
|
2024-12-02 11:45:30 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/layer"
|
2023-08-31 11:37:03 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/utils"
|
2024-11-28 05:48:14 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/tracing"
|
2024-06-17 17:56:43 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
2023-10-04 14:50:37 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
2023-08-31 11:37:03 +03:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2024-10-10 11:59:53 +03:00
|
|
|
"github.com/panjf2000/ants/v2"
|
2023-08-31 11:37:03 +03:00
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2023-09-05 18:17:22 +03:00
|
|
|
type Config interface {
|
|
|
|
DefaultTimestamp() bool
|
2024-12-06 15:01:16 +03:00
|
|
|
ArchiveCompression() bool
|
2023-08-21 16:50:23 +03:00
|
|
|
ClientCut() bool
|
2024-09-26 17:32:27 +03:00
|
|
|
IndexPageEnabled() bool
|
|
|
|
IndexPageTemplate() string
|
2023-08-25 14:53:59 +03:00
|
|
|
BufferMaxSizeForPut() uint64
|
2023-11-28 11:29:08 +03:00
|
|
|
NamespaceHeader() string
|
2024-12-12 09:28:22 +03:00
|
|
|
EnableFilepathFallback() bool
|
2023-09-05 18:17:22 +03:00
|
|
|
}
|
|
|
|
|
2024-06-17 17:56:43 +03:00
|
|
|
// PrmContainer groups parameters of FrostFS.Container operation.
|
|
|
|
type PrmContainer struct {
|
|
|
|
// Container identifier.
|
|
|
|
ContainerID cid.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmAuth groups authentication parameters for the FrostFS operation.
|
|
|
|
type PrmAuth struct {
|
|
|
|
// Bearer token to be used for the operation. Overlaps PrivateKey. Optional.
|
|
|
|
BearerToken *bearer.Token
|
|
|
|
}
|
|
|
|
|
2024-07-15 16:35:08 +03:00
|
|
|
// PrmObjectHead groups parameters of FrostFS.HeadObject operation.
|
|
|
|
type PrmObjectHead struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Address to read the object header from.
|
|
|
|
Address oid.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectGet groups parameters of FrostFS.GetObject operation.
|
|
|
|
type PrmObjectGet struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Address to read the object header from.
|
|
|
|
Address oid.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectRange groups parameters of FrostFS.RangeObject operation.
|
|
|
|
type PrmObjectRange struct {
|
2024-06-17 17:56:43 +03:00
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Address to read the object header from.
|
|
|
|
Address oid.Address
|
|
|
|
|
|
|
|
// Offset-length range of the object payload to be read.
|
|
|
|
PayloadRange [2]uint64
|
|
|
|
}
|
|
|
|
|
2024-07-15 16:35:08 +03:00
|
|
|
// Object represents FrostFS object.
|
|
|
|
type Object struct {
|
|
|
|
// Object header (doesn't contain payload).
|
|
|
|
Header object.Object
|
2024-06-17 17:56:43 +03:00
|
|
|
|
|
|
|
// Object payload part encapsulated in io.Reader primitive.
|
|
|
|
// Returns ErrAccessDenied on read access violation.
|
|
|
|
Payload io.ReadCloser
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectCreate groups parameters of FrostFS.CreateObject operation.
|
|
|
|
type PrmObjectCreate struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
Object *object.Object
|
|
|
|
|
|
|
|
// Object payload encapsulated in io.Reader primitive.
|
|
|
|
Payload io.Reader
|
|
|
|
|
|
|
|
// Enables client side object preparing.
|
|
|
|
ClientCut bool
|
|
|
|
|
|
|
|
// Disables using Tillich-Zémor hash for payload.
|
|
|
|
WithoutHomomorphicHash bool
|
|
|
|
|
|
|
|
// Sets max buffer size to read payload.
|
|
|
|
BufferMaxSize uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectSearch groups parameters of FrostFS.sear SearchObjects operation.
|
|
|
|
type PrmObjectSearch struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Container to select the objects from.
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
Filters object.SearchFilters
|
|
|
|
}
|
|
|
|
|
2024-09-18 07:35:26 +03:00
|
|
|
type PrmInitMultiObjectReader struct {
|
|
|
|
// payload range
|
|
|
|
Off, Ln uint64
|
|
|
|
|
|
|
|
Addr oid.Address
|
|
|
|
Bearer *bearer.Token
|
|
|
|
}
|
|
|
|
|
2024-06-17 17:56:43 +03:00
|
|
|
type ResObjectSearch interface {
|
|
|
|
Read(buf []oid.ID) (int, error)
|
|
|
|
Iterate(f func(oid.ID) bool) error
|
|
|
|
Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrAccessDenied is returned from FrostFS in case of access violation.
|
|
|
|
ErrAccessDenied = errors.New("access denied")
|
|
|
|
// ErrGatewayTimeout is returned from FrostFS in case of timeout, deadline exceeded etc.
|
|
|
|
ErrGatewayTimeout = errors.New("gateway timeout")
|
2025-01-09 12:28:38 +03:00
|
|
|
// ErrQuotaLimitReached is returned from FrostFS in case of quota exceeded.
|
|
|
|
ErrQuotaLimitReached = errors.New("quota limit reached")
|
2025-03-03 18:06:41 +03:00
|
|
|
// ErrContainerNotFound is returned from FrostFS in case of container was not found.
|
|
|
|
ErrContainerNotFound = errors.New("container not found")
|
|
|
|
// ErrObjectNotFound is returned from FrostFS in case of object was not found.
|
|
|
|
ErrObjectNotFound = errors.New("object not found")
|
2024-06-17 17:56:43 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// FrostFS represents virtual connection to FrostFS network.
|
|
|
|
type FrostFS interface {
|
|
|
|
Container(context.Context, PrmContainer) (*container.Container, error)
|
2024-07-15 16:35:08 +03:00
|
|
|
HeadObject(context.Context, PrmObjectHead) (*object.Object, error)
|
|
|
|
GetObject(context.Context, PrmObjectGet) (*Object, error)
|
|
|
|
RangeObject(context.Context, PrmObjectRange) (io.ReadCloser, error)
|
2024-06-17 17:56:43 +03:00
|
|
|
CreateObject(context.Context, PrmObjectCreate) (oid.ID, error)
|
|
|
|
SearchObjects(context.Context, PrmObjectSearch) (ResObjectSearch, error)
|
2024-09-18 07:35:26 +03:00
|
|
|
InitMultiObjectReader(ctx context.Context, p PrmInitMultiObjectReader) (io.Reader, error)
|
|
|
|
|
2024-06-17 17:56:43 +03:00
|
|
|
utils.EpochInfoFetcher
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContainerResolver interface {
|
|
|
|
Resolve(ctx context.Context, name string) (*cid.ID, error)
|
|
|
|
}
|
|
|
|
|
2023-08-31 11:37:03 +03:00
|
|
|
type Handler struct {
|
|
|
|
log *zap.Logger
|
2024-06-17 17:56:43 +03:00
|
|
|
frostfs FrostFS
|
2023-08-31 11:37:03 +03:00
|
|
|
ownerID *user.ID
|
2023-09-05 18:17:22 +03:00
|
|
|
config Config
|
2024-06-17 17:56:43 +03:00
|
|
|
containerResolver ContainerResolver
|
2024-12-02 11:45:30 +03:00
|
|
|
tree layer.TreeService
|
2023-10-04 14:50:37 +03:00
|
|
|
cache *cache.BucketCache
|
2024-10-10 11:59:53 +03:00
|
|
|
workerPool *ants.Pool
|
2023-08-31 11:37:03 +03:00
|
|
|
}
|
|
|
|
|
2024-06-17 17:56:43 +03:00
|
|
|
type AppParams struct {
|
|
|
|
Logger *zap.Logger
|
|
|
|
FrostFS FrostFS
|
|
|
|
Owner *user.ID
|
|
|
|
Resolver ContainerResolver
|
|
|
|
Cache *cache.BucketCache
|
|
|
|
}
|
|
|
|
|
2024-12-02 11:45:30 +03:00
|
|
|
func New(params *AppParams, config Config, tree layer.TreeService, workerPool *ants.Pool) *Handler {
|
2023-08-31 11:37:03 +03:00
|
|
|
return &Handler{
|
|
|
|
log: params.Logger,
|
2024-06-17 17:56:43 +03:00
|
|
|
frostfs: params.FrostFS,
|
2023-08-31 11:37:03 +03:00
|
|
|
ownerID: params.Owner,
|
2023-09-05 18:17:22 +03:00
|
|
|
config: config,
|
2023-08-31 11:37:03 +03:00
|
|
|
containerResolver: params.Resolver,
|
|
|
|
tree: tree,
|
2023-10-04 14:50:37 +03:00
|
|
|
cache: params.Cache,
|
2024-10-10 11:59:53 +03:00
|
|
|
workerPool: workerPool,
|
2023-08-31 11:37:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-10 11:59:53 +03:00
|
|
|
// byNativeAddress is a wrapper for function (e.g. request.headObject, request.receiveFile) that
|
2023-08-31 11:37:03 +03:00
|
|
|
// prepares request and object address to it.
|
2025-03-03 18:06:41 +03:00
|
|
|
func (h *Handler) byNativeAddress(ctx context.Context, req *fasthttp.RequestCtx, cnrID cid.ID, objID oid.ID, handler func(context.Context, *fasthttp.RequestCtx, oid.Address)) {
|
2024-11-28 05:48:14 +03:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "handler.byNativeAddress")
|
|
|
|
defer span.End()
|
|
|
|
|
2024-12-02 11:45:30 +03:00
|
|
|
addr := newAddress(cnrID, objID)
|
|
|
|
handler(ctx, req, addr)
|
2023-08-31 11:37:03 +03:00
|
|
|
}
|
|
|
|
|
2024-10-10 11:59:53 +03:00
|
|
|
// byS3Path is a wrapper for function (e.g. request.headObject, request.receiveFile) that
|
|
|
|
// resolves object address from S3-like path <bucket name>/<object key>.
|
2025-03-03 18:06:41 +03:00
|
|
|
func (h *Handler) byS3Path(ctx context.Context, req *fasthttp.RequestCtx, cnrID cid.ID, path string, handler func(context.Context, *fasthttp.RequestCtx, oid.Address)) {
|
2024-11-28 05:48:14 +03:00
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "handler.byS3Path")
|
|
|
|
defer span.End()
|
|
|
|
|
2024-12-02 11:45:30 +03:00
|
|
|
foundOID, err := h.tree.GetLatestVersion(ctx, &cnrID, path)
|
2023-08-31 11:37:03 +03:00
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
h.logAndSendError(ctx, req, logs.FailedToGetLatestVersionOfObject, err, zap.String("path", path))
|
2023-08-31 11:37:03 +03:00
|
|
|
return
|
|
|
|
}
|
2024-12-02 11:45:30 +03:00
|
|
|
if foundOID.IsDeleteMarker {
|
2025-03-03 18:06:41 +03:00
|
|
|
h.logAndSendError(ctx, req, logs.ObjectWasDeleted, ErrObjectNotFound)
|
2023-08-31 11:37:03 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-12-02 11:45:30 +03:00
|
|
|
addr := newAddress(cnrID, foundOID.OID)
|
2025-03-03 18:06:41 +03:00
|
|
|
handler(ctx, req, addr)
|
2023-08-31 11:37:03 +03:00
|
|
|
}
|
|
|
|
|
2024-10-10 11:59:53 +03:00
|
|
|
// byAttribute is a wrapper similar to byNativeAddress.
|
2025-03-03 18:06:41 +03:00
|
|
|
func (h *Handler) byAttribute(ctx context.Context, req *fasthttp.RequestCtx, handler func(context.Context, *fasthttp.RequestCtx, oid.Address)) {
|
|
|
|
cidParam, _ := req.UserValue("cid").(string)
|
|
|
|
key, _ := req.UserValue("attr_key").(string)
|
|
|
|
val, _ := req.UserValue("attr_val").(string)
|
2024-10-08 12:08:39 +03:00
|
|
|
|
2024-02-29 12:50:56 +03:00
|
|
|
key, err := url.QueryUnescape(key)
|
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
h.logAndSendError(ctx, req, logs.FailedToUnescapeQuery, err, zap.String("cid", cidParam), zap.String("attr_key", key))
|
2024-02-29 12:50:56 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
val, err = url.QueryUnescape(val)
|
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
h.logAndSendError(ctx, req, logs.FailedToUnescapeQuery, err, zap.String("cid", cidParam), zap.String("attr_val", key))
|
2024-02-29 12:50:56 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-02-09 21:48:32 +03:00
|
|
|
val = prepareAtribute(key, val)
|
2025-02-04 13:21:57 +03:00
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
ctx = utils.SetReqLog(ctx, h.reqLogger(ctx).With(zap.String("cid", cidParam),
|
|
|
|
zap.String("attr_key", key), zap.String("attr_val", val)))
|
2023-08-31 11:37:03 +03:00
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
bktInfo, err := h.getBucketInfo(ctx, cidParam)
|
2023-08-31 11:37:03 +03:00
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
h.logAndSendError(ctx, req, logs.FailedToGetBucketInfo, err)
|
2023-08-31 11:37:03 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
objID, err := h.findObjectByAttribute(ctx, bktInfo.CID, key, val)
|
2023-08-31 11:37:03 +03:00
|
|
|
if err != nil {
|
2024-12-12 09:28:22 +03:00
|
|
|
if errors.Is(err, io.EOF) {
|
2025-03-03 18:06:41 +03:00
|
|
|
err = fmt.Errorf("%w: %s", ErrObjectNotFound, err.Error())
|
2024-12-12 09:28:22 +03:00
|
|
|
}
|
2025-03-03 18:06:41 +03:00
|
|
|
h.logAndSendError(ctx, req, logs.FailedToFindObjectByAttribute, err)
|
2023-08-31 11:37:03 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-12-02 11:45:30 +03:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(bktInfo.CID)
|
|
|
|
addr.SetObject(objID)
|
2024-12-12 09:28:22 +03:00
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
handler(ctx, req, addr)
|
2024-12-12 09:28:22 +03:00
|
|
|
}
|
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
func (h *Handler) findObjectByAttribute(ctx context.Context, cnrID cid.ID, attrKey, attrVal string) (oid.ID, error) {
|
2024-12-12 09:28:22 +03:00
|
|
|
res, err := h.search(ctx, cnrID, attrKey, attrVal, object.MatchStringEqual)
|
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
return oid.ID{}, fmt.Errorf("search objects: %w", err)
|
2024-12-12 09:28:22 +03:00
|
|
|
}
|
2023-08-31 11:37:03 +03:00
|
|
|
defer res.Close()
|
|
|
|
|
|
|
|
buf := make([]oid.ID, 1)
|
|
|
|
|
|
|
|
n, err := res.Read(buf)
|
|
|
|
if n == 0 {
|
2024-12-12 09:28:22 +03:00
|
|
|
switch {
|
|
|
|
case errors.Is(err, io.EOF) && h.needSearchByFileName(attrKey, attrVal):
|
2025-03-03 18:06:41 +03:00
|
|
|
h.reqLogger(ctx).Debug(logs.ObjectNotFoundByFilePathTrySearchByFileName, logs.TagField(logs.TagExternalStorage))
|
2025-02-09 21:48:32 +03:00
|
|
|
attrVal = prepareAtribute(attrFileName, attrVal)
|
2025-03-03 18:06:41 +03:00
|
|
|
return h.findObjectByAttribute(ctx, cnrID, attrFileName, attrVal)
|
2024-12-12 09:28:22 +03:00
|
|
|
case errors.Is(err, io.EOF):
|
2025-03-03 18:06:41 +03:00
|
|
|
h.reqLogger(ctx).Error(logs.ObjectNotFound, zap.Error(err), logs.TagField(logs.TagExternalStorage))
|
2024-12-12 09:28:22 +03:00
|
|
|
return oid.ID{}, fmt.Errorf("object not found: %w", err)
|
|
|
|
default:
|
2025-03-03 18:06:41 +03:00
|
|
|
h.reqLogger(ctx).Error(logs.ReadObjectListFailed, zap.Error(err), logs.TagField(logs.TagExternalStorage))
|
2024-12-12 09:28:22 +03:00
|
|
|
return oid.ID{}, fmt.Errorf("read object list failed: %w", err)
|
2023-08-31 11:37:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-12 09:28:22 +03:00
|
|
|
return buf[0], nil
|
|
|
|
}
|
2023-08-31 11:37:03 +03:00
|
|
|
|
2024-12-12 09:28:22 +03:00
|
|
|
func (h *Handler) needSearchByFileName(key, val string) bool {
|
|
|
|
if key != attrFilePath || !h.config.EnableFilepathFallback() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.HasPrefix(val, "/") && strings.Count(val, "/") == 1 || !strings.Contains(val, "/")
|
2023-08-31 11:37:03 +03:00
|
|
|
}
|
2023-10-04 14:50:37 +03:00
|
|
|
|
2025-02-09 21:48:32 +03:00
|
|
|
func prepareAtribute(attrKey, attrVal string) string {
|
|
|
|
if attrKey == attrFileName {
|
|
|
|
return prepareFileName(attrVal)
|
|
|
|
}
|
|
|
|
|
|
|
|
if attrKey == attrFilePath {
|
|
|
|
return prepareFilePath(attrVal)
|
|
|
|
}
|
|
|
|
|
|
|
|
return attrVal
|
|
|
|
}
|
|
|
|
|
2025-02-04 13:21:57 +03:00
|
|
|
func prepareFileName(fileName string) string {
|
|
|
|
if strings.HasPrefix(fileName, "/") {
|
|
|
|
return fileName[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
return fileName
|
|
|
|
}
|
|
|
|
|
2025-02-09 21:48:32 +03:00
|
|
|
func prepareFilePath(filePath string) string {
|
|
|
|
if !strings.HasPrefix(filePath, "/") {
|
|
|
|
return "/" + filePath
|
|
|
|
}
|
|
|
|
|
|
|
|
return filePath
|
|
|
|
}
|
|
|
|
|
2023-10-04 14:50:37 +03:00
|
|
|
// resolveContainer decode container id, if it's not a valid container id
|
|
|
|
// then trey to resolve name using provided resolver.
|
|
|
|
func (h *Handler) resolveContainer(ctx context.Context, containerID string) (*cid.ID, error) {
|
|
|
|
cnrID := new(cid.ID)
|
|
|
|
err := cnrID.DecodeString(containerID)
|
|
|
|
if err != nil {
|
|
|
|
cnrID, err = h.containerResolver.Resolve(ctx, containerID)
|
|
|
|
if err != nil && strings.Contains(err.Error(), "not found") {
|
2025-03-03 18:06:41 +03:00
|
|
|
err = fmt.Errorf("%w: %s", ErrContainerNotFound, err.Error())
|
2023-10-04 14:50:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return cnrID, err
|
|
|
|
}
|
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
func (h *Handler) getBucketInfo(ctx context.Context, containerName string) (*data.BucketInfo, error) {
|
2023-11-28 11:29:08 +03:00
|
|
|
ns, err := middleware.GetNamespace(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if bktInfo := h.cache.Get(ns, containerName); bktInfo != nil {
|
2023-10-04 14:50:37 +03:00
|
|
|
return bktInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cnrID, err := h.resolveContainer(ctx, containerName)
|
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
return nil, fmt.Errorf("resolve container: %w", err)
|
2023-10-04 14:50:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bktInfo, err := h.readContainer(ctx, *cnrID)
|
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
return nil, fmt.Errorf("read container: %w", err)
|
2023-10-04 14:50:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if err = h.cache.Put(bktInfo); err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
h.reqLogger(ctx).Warn(logs.CouldntPutBucketIntoCache,
|
2023-10-04 14:50:37 +03:00
|
|
|
zap.String("bucket name", bktInfo.Name),
|
|
|
|
zap.Stringer("bucket cid", bktInfo.CID),
|
2025-01-28 14:42:40 +03:00
|
|
|
zap.Error(err),
|
|
|
|
logs.TagField(logs.TagDatapath))
|
2023-10-04 14:50:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return bktInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handler) readContainer(ctx context.Context, cnrID cid.ID) (*data.BucketInfo, error) {
|
2024-06-17 17:56:43 +03:00
|
|
|
prm := PrmContainer{ContainerID: cnrID}
|
|
|
|
res, err := h.frostfs.Container(ctx, prm)
|
2023-10-04 14:50:37 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("get frostfs container '%s': %w", cnrID.String(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bktInfo := &data.BucketInfo{
|
|
|
|
CID: cnrID,
|
|
|
|
Name: cnrID.EncodeToString(),
|
|
|
|
}
|
|
|
|
|
2024-06-17 17:56:43 +03:00
|
|
|
if domain := container.ReadDomain(*res); domain.Name() != "" {
|
2023-10-04 14:50:37 +03:00
|
|
|
bktInfo.Name = domain.Name()
|
|
|
|
bktInfo.Zone = domain.Zone()
|
|
|
|
}
|
|
|
|
|
2024-06-17 17:56:43 +03:00
|
|
|
bktInfo.HomomorphicHashDisabled = container.IsHomomorphicHashingDisabled(*res)
|
2024-12-20 09:45:42 +03:00
|
|
|
bktInfo.PlacementPolicy = res.PlacementPolicy()
|
2023-10-04 14:50:37 +03:00
|
|
|
|
|
|
|
return bktInfo, err
|
|
|
|
}
|
2024-09-26 17:32:27 +03:00
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
func (h *Handler) browseIndex(ctx context.Context, req *fasthttp.RequestCtx, cidParam, oidParam string, isNativeList bool) {
|
|
|
|
ctx, span := tracing.StartSpanFromContext(ctx, "handler.browseIndex")
|
2024-11-28 05:48:14 +03:00
|
|
|
defer span.End()
|
|
|
|
|
2024-10-10 11:59:53 +03:00
|
|
|
if !h.config.IndexPageEnabled() {
|
2025-03-03 18:06:41 +03:00
|
|
|
req.SetStatusCode(fasthttp.StatusNotFound)
|
2024-10-10 11:59:53 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
unescapedKey, err := url.QueryUnescape(oidParam)
|
2024-09-26 17:32:27 +03:00
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
h.logAndSendError(ctx, req, logs.FailedToUnescapeOIDParam, err)
|
2024-10-10 11:59:53 +03:00
|
|
|
return
|
2024-09-26 17:32:27 +03:00
|
|
|
}
|
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
bktInfo, err := h.getBucketInfo(ctx, cidParam)
|
2024-10-10 11:59:53 +03:00
|
|
|
if err != nil {
|
2025-03-03 18:06:41 +03:00
|
|
|
h.logAndSendError(ctx, req, logs.FailedToGetBucketInfo, err)
|
2024-10-10 11:59:53 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
listFunc := h.getDirObjectsS3
|
2024-12-02 11:45:30 +03:00
|
|
|
if isNativeList {
|
|
|
|
// tree probe failed, trying to use native
|
|
|
|
listFunc = h.getDirObjectsNative
|
2024-09-26 17:32:27 +03:00
|
|
|
}
|
|
|
|
|
2025-03-03 18:06:41 +03:00
|
|
|
h.browseObjects(ctx, req, browseParams{
|
2024-10-10 11:59:53 +03:00
|
|
|
bucketInfo: bktInfo,
|
|
|
|
prefix: unescapedKey,
|
|
|
|
listObjects: listFunc,
|
|
|
|
isNative: isNativeList,
|
|
|
|
})
|
2024-09-26 17:32:27 +03:00
|
|
|
}
|