Skip to content

Commit

Permalink
fix: ImageUtil ':' handling.Add getGroup & getReg
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Apr 6, 2023
1 parent 1f6affe commit e23fa4f
Showing 1 changed file with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ private ImageUtil() {
* Create an image from the individual parts.
*
* @param registry The registry.
* @param repository The repository.
* @param repository The group.
* @param name The name.
* @param tag The tag.
* @return The image.
*/
public static String getImage(Optional<String> registry, String repository, String name, String tag) {
public static String getImage(Optional<String> registry, String group, String name, String tag) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("Docker image name cannot be null!");
}
Expand All @@ -29,12 +29,44 @@ public static String getImage(Optional<String> registry, String repository, Stri
}
StringBuilder sb = new StringBuilder();
registry.ifPresent(r -> sb.append(r).append(SLASH));
sb.append(repository).append(SLASH);
sb.append(group).append(SLASH);

sb.append(name).append(COLN).append(tag);
return sb.toString();
}

/**
* Return the image registry.
*
* @param image The docker image.
* @return The image registry.
*/
public static Optional<String> getRegistry(String image) {
String[] parts = image.split(SLASH);
if (parts.length <= 2) {
//name:tag
//group/name:tag
return Optional.empty();
}
return Optional.ofNullable(parts[0]);
}

/**
* Return the image group.
*
* @param image The docker image.
* @return The image group.
*/
public static String getGroup(String image) {
String[] parts = image.split(SLASH);
if (parts.length <= 2) {
//name:tag
//group/name:tag
return parts[0];
}
return parts[1];
}

/**
* Return the docker image repository.
*
Expand Down Expand Up @@ -72,7 +104,7 @@ public static String getName(String image) {
}

if (tagged.contains(COLN)) {
return tagged.substring(0, tagged.indexOf(COLN));
return tagged.substring(0, tagged.lastIndexOf(COLN));
}
return tagged;
}
Expand All @@ -85,7 +117,7 @@ public static String getName(String image) {
*/
public static String getTag(String image) {
if (image.contains(COLN)) {
return image.substring(image.indexOf(COLN) + 1);
return image.substring(image.lastIndexOf(COLN) + 1);
}
return image;
}
Expand Down

0 comments on commit e23fa4f

Please sign in to comment.