[#174] Add slash clipping for FileName attribute
According to the FrostFS API specification, the FileName attribute cannot contain a slash at the beginning. Signed-off-by: Roman Loginov <r.loginov@yadro.com>
This commit is contained in:
parent
20319418cc
commit
47d74a5a77
3 changed files with 44 additions and 3 deletions
|
@ -253,6 +253,10 @@ func (h *Handler) byAttribute(c *fasthttp.RequestCtx, handler func(context.Conte
|
|||
return
|
||||
}
|
||||
|
||||
if key == attrFileName {
|
||||
val = prepareFileName(val)
|
||||
}
|
||||
|
||||
log = log.With(zap.String("cid", cidParam), zap.String("attr_key", key), zap.String("attr_val", val))
|
||||
|
||||
bktInfo, err := h.getBucketInfo(ctx, cidParam, log)
|
||||
|
@ -294,7 +298,7 @@ func (h *Handler) findObjectByAttribute(ctx context.Context, log *zap.Logger, cn
|
|||
switch {
|
||||
case errors.Is(err, io.EOF) && h.needSearchByFileName(attrKey, attrVal):
|
||||
log.Debug(logs.ObjectNotFoundByFilePathTrySearchByFileName, logs.TagField(logs.TagExternalStorage))
|
||||
return h.findObjectByAttribute(ctx, log, cnrID, attrFileName, attrVal)
|
||||
return h.findObjectByAttribute(ctx, log, cnrID, attrFileName, prepareFileName(attrVal))
|
||||
case errors.Is(err, io.EOF):
|
||||
log.Error(logs.ObjectNotFound, zap.Error(err), logs.TagField(logs.TagExternalStorage))
|
||||
return oid.ID{}, fmt.Errorf("object not found: %w", err)
|
||||
|
@ -315,6 +319,14 @@ func (h *Handler) needSearchByFileName(key, val string) bool {
|
|||
return strings.HasPrefix(val, "/") && strings.Count(val, "/") == 1 || !strings.Contains(val, "/")
|
||||
}
|
||||
|
||||
func prepareFileName(fileName string) string {
|
||||
if strings.HasPrefix(fileName, "/") {
|
||||
return fileName[1:]
|
||||
}
|
||||
|
||||
return fileName
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue