private Object readResolve() { if (pushCredentialsId == null && registry != null) { pushCredentialsId = registry.getCredentialsId(); } if (pullCredentialsId != null) { fromRegistry = new DockerRegistryEndpoint(null, pullCredentialsId); } return this; } }
protected Object readResolve() { if (volumesFrom != null) { if (StringUtils.isNotBlank(volumesFrom)) { setVolumesFrom2(new String[]{volumesFrom}); } volumesFrom = null; } if (pullCredentialsId == null && registry != null) { pullCredentialsId = registry.getCredentialsId(); } return this; }
@Override public UninstantiatedDescribable uninstantiate(Step step) throws UnsupportedOperationException { RegistryEndpointStep s = (RegistryEndpointStep) step; Map<String, Object> args = new TreeMap<>(); args.put("url", s.registry.getUrl()); args.put("credentialsId", s.registry.getCredentialsId()); args.put("toolName", s.toolName); args.values().removeAll(Collections.singleton(null)); return new UninstantiatedDescribable(args); }
@Override public String getRegistryCredentialsId(@Nullable Run run) { if (config.getRegistry() != null && !StringUtils.isBlank(config.getRegistry().getCredentialsId())) { return config.getRegistry().getCredentialsId(); } else { return null; } } }
@Restricted(NoExternalUse.class) public static void setRegistryAuthentication(PullImageCmd cmd, DockerRegistryEndpoint registry, ItemGroup context) { if (registry != null && registry.getCredentialsId() != null) { AuthConfig auth = getAuthConfig(registry, context); cmd.withAuthConfig(auth); } }
@Restricted(NoExternalUse.class) public static void setRegistryAuthentication(PushImageCmd cmd, DockerRegistryEndpoint registry, ItemGroup context) { if (registry != null && registry.getCredentialsId() != null) { AuthConfig auth = getAuthConfig(registry, context); cmd.withAuthConfig(auth); } }
@DataBoundSetter public void setDockerCredentials(List<DockerRegistryEndpoint> dockerCredentials) { List<DockerRegistryEndpoint> endpoints = new ArrayList<>(); for (DockerRegistryEndpoint endpoint : dockerCredentials) { String credentialsId = org.apache.commons.lang.StringUtils.trimToNull(endpoint.getCredentialsId()); if (credentialsId == null) { // no credentials item is selected, skip this endpoint continue; } String registryUrl = org.apache.commons.lang.StringUtils.trimToNull(endpoint.getUrl()); // null URL results in "https://index.docker.io/v1/" effectively if (registryUrl != null) { // It's common that the user omits the scheme prefix, we add http:// as default. // Otherwise it will cause MalformedURLException when we call endpoint.getEffectiveURL(); if (!Constants.URI_SCHEME_PREFIX.matcher(registryUrl).find()) { registryUrl = "http://" + registryUrl; } } endpoints.add(new DockerRegistryEndpoint(registryUrl, credentialsId)); } this.dockerCredentials = endpoints; }
@Override public String getRegistryCredentialsId(@Nullable Run run) { if (run != null) { Job job = run.getParent(); ItemGroup parent = job.getParent(); while (parent != null) { if (parent instanceof AbstractFolder) { AbstractFolder folder = (AbstractFolder) parent; FolderConfig config = (FolderConfig) folder.getProperties().get(FolderConfig.class); if (config != null) { DockerRegistryEndpoint registry = config.getRegistry(); if (registry != null && !StringUtils.isBlank(registry.getCredentialsId())) { return registry.getCredentialsId(); } } } if (parent instanceof Item) { parent = ((Item) parent).getParent(); } else { parent = null; } } } return null; } }
public AuthConfig getAuthConfig(Job<?, ?> project) { if (dockerRegistryEndpoint == null || Strings.isNullOrEmpty(dockerRegistryEndpoint.getCredentialsId())) { return null; } AuthConfig authConfig = new AuthConfig(); authConfig.withRegistryAddress(dockerRegistryEndpoint.getUrl()); DockerRegistryToken token = this.dockerRegistryEndpoint.getToken(project); if (token != null) { String credentials = new String(Base64.decodeBase64(token.getToken()), Charsets.UTF_8); String[] usernamePassword = credentials.split(":"); authConfig.withUsername(usernamePassword[0]); authConfig.withPassword(usernamePassword[1]); authConfig.withEmail(token.getEmail()); } return authConfig; }
withId(registry.getCredentialsId())); throw new IllegalArgumentException("Invalid Credential ID " + registry.getCredentialsId());
private String buildImage() throws IOException, InterruptedException { final AuthConfigurations auths = new AuthConfigurations(); final DockerRegistryEndpoint pullRegistry = getFromRegistry(); if (pullRegistry != null && pullRegistry.getCredentialsId() != null) { auths.addConfig(DockerCloud.getAuthConfig(pullRegistry, run.getParent().getParent()));