Skip to content

Commit

Permalink
tape-api: map request supplied paths based on frontend.root
Browse files Browse the repository at this point in the history
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 d78a480)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  • Loading branch information
kofemann authored and mksahakyan committed Mar 1, 2024
1 parent 2c8a17f commit f9ef94a
Showing 1 changed file with 21 additions and 2 deletions.
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
* <p>
Expand All @@ -134,6 +144,8 @@ public List<ArchiveInfo> getArchiveInfo(
String requestPayload) {

List<String> paths;
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);

try {
JSONObject jsonPayload = new JSONObject(requestPayload);
Expand All @@ -147,13 +159,20 @@ public List<ArchiveInfo> 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;
}
}

0 comments on commit f9ef94a

Please sign in to comment.