@CheckForNull private static DockerConfigFile loadLegacyConfig(String dockerConfigPath) throws IOException { File dockerLegacyCfgFile = new File(dockerConfigPath, DOCKER_LEGACY_CFG); if (!dockerLegacyCfgFile.exists() || !dockerLegacyCfgFile.isFile()) { return null; } //parse legacy auth config file format try { return new DockerConfigFile(MAPPER.<Map<String, AuthConfig>>readValue(dockerLegacyCfgFile, CONFIG_MAP_TYPE)); } catch (IOException e) { // pass } List<String> authFileContent = FileUtils.readLines(dockerLegacyCfgFile, StandardCharsets.UTF_8); if (authFileContent.size() < 2) { throw new IOException("The Auth Config file is empty"); } AuthConfig config = new AuthConfig(); String[] origAuth = authFileContent.get(0).split(" = "); if (origAuth.length != 2) { throw new IOException("Invalid Auth config file"); } config.withAuth(origAuth[1]); String[] origEmail = authFileContent.get(1).split(" = "); if (origEmail.length != 2) { throw new IOException("Invalid Auth config file"); } config.withEmail(origEmail[1]); return new DockerConfigFile(new HashMap<>(Collections.singletonMap(config.getRegistryAddress(), config))); }
@Override public AuthConfig authConfig() { checkNotNull(dockerClientConfig.getRegistryUsername(), "Configured username is null."); checkNotNull(dockerClientConfig.getRegistryUrl(), "Configured serverAddress is null."); return new AuthConfig() .withUsername(dockerClientConfig.getRegistryUsername()) .withPassword(dockerClientConfig.getRegistryPassword()) .withEmail(dockerClientConfig.getRegistryEmail()) .withRegistryAddress(dockerClientConfig.getRegistryUrl()); }
private AuthConfig getAuthConfig() { AuthConfig authConfig = null; if (getRegistryUsername() != null && getRegistryPassword() != null && getRegistryEmail() != null && getRegistryUrl() != null) { authConfig = new AuthConfig() .withUsername(getRegistryUsername()) .withPassword(getRegistryPassword()) .withEmail(getRegistryEmail()) .withRegistryAddress(getRegistryUrl()); } return authConfig; }
@CheckForNull private static DockerConfigFile loadLegacyConfig(String dockerConfigPath) throws IOException { File dockerLegacyCfgFile = new File(dockerConfigPath, DOCKER_LEGACY_CFG); if (!dockerLegacyCfgFile.exists() || !dockerLegacyCfgFile.isFile()) { return null; } //parse legacy auth config file format try { return new DockerConfigFile(MAPPER.<Map<String, AuthConfig>>readValue(dockerLegacyCfgFile, CONFIG_MAP_TYPE)); } catch (IOException e) { // pass } List<String> authFileContent = FileUtils.readLines(dockerLegacyCfgFile, StandardCharsets.UTF_8); if (authFileContent.size() < 2) { throw new IOException("The Auth Config file is empty"); } AuthConfig config = new AuthConfig(); String[] origAuth = authFileContent.get(0).split(" = "); if (origAuth.length != 2) { throw new IOException("Invalid Auth config file"); } config.withAuth(origAuth[1]); String[] origEmail = authFileContent.get(1).split(" = "); if (origEmail.length != 2) { throw new IOException("Invalid Auth config file"); } config.withEmail(origEmail[1]); return new DockerConfigFile(new HashMap<>(Collections.singletonMap(config.getRegistryAddress(), config))); }
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; }
@Override public AuthConfig authConfig() { checkNotNull(dockerClientConfig.getRegistryUsername(), "Configured username is null."); checkNotNull(dockerClientConfig.getRegistryUrl(), "Configured serverAddress is null."); return new AuthConfig() .withUsername(dockerClientConfig.getRegistryUsername()) .withPassword(dockerClientConfig.getRegistryPassword()) .withEmail(dockerClientConfig.getRegistryEmail()) .withRegistryAddress(dockerClientConfig.getRegistryUrl()); }
private void configureBuildCommand(Map<String, Object> params, BuildImageCmd buildImageCmd) { if (params.containsKey(NO_CACHE)) { buildImageCmd.withNoCache((boolean) params.get(NO_CACHE)); } if (params.containsKey(REMOVE)) { buildImageCmd.withRemove((boolean) params.get(REMOVE)); } if (params.containsKey(DOCKERFILE_NAME)) { buildImageCmd.withDockerfile(new File((String) params.get(DOCKERFILE_NAME))); } if(this.dockerClientConfig.getRegistryUsername() != null && this.dockerClientConfig.getRegistryPassword() != null){ AuthConfig buildAuthConfig = new AuthConfig().withUsername(this.dockerClientConfig.getRegistryUsername()) .withPassword(this.dockerClientConfig.getRegistryPassword()) .withEmail(this.dockerClientConfig.getRegistryEmail()) .withRegistryAddress(this.dockerClientConfig.getRegistryUrl()); final AuthConfigurations authConfigurations = new AuthConfigurations(); authConfigurations.addConfig(buildAuthConfig); buildImageCmd.withBuildAuthConfigs(authConfigurations); } }
private void configureBuildCommand(Map<String, Object> params, BuildImageCmd buildImageCmd) { if (params.containsKey(NO_CACHE)) { buildImageCmd.withNoCache((boolean) params.get(NO_CACHE)); } if (params.containsKey(REMOVE)) { buildImageCmd.withRemove((boolean) params.get(REMOVE)); } if (params.containsKey(DOCKERFILE_NAME)) { buildImageCmd.withDockerfile(new File((String) params.get(DOCKERFILE_NAME))); } if(this.dockerClientConfig.getRegistryUsername() != null && this.dockerClientConfig.getRegistryPassword() != null){ AuthConfig buildAuthConfig = new AuthConfig().withUsername(this.dockerClientConfig.getRegistryUsername()) .withPassword(this.dockerClientConfig.getRegistryPassword()) .withEmail(this.dockerClientConfig.getRegistryEmail()) .withRegistryAddress(this.dockerClientConfig.getRegistryUrl()); final AuthConfigurations authConfigurations = new AuthConfigurations(); authConfigurations.addConfig(buildAuthConfig); buildImageCmd.withBuildAuthConfigs(authConfigurations); } }
private AuthConfig getAuthConfig() { AuthConfig authConfig = null; if (getRegistryUsername() != null && getRegistryPassword() != null && getRegistryEmail() != null && getRegistryUrl() != null) { authConfig = new AuthConfig() .withUsername(getRegistryUsername()) .withPassword(getRegistryPassword()) .withEmail(getRegistryEmail()) .withRegistryAddress(getRegistryUrl()); } return authConfig; }
new AuthConfig() .withRegistryAddress(registry.getUrl()) .withEmail(registry.getUserEmail()) .withUsername(registry.getUserName()) .withPassword(registry.getPassword())