From f9ef94a8dd176b390e2965bf26670e1ec01c80b6 Mon Sep 17 00:00:00 2001 From: Tigran Mkrtchyan Date: Mon, 12 Feb 2024 09:27:26 +0100 Subject: [PATCH] tape-api: map request supplied paths based on frontend.root Motivation: ArchiveInfo request contains paths like: ``` paths: [ "/file1", "/file1", "/file3" ] ``` Those paths are relative to frontend.root, so, should be mapped before processed by rest of the dCache. Modification: map request supplied paths based on frontend.root. Strip the prefix when generating reply. Result: ArchiveInfoResources respects frondend.root Fixes: #7506 Acked-by: Marina Sahakyan Target: master, 9.2 Require-book: no Require-notes: yes (cherry picked from commit d78a4805ed1be864fc731a6aaefe024f7c70b3d8) Signed-off-by: Tigran Mkrtchyan --- .../resources/tape/ArchiveInfoResources.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/ArchiveInfoResources.java b/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/ArchiveInfoResources.java index 3cabfd53c45..718c871a58b 100644 --- a/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/ArchiveInfoResources.java +++ b/modules/dcache-frontend/src/main/java/org/dcache/restful/resources/tape/ArchiveInfoResources.java @@ -59,8 +59,10 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ package org.dcache.restful.resources.tape; +import static org.dcache.http.AuthenticationHandler.getLoginAttributes; import static org.dcache.restful.util.JSONUtils.newBadRequestException; +import diskCacheV111.util.FsPath; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -74,12 +76,16 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING import javax.servlet.http.HttpServletRequest; import javax.ws.rs.BadRequestException; import javax.ws.rs.Consumes; +import javax.ws.rs.ForbiddenException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; + +import org.dcache.auth.attributes.LoginAttributes; import org.dcache.cells.CellStub; +import org.dcache.http.PathMapper; import org.dcache.restful.providers.tape.ArchiveInfo; import org.dcache.restful.util.HandlerBuilders; import org.dcache.restful.util.wlcg.ArchiveInfoCollector; @@ -108,6 +114,10 @@ public final class ArchiveInfoResources { @Inject private ArchiveInfoCollector archiveInfoCollector; + @Inject + private PathMapper pathMapper; + + /** * Return the file locality information for a list of file paths. *

@@ -134,6 +144,8 @@ public List getArchiveInfo( String requestPayload) { List paths; + FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request)); + FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new); try { JSONObject jsonPayload = new JSONObject(requestPayload); @@ -147,13 +159,20 @@ public List getArchiveInfo( paths = new ArrayList<>(); for (int i = 0; i < len; ++i) { - paths.add(jsonArray.getString(i)); + String requestedPath = jsonArray.getString(i); + String dcachePath = rootPath.chroot(requestedPath).toString(); + paths.add(dcachePath); } } catch (JSONException e) { throw newBadRequestException(requestPayload, e); } - return archiveInfoCollector.getInfo(HandlerBuilders.roleAwarePnfsHandler(pnfsManager), + var archiveInfos = archiveInfoCollector.getInfo(HandlerBuilders.roleAwarePnfsHandler(pnfsManager), paths); + + archiveInfos.forEach(ai -> + ai.setPath(FsPath.create(ai.getPath()).stripPrefix(rootPath))); + + return archiveInfos; } }