Skip to content

Commit

Permalink
frontend: handle frontend.root variable properly
Browse files Browse the repository at this point in the history
Motivation:
===========

Issue dCache#7506 is about failures to
invoke WLCG tape API to stage files on files relative to {webdav,frontend}.root

Modification:
============

Take frontend.root path into account when calculating effective prefix

Result:
=======

Able to call stage API successully on paths ralative to frontend.root

Patch: https://rb.dcache.org/r/14267/
Target: trunk
Request: 10.x
Request: 9.x
  • Loading branch information
DmitryLitvintsev committed Jun 25, 2024
1 parent 379449a commit a194c9e
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ 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.resources.bulk.BulkResources.getRestriction;
import static org.dcache.restful.resources.bulk.BulkResources.getSubject;
import static org.dcache.restful.util.HttpServletRequests.getUserRootAwareTargetPrefix;
import static org.dcache.restful.util.JSONUtils.newBadRequestException;

import com.google.common.base.Strings;
import diskCacheV111.util.FsPath;
import diskCacheV111.util.PnfsHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand All @@ -84,6 +86,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand All @@ -93,8 +96,10 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.dcache.auth.attributes.LoginAttributes;
import org.dcache.auth.attributes.Restriction;
import org.dcache.cells.CellStub;
import org.dcache.http.PathMapper;
import org.dcache.restful.providers.tape.StageRequestInfo;
import org.dcache.restful.util.HandlerBuilders;
import org.dcache.restful.util.bulk.BulkServiceCommunicator;
Expand Down Expand Up @@ -130,6 +135,9 @@ public final class StageResources {
@Inject
private BulkServiceCommunicator service;

@Inject
private PathMapper pathMapper;

@Inject
@Named("pnfs-stub")
private CellStub pnfsmanager;
Expand Down Expand Up @@ -281,7 +289,10 @@ public Response submit(
Subject subject = getSubject();
Restriction restriction = getRestriction();

BulkRequest request = toBulkRequest(requestPayload);
FsPath userRoot = LoginAttributes.getUserRoot(getLoginAttributes(request));
FsPath rootPath = pathMapper.effectiveRoot(userRoot, ForbiddenException::new);

BulkRequest request = toBulkRequest(requestPayload, rootPath);

/*
* Frontend sets the URL. The backend service provides the UUID.
Expand Down Expand Up @@ -340,7 +351,7 @@ public Response clearRequest(@ApiParam("The unique id of the request.")
return Response.ok().build();
}

private BulkRequest toBulkRequest(String requestPayload) {
private BulkRequest toBulkRequest(String requestPayload, FsPath rootPath) {
if (Strings.emptyToNull(requestPayload) == null) {
throw new BadRequestException("empty request payload.");
}
Expand All @@ -353,7 +364,7 @@ private BulkRequest toBulkRequest(String requestPayload) {
request.setActivity("STAGE");

PnfsHandler handler = HandlerBuilders.unrestrictedPnfsHandler(pnfsmanager);
request.setTargetPrefix(getUserRootAwareTargetPrefix(this.request, null, handler));
request.setTargetPrefix(getUserRootAwareTargetPrefix(this.request, rootPath.toString(), handler));

try {
JSONObject reqPayload = new JSONObject(requestPayload);
Expand Down

0 comments on commit a194c9e

Please sign in to comment.