Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALS-7475] Add detailed logging for container path and query parameters #207

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.ws.rs.*;
import javax.ws.rs.core.*;

import edu.harvard.dbmi.avillach.data.entity.Query;
import edu.harvard.dbmi.avillach.domain.*;
import edu.harvard.dbmi.avillach.service.*;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
Expand Down Expand Up @@ -154,34 +153,35 @@ public QueryStatus queryStatus(
@POST
@Path("/query/{queryId}/result")
@Operation(
summary = "Returns result for given query",
responses = {@ApiResponse(
responseCode = "200", description = "Query result", content = @Content(schema = @Schema(implementation = Response.class))
)}
summary = "Returns result for given query",
responses = {@ApiResponse(
responseCode = "200", description = "Query result", content = @Content(schema = @Schema(implementation = Response.class))
)}
)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response queryResult(
@Parameter(
description = "The UUID of the query to fetch the status of. The UUID is "
+ "returned by the /query endpoint as the \"picsureResultId\" in the response object"
) @PathParam("queryId") UUID queryId, @Parameter QueryRequest credentialsQueryRequest, @Context HttpHeaders headers
@Parameter(
description = "The UUID of the query to fetch the status of. The UUID is "
+ "returned by the /query endpoint as the \"picsureResultId\" in the response object"
) @PathParam("queryId") UUID queryId, @Parameter QueryRequest credentialsQueryRequest, @Context HttpHeaders headers
) {
return queryService.queryResult(queryId, credentialsQueryRequest, headers);
}

@POST
@Path("/query/{queryId}/signed-url")
@Operation(
summary = "Returns a signed url for given query",
responses = {@ApiResponse(
responseCode = "200", description = "Query result", content = @Content(schema = @Schema(implementation = Response.class))
)}
summary = "Returns a signed url for given query",
responses = {@ApiResponse(
responseCode = "200", description = "Query result", content = @Content(schema = @Schema(implementation = Response.class))
)}
)
@Produces(MediaType.APPLICATION_JSON)
public Response queryResultSignedUrl(
@Parameter(
description = "The UUID of the query to fetch the status of. The UUID is "
+ "returned by the /query endpoint as the \"picsureResultId\" in the response object"
) @PathParam("queryId") UUID queryId, @Parameter QueryRequest credentialsQueryRequest, @Context HttpHeaders headers
@Parameter(
description = "The UUID of the query to fetch the status of. The UUID is "
+ "returned by the /query endpoint as the \"picsureResultId\" in the response object"
) @PathParam("queryId") UUID queryId, @Parameter QueryRequest credentialsQueryRequest, @Context HttpHeaders headers
) {
return queryService.queryResultSignedUrl(queryId, credentialsQueryRequest, headers);
}
Expand Down Expand Up @@ -229,16 +229,20 @@ public Response generateContinuousBin(QueryRequest continuousData, @Context Http
@Path("/proxy/{container}/{request : .+}")
@Operation(hidden = true)
public Response postProxy(
@PathParam("container") String containerId, @PathParam("request") String request, @Context UriInfo uriInfo, String body
@PathParam("container") String containerId, @PathParam("request") String request, @Context UriInfo uriInfo, String body,
@Context HttpHeaders headers
) {
return proxyWebClient.postProxy(containerId, request, body, uriInfo.getQueryParameters());
return proxyWebClient.postProxy(containerId, request, body, uriInfo.getQueryParameters(), headers);
}

@GET
@Path("/proxy/{container}/{request : .+}")
@Operation(hidden = true)
public Response getProxy(@PathParam("container") String containerId, @PathParam("request") String request, @Context UriInfo uriInfo) {
return proxyWebClient.getProxy(containerId, request, uriInfo.getQueryParameters());
public Response getProxy(
@PathParam("container") String containerId, @PathParam("request") String request, @Context UriInfo uriInfo,
@Context HttpHeaders headers
) {
return proxyWebClient.getProxy(containerId, request, uriInfo.getQueryParameters(), headers);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.harvard.dbmi.avillach.data.repository.ResourceRepository;
import edu.harvard.dbmi.avillach.util.HttpClientUtil;
import edu.harvard.dbmi.avillach.util.Utilities;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
Expand All @@ -16,6 +17,7 @@

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import java.io.IOException;
Expand All @@ -34,10 +36,18 @@ public ProxyWebClient() {
client = HttpClientUtil.getConfiguredHttpClient();
}

public Response postProxy(String containerId, String path, String body, MultivaluedMap<String, String> queryParams) {
public Response postProxy(
String containerId, String path, String body, MultivaluedMap<String, String> queryParams, HttpHeaders headers
) {
if (containerIsNOTAResource(containerId)) {
return Response.status(400, "container name not trustworthy").build();
}

String requestSource = Utilities.getRequestSourceFromHeader(headers);
LOG.info(
"path={}, requestSource={}, containerId={}, body={}, queryParams={}, ", path, requestSource, containerId, body, queryParams
);

try {
URI uri =
new URIBuilder().setScheme("http").setHost(containerId).setPath(path).setParameters(processParams(queryParams)).build();
Expand All @@ -53,10 +63,14 @@ public Response postProxy(String containerId, String path, String body, Multival
}
}

public Response getProxy(String containerId, String path, MultivaluedMap<String, String> queryParams) {
public Response getProxy(String containerId, String path, MultivaluedMap<String, String> queryParams, HttpHeaders headers) {
if (containerIsNOTAResource(containerId)) {
return Response.status(400, "container name not trustworthy").build();
}

String requestSource = Utilities.getRequestSourceFromHeader(headers);
LOG.info("path={}, requestSource={}, containerId={}, queryParams={}", path, requestSource, containerId, queryParams);

try {
URI uri =
new URIBuilder().setScheme("http").setHost(containerId).setPath(path).setParameters(processParams(queryParams)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -50,7 +49,7 @@ public void shouldPostToProxy() throws IOException {
Mockito.when(resourceRepository.getByColumn("name", "foo")).thenReturn(List.of(new Resource()));
subject.client = client;

Response actual = subject.postProxy("foo", "/my/cool/path", "{}", new MultivaluedHashMap<>());
Response actual = subject.postProxy("foo", "/my/cool/path", "{}", new MultivaluedHashMap<>(), null);

Assert.assertEquals(200, actual.getStatus());
}
Expand All @@ -63,7 +62,7 @@ public void shouldGetToProxy() throws IOException {
Mockito.when(resourceRepository.getByColumn("name", "bar")).thenReturn(List.of(new Resource()));
subject.client = client;

Response actual = subject.getProxy("bar", "/my/cool/path", new MultivaluedHashMap<>());
Response actual = subject.getProxy("bar", "/my/cool/path", new MultivaluedHashMap<>(), null);

Assert.assertEquals(200, actual.getStatus());
}
Expand All @@ -72,10 +71,10 @@ public void shouldGetToProxy() throws IOException {
public void shouldRejectNastyHost() {
Mockito.when(resourceRepository.getByColumn("name", "an.evil.domain")).thenReturn(List.of());

Response actual = subject.postProxy("an.evil.domain", "hax", null, new MultivaluedHashMap<>());
Response actual = subject.postProxy("an.evil.domain", "hax", null, new MultivaluedHashMap<>(), null);
assertEquals(400, actual.getStatus());

actual = subject.getProxy("an.evil.domain", "hax", new MultivaluedHashMap<>());
actual = subject.getProxy("an.evil.domain", "hax", new MultivaluedHashMap<>(), null);
assertEquals(400, actual.getStatus());
}

Expand All @@ -89,7 +88,7 @@ public void shouldPostWithParams() throws IOException {

MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>();
params.put("site", List.of("bch"));
Response actual = subject.postProxy("foo", "/my/cool/path", "{}", params);
Response actual = subject.postProxy("foo", "/my/cool/path", "{}", params, null);

Assert.assertEquals(200, actual.getStatus());
}
Expand Down
Loading