From e69d607e63d632bd49bea1d64ad0a8dd7805a398 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Wed, 25 Dec 2024 14:36:17 +0100 Subject: [PATCH] Remove unneeded user async api Signed-off-by: Paolo Di Tommaso --- .../wave/controller/ContainerController.groovy | 16 ++++++---------- .../wave/controller/InspectController.groovy | 12 ++++-------- .../controller/RegistryProxyController.groovy | 4 ++-- .../io/seqera/wave/service/UserService.groovy | 4 ---- .../seqera/wave/service/UserServiceImpl.groovy | 16 ---------------- 5 files changed, 12 insertions(+), 40 deletions(-) diff --git a/src/main/groovy/io/seqera/wave/controller/ContainerController.groovy b/src/main/groovy/io/seqera/wave/controller/ContainerController.groovy index 0286dc5f2..4b59d4d62 100644 --- a/src/main/groovy/io/seqera/wave/controller/ContainerController.groovy +++ b/src/main/groovy/io/seqera/wave/controller/ContainerController.groovy @@ -20,7 +20,6 @@ package io.seqera.wave.controller import java.nio.file.Path import java.time.Instant -import java.util.concurrent.CompletableFuture import javax.annotation.PostConstruct import groovy.transform.CompileStatic @@ -76,7 +75,6 @@ import io.seqera.wave.service.scan.ContainerScanService import io.seqera.wave.service.validation.ValidationService import io.seqera.wave.service.validation.ValidationServiceImpl import io.seqera.wave.tower.PlatformId -import io.seqera.wave.tower.User import io.seqera.wave.tower.auth.JwtAuth import io.seqera.wave.tower.auth.JwtAuthStore import io.seqera.wave.util.DataTimeUtils @@ -94,7 +92,6 @@ import static io.seqera.wave.util.ContainerHelper.makeResponseV1 import static io.seqera.wave.util.ContainerHelper.makeResponseV2 import static io.seqera.wave.util.ContainerHelper.makeTargetImage import static io.seqera.wave.util.ContainerHelper.patchPlatformEndpoint -import static java.util.concurrent.CompletableFuture.completedFuture /** * Implement a controller to receive container token requests * @@ -182,17 +179,17 @@ class ContainerController { @Deprecated @Post('/container-token') @ExecuteOn(TaskExecutors.BLOCKING) - CompletableFuture> getToken(HttpRequest httpRequest, @Body SubmitContainerTokenRequest req) { + HttpResponse getToken(HttpRequest httpRequest, @Body SubmitContainerTokenRequest req) { return getContainerImpl(httpRequest, req, false) } @Post('/v1alpha2/container') @ExecuteOn(TaskExecutors.BLOCKING) - CompletableFuture> getTokenV2(HttpRequest httpRequest, @Body SubmitContainerTokenRequest req) { + HttpResponse getTokenV2(HttpRequest httpRequest, @Body SubmitContainerTokenRequest req) { return getContainerImpl(httpRequest, req, true) } - protected CompletableFuture> getContainerImpl(HttpRequest httpRequest, SubmitContainerTokenRequest req, boolean v2) { + protected HttpResponse getContainerImpl(HttpRequest httpRequest, SubmitContainerTokenRequest req, boolean v2) { // patch platform endpoint req.towerEndpoint = patchPlatformEndpoint(req.towerEndpoint) @@ -207,7 +204,7 @@ class ContainerController { // anonymous access if( !req.towerAccessToken ) { - return completedFuture(handleRequest(httpRequest, req, PlatformId.NULL, v2)) + return handleRequest(httpRequest, req, PlatformId.NULL, v2) } // first check if the service is registered @@ -222,9 +219,8 @@ class ContainerController { jwtAuthStore.storeIfAbsent(auth) // find out the user associated with the specified tower access token - return userService - .getUserByAccessTokenAsync(registration.endpoint, auth) - .thenApply((User user) -> handleRequest(httpRequest, req, PlatformId.of(user,req), v2)) + final user = userService.getUserByAccessToken(registration.endpoint, auth) + return handleRequest(httpRequest, req, PlatformId.of(user,req), v2) } protected HttpResponse handleRequest(HttpRequest httpRequest, SubmitContainerTokenRequest req, PlatformId identity, boolean v2) { diff --git a/src/main/groovy/io/seqera/wave/controller/InspectController.groovy b/src/main/groovy/io/seqera/wave/controller/InspectController.groovy index 6093d4dfb..de3c9d541 100644 --- a/src/main/groovy/io/seqera/wave/controller/InspectController.groovy +++ b/src/main/groovy/io/seqera/wave/controller/InspectController.groovy @@ -18,7 +18,6 @@ package io.seqera.wave.controller -import java.util.concurrent.CompletableFuture import groovy.transform.CompileStatic import groovy.util.logging.Slf4j @@ -38,7 +37,6 @@ import io.seqera.wave.service.UserService import io.seqera.wave.service.inspect.ContainerInspectService import io.seqera.wave.service.pairing.PairingService import io.seqera.wave.tower.PlatformId -import io.seqera.wave.tower.User import io.seqera.wave.tower.auth.JwtAuth import jakarta.inject.Inject import static io.seqera.wave.util.ContainerHelper.patchPlatformEndpoint @@ -71,7 +69,7 @@ class InspectController { private String serverUrl @Post("/v1alpha1/inspect") - CompletableFuture> inspect(@Body ContainerInspectRequest req, @Nullable @QueryValue String platform) { + HttpResponse inspect(@Body ContainerInspectRequest req, @Nullable @QueryValue String platform) { if( !req.containerImage ) throw new BadRequestException("Missing 'containerImage' attribute") @@ -86,7 +84,7 @@ class InspectController { // anonymous access if( !req.towerAccessToken ) { - return CompletableFuture.completedFuture(makeResponse(req, platform, PlatformId.NULL)) + return makeResponse(req, platform, PlatformId.NULL) } // We first check if the service is registered @@ -95,10 +93,8 @@ class InspectController { throw new BadRequestException("Tower instance '${req.towerEndpoint}' has not enabled to connect Wave service '$serverUrl'") // find out the user associated with the specified tower access token - return userService - .getUserByAccessTokenAsync(registration.endpoint, JwtAuth.of(req)) - .thenApply((User user) -> makeResponse(req, platform, PlatformId.of(user,req)) ) - + final user = userService .getUserByAccessToken(registration.endpoint, JwtAuth.of(req)) + return makeResponse(req, platform, PlatformId.of(user,req)) } protected HttpResponse makeResponse(ContainerInspectRequest req, String platform, PlatformId identity) { diff --git a/src/main/groovy/io/seqera/wave/controller/RegistryProxyController.groovy b/src/main/groovy/io/seqera/wave/controller/RegistryProxyController.groovy index 3c7b1fdf5..19e53e968 100644 --- a/src/main/groovy/io/seqera/wave/controller/RegistryProxyController.groovy +++ b/src/main/groovy/io/seqera/wave/controller/RegistryProxyController.groovy @@ -215,7 +215,7 @@ class RegistryProxyController { } else if( resp.body!=null ) { log.debug "Returning ${route.type} from repository: '${route.getTargetContainer()}'" - return fromContentResponse(resp, route) + return fromContentResponse(resp) } else if( blobCacheService ) { log.debug "Forwarding ${route.type} cache request '${route.getTargetContainer()}'" @@ -346,7 +346,7 @@ class RegistryProxyController { .headers(toMutableHeaders(response.headers)) } - MutableHttpResponse fromContentResponse(DelegateResponse resp, RoutePath route) { + MutableHttpResponse fromContentResponse(DelegateResponse resp) { HttpResponse .status(HttpStatus.valueOf(resp.statusCode)) .body(resp.body) diff --git a/src/main/groovy/io/seqera/wave/service/UserService.groovy b/src/main/groovy/io/seqera/wave/service/UserService.groovy index 331b0de86..af9a1f0b6 100644 --- a/src/main/groovy/io/seqera/wave/service/UserService.groovy +++ b/src/main/groovy/io/seqera/wave/service/UserService.groovy @@ -18,11 +18,9 @@ package io.seqera.wave.service -import java.util.concurrent.CompletableFuture import io.seqera.wave.tower.User import io.seqera.wave.tower.auth.JwtAuth - /** * Declare a service to access a Tower user * @@ -32,6 +30,4 @@ interface UserService { User getUserByAccessToken(String endpoint, JwtAuth auth) - CompletableFuture getUserByAccessTokenAsync(String endpoint, JwtAuth auth) - } diff --git a/src/main/groovy/io/seqera/wave/service/UserServiceImpl.groovy b/src/main/groovy/io/seqera/wave/service/UserServiceImpl.groovy index 0af9ad120..c3b978303 100644 --- a/src/main/groovy/io/seqera/wave/service/UserServiceImpl.groovy +++ b/src/main/groovy/io/seqera/wave/service/UserServiceImpl.groovy @@ -18,19 +18,15 @@ package io.seqera.wave.service -import java.util.concurrent.CompletableFuture -import java.util.concurrent.ExecutorService import groovy.transform.CompileStatic import groovy.util.logging.Slf4j import io.micronaut.core.annotation.Nullable -import io.micronaut.scheduling.TaskExecutors import io.seqera.wave.exception.UnauthorizedException import io.seqera.wave.tower.User import io.seqera.wave.tower.auth.JwtAuth import io.seqera.wave.tower.client.TowerClient import jakarta.inject.Inject -import jakarta.inject.Named import jakarta.inject.Singleton /** * Define a service to access a Tower user @@ -46,18 +42,6 @@ class UserServiceImpl implements UserService { @Nullable private TowerClient towerClient - @Inject - @Named(TaskExecutors.BLOCKING) - private ExecutorService ioExecutor - - @Override - CompletableFuture getUserByAccessTokenAsync(String endpoint, JwtAuth auth) { - if( !towerClient ) - throw new IllegalStateException("Missing Tower client - make sure the 'tower' micronaut environment has been provided") - - return CompletableFuture.supplyAsync(()-> getUserByAccessToken(endpoint,auth), ioExecutor) - } - @Override User getUserByAccessToken(String endpoint, JwtAuth auth) { final resp = towerClient.userInfo(endpoint, auth)