diff --git a/docker-compose.yml b/docker-compose.yml index 845d0324..d715f56c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/src/main/java/api/Tapir.java b/src/main/java/api/Tapir.java index 5a124c35..7983e8b8 100644 --- a/src/main/java/api/Tapir.java +++ b/src/main/java/api/Tapir.java @@ -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; @@ -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(); } diff --git a/src/main/java/api/mapper/exceptions/TapirExceptionMapper.java b/src/main/java/api/mapper/exceptions/TapirExceptionMapper.java index dc2347c7..7c2c2e7f 100644 --- a/src/main/java/api/mapper/exceptions/TapirExceptionMapper.java +++ b/src/main/java/api/mapper/exceptions/TapirExceptionMapper.java @@ -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; @@ -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(); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 92693147..b92b34cb 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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