Skip to content

Commit

Permalink
Remove unneeded user async api
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Dec 25, 2024
1 parent 9e25687 commit e69d607
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
*
Expand Down Expand Up @@ -182,17 +179,17 @@ class ContainerController {
@Deprecated
@Post('/container-token')
@ExecuteOn(TaskExecutors.BLOCKING)
CompletableFuture<HttpResponse<SubmitContainerTokenResponse>> getToken(HttpRequest httpRequest, @Body SubmitContainerTokenRequest req) {
HttpResponse<SubmitContainerTokenResponse> getToken(HttpRequest httpRequest, @Body SubmitContainerTokenRequest req) {
return getContainerImpl(httpRequest, req, false)
}

@Post('/v1alpha2/container')
@ExecuteOn(TaskExecutors.BLOCKING)
CompletableFuture<HttpResponse<SubmitContainerTokenResponse>> getTokenV2(HttpRequest httpRequest, @Body SubmitContainerTokenRequest req) {
HttpResponse<SubmitContainerTokenResponse> getTokenV2(HttpRequest httpRequest, @Body SubmitContainerTokenRequest req) {
return getContainerImpl(httpRequest, req, true)
}

protected CompletableFuture<HttpResponse<SubmitContainerTokenResponse>> getContainerImpl(HttpRequest httpRequest, SubmitContainerTokenRequest req, boolean v2) {
protected HttpResponse<SubmitContainerTokenResponse> getContainerImpl(HttpRequest httpRequest, SubmitContainerTokenRequest req, boolean v2) {
// patch platform endpoint
req.towerEndpoint = patchPlatformEndpoint(req.towerEndpoint)

Expand All @@ -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
Expand All @@ -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<SubmitContainerTokenResponse> handleRequest(HttpRequest httpRequest, SubmitContainerTokenRequest req, PlatformId identity, boolean v2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package io.seqera.wave.controller

import java.util.concurrent.CompletableFuture

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
Expand All @@ -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
Expand Down Expand Up @@ -71,7 +69,7 @@ class InspectController {
private String serverUrl

@Post("/v1alpha1/inspect")
CompletableFuture<HttpResponse<ContainerInspectResponse>> inspect(@Body ContainerInspectRequest req, @Nullable @QueryValue String platform) {
HttpResponse<ContainerInspectResponse> inspect(@Body ContainerInspectRequest req, @Nullable @QueryValue String platform) {

if( !req.containerImage )
throw new BadRequestException("Missing 'containerImage' attribute")
Expand All @@ -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
Expand All @@ -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<ContainerInspectResponse> makeResponse(ContainerInspectRequest req, String platform, PlatformId identity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}'"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions src/main/groovy/io/seqera/wave/service/UserService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -32,6 +30,4 @@ interface UserService {

User getUserByAccessToken(String endpoint, JwtAuth auth)

CompletableFuture<User> getUserByAccessTokenAsync(String endpoint, JwtAuth auth)

}
16 changes: 0 additions & 16 deletions src/main/groovy/io/seqera/wave/service/UserServiceImpl.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,18 +42,6 @@ class UserServiceImpl implements UserService {
@Nullable
private TowerClient towerClient

@Inject
@Named(TaskExecutors.BLOCKING)
private ExecutorService ioExecutor

@Override
CompletableFuture<User> 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)
Expand Down

0 comments on commit e69d607

Please sign in to comment.