Skip to content

Commit

Permalink
wip5
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Dec 21, 2023
1 parent c59f5d8 commit 4fbf3bb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,34 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'() {
Expand Down

0 comments on commit 4fbf3bb

Please sign in to comment.