public String getNamespaceAndRepo() { if (namespace != null) { return namespace + SECTION_SEPARATOR + repository; } else if (isDockerHubImage()) { return DEFAULT_NAMESPACE + SECTION_SEPARATOR + repository; } return repository; }
/** * Convert to a canonical single string representation * * @return E.g.:<p/> * registry.hub.docker.com/library/alpine -> alpine<p/> * registry.hub.docker.com/mongons/mongo -> mongons/mongo<p/> * registry.local.corp/proj/image -> registry.local.corp/proj/image */ @Override public String toString() { StringBuilder imageName = new StringBuilder(); if (!isDockerHubImage()) { imageName.append(host); imageName.append(SECTION_SEPARATOR); } // If namespace is null, do not set the default value 'library' as not all // V2 registry implementations support this convention imageName.append(getNamespaceAndRepo()); if (tag != null) { imageName.append(TAG_SEPARATOR); imageName.append(tag); } return imageName.toString(); } }
private void processListImageTagsRequest(RequestContext context) { // Docker Hub list tags requests are expected to use the v2 endpoint, // otherwise an incomplete list of tags is returned. Also use the 'library' namespace // for image without one in order for the request to succeed String imageName = context.request.customProperties.get(SEARCH_QUERY_PROP_NAME); boolean isDockerHubImage = DockerImage.fromImageName(imageName).isDockerHubImage(); if (isDockerHubImage) { processV2ListImageTagsRequest(context); return; } String apiVersion = getApiVersion(context.registryState); if (ApiVersion.V1.toString().equals(apiVersion)) { processV1ListImageTagsRequest(context); } else if (ApiVersion.V2.toString().equals(apiVersion)) { processV2ListImageTagsRequest(context); } else { String errorMsg = String.format("Unsupported registry version '%s'.", apiVersion); context.operation.fail(new LocalizableValidationException(errorMsg, "adapter.unsupported.registry.version", apiVersion)); } }