static ServiceDocument buildDefaultStateInstance(ServiceHost host) { RegistryState state = new RegistryState(); state.documentSelfLink = DEFAULT_INSTANCE_LINK; state.address = DEFAULT_REGISTRY_ADDRESS; state.name = DEFAULT_REGISTRY_NAME; state.endpointType = RegistryState.DOCKER_REGISTRY_ENDPOINT_TYPE; state.disabled = Boolean.FALSE; state.customProperties = new HashMap<>(); state.customProperties.put(API_VERSION_PROP_NAME, ApiVersion.V1.toString()); boolean disableDefaultRegistry = Boolean.valueOf( ConfigurationUtil.getProperty(RegistryService.DISABLE_DEFAULT_REGISTRY_PROP_NAME)); // create or delete default registry if (disableDefaultRegistry) { // ensure default registry does not exist host.registerForServiceAvailability((o, e) -> { host.log(Level.INFO, "registerForServiceAvailability: %s", RegistryFactoryService.SELF_LINK); deleteDefaultRegistry(host); }, true, RegistryFactoryService.SELF_LINK); return null; } return state; }
String apiVersion = o.getBody(RegistryPingResponse.class).apiVersion.name(); if (hostSpec.hostState.customProperties == null) { hostSpec.hostState.customProperties = new HashMap<>();
private void createHarborRegistry(Operation post, String harborUrl, String authCredentialsLink) { RegistryState state = new RegistryState(); state.documentSelfLink = Harbor.DEFAULT_REGISTRY_LINK; state.address = harborUrl; state.name = Harbor.DEFAULT_REGISTRY_NAME; state.endpointType = RegistryState.DOCKER_REGISTRY_ENDPOINT_TYPE; state.authCredentialsLink = authCredentialsLink; state.customProperties = new HashMap<>(); state.customProperties.put(RegistryService.API_VERSION_PROP_NAME, RegistryService.ApiVersion.V2.toString()); sendRequest(Operation .createPost(UriUtils.buildUri(getHost(), RegistryFactoryService.SELF_LINK)) .setBodyNoCloning(state) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_FORCE_INDEX_UPDATE) .setCompletion((o, e) -> { if (e != null) { logSevere("Unable to create default harbor registry: %s", Utils.toString(e)); post.fail(e); return; } post.complete(); })); }
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)); } }
private RegistryState createRegistry(String name, String address, String projectLink) throws Throwable { RegistryState registry = new RegistryState(); registry.name = name; registry.address = address; registry.endpointType = RegistryState.DOCKER_REGISTRY_ENDPOINT_TYPE; registry.customProperties = new HashMap<>(); registry.customProperties.put(RegistryService.API_VERSION_PROP_NAME, ApiVersion.V1.toString()); if (projectLink != null && !projectLink.isEmpty()) { registry.tenantLinks = Collections.singletonList(projectLink); } RegistryState resultRegistry = doPost(registry, RegistryFactoryService.SELF_LINK); host.log(Level.INFO, "Created %s registry '%s' [%s].", address == null ? "global" : "project-specific", name, resultRegistry.documentSelfLink); return resultRegistry; }
private void processSearchRequest(RequestContext context) { String apiVersion = getApiVersion(context.registryState); if (ApiVersion.V1.toString().equals(apiVersion)) { processV1SearchRequest(context); } else if (ApiVersion.V2.toString().equals(apiVersion)) { processV2SearchRequest(context); } else { String errorMsg = String.format("Unsupported registry version '%s'.", apiVersion); context.operation.fail(new LocalizableValidationException(errorMsg, "adapter.unsupported.registry.version", apiVersion)); } }
@Before public void createDockerHubRegistryState() throws Throwable { RegistryState registryState = new RegistryState(); registryState.address = getDockerHubRegistryUri().toString(); registryState.customProperties = new HashMap<>(); registryState.customProperties.put(RegistryService.API_VERSION_PROP_NAME, ApiVersion.V1.toString()); dockerHubRegistryStateLink = doPost(registryState, RegistryFactoryService.SELF_LINK).documentSelfLink; createSslTrustCert(new URI(registryState.address).getHost()); }
@Before public void createV2RegistryState() throws Throwable { RegistryState registryState = new RegistryState(); registryState.address = getV2RegistryUri().toString(); registryState.customProperties = new HashMap<>(); registryState.customProperties.put(RegistryService.API_VERSION_PROP_NAME, ApiVersion.V2.toString()); v2RegistryStateLink = doPost(registryState, RegistryFactoryService.SELF_LINK).documentSelfLink; createSslTrustCert(new URI(registryState.address).getHost()); }