@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))); }
@Nonnull public static DockerConfigFile loadConfig(@CheckForNull String dockerConfigPath) throws IOException { // no any configs, but for empty auths return non null object if (dockerConfigPath == null) { return new DockerConfigFile(); } //parse new docker config file format DockerConfigFile dockerConfig = loadCurrentConfig(dockerConfigPath); //parse old auth config file format if (dockerConfig == null) { dockerConfig = loadLegacyConfig(dockerConfigPath); } //otherwise create default config if (dockerConfig == null) { dockerConfig = new DockerConfigFile(); } for (Map.Entry<String, AuthConfig> entry : dockerConfig.getAuths().entrySet()) { AuthConfig authConfig = entry.getValue(); decodeAuth(authConfig); authConfig.withAuth(null); authConfig.withRegistryAddress(entry.getKey()); } return dockerConfig; }
@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))); }
@Nonnull public static DockerConfigFile loadConfig(@CheckForNull String dockerConfigPath) throws IOException { // no any configs, but for empty auths return non null object if (dockerConfigPath == null) { return new DockerConfigFile(); } //parse new docker config file format DockerConfigFile dockerConfig = loadCurrentConfig(dockerConfigPath); //parse old auth config file format if (dockerConfig == null) { dockerConfig = loadLegacyConfig(dockerConfigPath); } //otherwise create default config if (dockerConfig == null) { dockerConfig = new DockerConfigFile(); } for (Map.Entry<String, AuthConfig> entry : dockerConfig.getAuths().entrySet()) { AuthConfig authConfig = entry.getValue(); decodeAuth(authConfig); authConfig.withAuth(null); authConfig.withRegistryAddress(entry.getKey()); } return dockerConfig; }