summaryrefslogtreecommitdiffstats
path: root/config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java
diff options
context:
space:
mode:
Diffstat (limited to 'config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java')
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java26
1 files changed, 13 insertions, 13 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java b/config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java
index bbcf4b48c1d..b9693685cf6 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java
@@ -24,6 +24,9 @@ public class DockerImage {
this.registry = Objects.requireNonNull(registry, "registry must be non-null");
this.repository = Objects.requireNonNull(repository, "repository must be non-null");
this.tag = Objects.requireNonNull(tag, "tag must be non-null");
+
+ if (tag.isPresent() && tag.get().isBlank())
+ throw new IllegalArgumentException("Set tag cannot be empty");
}
/** Returns the registry-part of this, i.e. the host/port of the registry. */
@@ -58,6 +61,8 @@ public class DockerImage {
/** Returns a copy of this with registry set to given value */
public DockerImage withRegistry(String registry) {
+ if (registry.isBlank()) throw new IllegalArgumentException("Registry cannot be empty");
+ if (registry.charAt(registry.length() - 1) == '/') throw new IllegalArgumentException("Registry cannot end with '/': " + registry);
return new DockerImage(registry, repository, tag);
}
@@ -86,26 +91,21 @@ public class DockerImage {
return Objects.hash(registry, repository, tag);
}
- public static DockerImage from(String registry, String repository) {
- return new DockerImage(registry, repository, Optional.empty());
- }
-
public static DockerImage fromString(String s) {
if (s.isEmpty()) return EMPTY;
- int firstPathSeparator = s.indexOf('/');
- if (firstPathSeparator < 0) throw new IllegalArgumentException("Missing path separator in '" + s + "'");
+ int repositoryStart = s.lastIndexOf('/', s.lastIndexOf('/') - 1);
+ if (repositoryStart < 0) throw new IllegalArgumentException("Expected to find at least 2 path segments in: " + s);
- String registry = s.substring(0, firstPathSeparator);
- String repository = s.substring(firstPathSeparator + 1);
- if (repository.isEmpty()) throw new IllegalArgumentException("Repository must be non-empty in '" + s + "'");
+ String registry = s.substring(0, repositoryStart);
+ String repository = s.substring(repositoryStart + 1);
int tagStart = repository.indexOf(':');
- if (tagStart < 0) return new DockerImage(registry, repository, Optional.empty());
+ Optional<String> tag = tagStart < 0 ? Optional.empty() : Optional.of(repository.substring(tagStart + 1));
- String tag = repository.substring(tagStart + 1);
- repository = repository.substring(0, tagStart);
- return new DockerImage(registry, repository, Optional.of(tag));
+ if (tagStart >= 0) repository = repository.substring(0, tagStart);
+ if (repository.isEmpty()) throw new IllegalArgumentException("Repository must be non-empty in '" + s + "'");
+ return new DockerImage(registry, repository, tag);
}
}