Skip to content

Commit

Permalink
Add container name validation
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 Feb 24, 2023
1 parent 44f8cc0 commit c3b6d9a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import nextflow.container.resolver.ContainerResolver
import nextflow.container.resolver.DefaultContainerResolver
import nextflow.plugin.Priority
import nextflow.processor.TaskRun
import nextflow.util.StringUtils

/**
* Implement Wave container resolve logic
*
Expand Down Expand Up @@ -101,6 +103,7 @@ class WaveContainerResolver implements ContainerResolver {
* when the task does not request any container or dockerfile to build
*/
protected ContainerInfo waveContainer(TaskRun task, String container) {
validateContainerRepo(container)
final assets = client().resolveAssets(task, container)
if( assets ) {
return client().fetchContainerImage(assets)
Expand All @@ -110,4 +113,10 @@ class WaveContainerResolver implements ContainerResolver {
return null
}

static protected void validateContainerRepo(String name) {
final scheme = StringUtils.getUrlProtocol(name)
if( scheme )
throw new IllegalArgumentException("Container repository should not start with URL like prefix - offending value: $name")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,26 @@ class WaveContainerResolverTest extends Specification {
and:
result == SINGULARITY_CONTAINER
}

def 'should validate container name' () {
when:
WaveContainerResolver.validateContainerRepo('ubuntu')
then:
noExceptionThrown()

when:
WaveContainerResolver.validateContainerRepo('ubuntu:latest')
then:
noExceptionThrown()

when:
WaveContainerResolver.validateContainerRepo('quay.io/wtsicgp/nanoseq:3.3.0')
then:
noExceptionThrown()

when:
WaveContainerResolver.validateContainerRepo('docker://quay.io/wtsicgp/nanoseq:3.3.0')
then:
thrown(IllegalArgumentException)
}
}

0 comments on commit c3b6d9a

Please sign in to comment.