From 4fbf3bb25d6b725780ed2254a893d8c7fc17adfe Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Thu, 21 Dec 2023 17:03:46 +0100 Subject: [PATCH] wip5 Signed-off-by: Paolo Di Tommaso --- .../wave/auth/RegistryAuthServiceImpl.groovy | 12 ++++++------ .../wave/controller/ValidateController.groovy | 2 +- .../ValidateRegistryCredsRequest.groovy | 18 +++++++++++++++++- .../wave/auth/RegistryAuthServiceTest.groovy | 16 ++++++++-------- 4 files changed, 32 insertions(+), 16 deletions(-) rename src/main/groovy/io/seqera/wave/{model => exchange}/ValidateRegistryCredsRequest.groovy (73%) diff --git a/src/main/groovy/io/seqera/wave/auth/RegistryAuthServiceImpl.groovy b/src/main/groovy/io/seqera/wave/auth/RegistryAuthServiceImpl.groovy index f7410eec4..c5eee2bcd 100644 --- a/src/main/groovy/io/seqera/wave/auth/RegistryAuthServiceImpl.groovy +++ b/src/main/groovy/io/seqera/wave/auth/RegistryAuthServiceImpl.groovy @@ -98,7 +98,7 @@ class RegistryAuthServiceImpl implements RegistryAuthService { if( !registryName ) registryName = DOCKER_IO - final target = RegistryMeta.parse(registryName) + final target = TargetInfo.parse(registryName) // 1. look up the registry authorisation info for the given registry name final registry = lookupService.lookup(target.registry) @@ -111,7 +111,7 @@ class RegistryAuthServiceImpl implements RegistryAuthService { // 3. make a request against the authorization "realm" service using basic // credentials to get the login token final basic = "${creds.username}:${creds.password}".bytes.encodeBase64() - final endpoint = registry.auth.getEndpoint(username, target.repository) + final endpoint = registry.auth.getEndpoint() HttpRequest request = HttpRequest.newBuilder() .uri(endpoint) .GET() @@ -261,18 +261,18 @@ class RegistryAuthServiceImpl implements RegistryAuthService { @Canonical - static class RegistryMeta { + static class TargetInfo { String registry String repository - static RegistryMeta parse(String registryOrRepository) { + static TargetInfo parse(String registryOrRepository) { assert registryOrRepository, "Missing 'registryOrRepository' argument" if( registryOrRepository.contains('/') ) { final coords = ContainerCoordinates.parse(registryOrRepository) - return new RegistryMeta(coords.getRegistry(), coords.getImage()) + return new TargetInfo(coords.getRegistry(), coords.getImage()) } else { - return new RegistryMeta(registryOrRepository) + return new TargetInfo(registryOrRepository) } } } diff --git a/src/main/groovy/io/seqera/wave/controller/ValidateController.groovy b/src/main/groovy/io/seqera/wave/controller/ValidateController.groovy index 00dcb0b83..8829432eb 100644 --- a/src/main/groovy/io/seqera/wave/controller/ValidateController.groovy +++ b/src/main/groovy/io/seqera/wave/controller/ValidateController.groovy @@ -23,7 +23,7 @@ import javax.validation.Valid import io.micronaut.http.annotation.Controller import io.micronaut.http.annotation.Post import io.seqera.wave.auth.RegistryAuthService -import io.seqera.wave.model.ValidateRegistryCredsRequest +import io.seqera.wave.exchange.ValidateRegistryCredsRequest import jakarta.inject.Inject import reactor.core.publisher.Mono diff --git a/src/main/groovy/io/seqera/wave/model/ValidateRegistryCredsRequest.groovy b/src/main/groovy/io/seqera/wave/exchange/ValidateRegistryCredsRequest.groovy similarity index 73% rename from src/main/groovy/io/seqera/wave/model/ValidateRegistryCredsRequest.groovy rename to src/main/groovy/io/seqera/wave/exchange/ValidateRegistryCredsRequest.groovy index e1d53b338..e62cd1fbc 100644 --- a/src/main/groovy/io/seqera/wave/model/ValidateRegistryCredsRequest.groovy +++ b/src/main/groovy/io/seqera/wave/exchange/ValidateRegistryCredsRequest.groovy @@ -16,18 +16,34 @@ * along with this program. If not, see . */ -package io.seqera.wave.model +package io.seqera.wave.exchange import javax.validation.constraints.NotBlank import io.micronaut.core.annotation.Introspected +/** + * Request object to valide a container registry credentials + */ @Introspected class ValidateRegistryCredsRequest { + + /** + * The registry user name + */ @NotBlank String userName + + /** + * The registry password + */ @NotBlank String password + + /** + * The registry name e.g. @{code docker.io} or a registry including the repository + * name e.g. {@code docker.io/user/repository} (without tag extension) + */ @NotBlank String registry } diff --git a/src/test/groovy/io/seqera/wave/auth/RegistryAuthServiceTest.groovy b/src/test/groovy/io/seqera/wave/auth/RegistryAuthServiceTest.groovy index cb2af51be..3fc762bf4 100644 --- a/src/test/groovy/io/seqera/wave/auth/RegistryAuthServiceTest.groovy +++ b/src/test/groovy/io/seqera/wave/auth/RegistryAuthServiceTest.groovy @@ -74,10 +74,10 @@ class RegistryAuthServiceTest extends Specification implements SecureDockerRegis void 'test valid login'() { given: - String uri = getTestRegistryName(REGISTRY) + String registry = getTestRegistryName(REGISTRY) when: - boolean logged = loginService.login(uri, USER, PWD) + boolean logged = loginService.login(registry, USER, PWD) then: logged == VALID @@ -95,26 +95,26 @@ class RegistryAuthServiceTest extends Specification implements SecureDockerRegis @IgnoreIf({!System.getenv('AZURECR_USER')}) void 'test valid azure login'() { given: - def REGISTRY = 'seqeralabs.azurecr.io' + def registry = 'seqeralabs.azurecr.io' expect: - loginService.login(REGISTRY, azureUsername, azurePassword) + loginService.login(registry, azureUsername, azurePassword) } @IgnoreIf({!System.getenv('AWS_ACCESS_KEY_ID')}) void 'test valid aws ecr private'() { given: - String REGISTRY = '195996028523.dkr.ecr.eu-west-1.amazonaws.com' + String registry = '195996028523.dkr.ecr.eu-west-1.amazonaws.com' expect: - loginService.login(REGISTRY, awsEcrUsername, awsEcrPassword) + loginService.login(registry, awsEcrUsername, awsEcrPassword) } @IgnoreIf({!System.getenv('AWS_ACCESS_KEY_ID')}) void 'test valid aws ecr public'() { given: - String REGISTRY = 'public.ecr.aws' + String registry = 'public.ecr.aws' expect: - loginService.login(REGISTRY, awsEcrUsername, awsEcrPassword) + loginService.login(registry, awsEcrUsername, awsEcrPassword) } void 'test containerService valid login'() {