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

Fix/local storage read access #361

Merged
merged 3 commits into from
Dec 28, 2023
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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:

keycloak:
image: quay.io/keycloak/keycloak
image: quay.io/keycloak/keycloak:22.0
volumes:
- /etc/localtime:/etc/localtime:ro
- ./dev/scripts/keycloak:/opt/keycloak/data/import
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/api/Tapir.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package api;

import core.exceptions.ModuleNotFoundException;
import core.exceptions.ProviderNotFoundException;
import core.service.AuthService;
import core.storage.local.LocalStorageRepository;
import core.tapir.User;
import jakarta.annotation.security.PermitAll;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
Expand All @@ -25,28 +25,31 @@ public Tapir(AuthService authService) {
}

@GET
@PermitAll
@Path("/storage/{namespace}/{name}/{identifier}/{filename}")
@Produces("application/zip")
public Response download(String namespace, String name, String identifier, String filename)
throws ModuleNotFoundException {
throws ModuleNotFoundException, ProviderNotFoundException {
String path = Paths.get(namespace, name, identifier, filename).toString();
File artefact;
if (identifier.matches(".*\\d.*")) {
LOGGER.fine("Identifier is a version string, assume user requested a provider " + identifier);
LOGGER.info("Requested the download of provider " + path);
path = LocalStorageRepository.PROVIDER_RESOURCE_DIR + path;
artefact = new File(path);
if (!artefact.exists()) {
throw new ProviderNotFoundException(path);
}
} else {
LOGGER.info("Requested the download of module " + path);
path = LocalStorageRepository.MODULE_RESOURCE_DIR + path;
}
File moduleArchive = new File(path);

if (!moduleArchive.exists()) {
throw new ModuleNotFoundException(path);
artefact = new File(path);
if (!artefact.exists()) {
throw new ModuleNotFoundException(path);
}
}

return Response
.ok(moduleArchive)
.ok(artefact)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import api.mapper.exceptions.response.ErrorResponse;
import core.exceptions.NotFoundException;
import core.exceptions.TapirException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
Expand All @@ -26,6 +27,7 @@ public Response toResponse(TapirException e) {
status = Response.Status.NOT_FOUND;
}
return Response.status(status)
.entity(new ErrorResponse(errorId, errorMessage)).build();
.entity(new ErrorResponse(errorId, errorMessage))
.header("Content-Type", MediaType.APPLICATION_JSON).build();
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ quarkus:
policy: permit
paths:
- /terraform/*
# this is the path used for the local storage backend
- /tapir/storage/*
- /.well-known/*
publish:
policy: publish
Expand Down