private static void decodeAuth(AuthConfig config) throws IOException { if (config.getAuth() == null) { return; } String str = new String(Base64.decodeBase64(config.getAuth()), StandardCharsets.UTF_8); String[] parts = str.split(":", 2); if (parts.length != 2) { throw new IOException("Invalid auth configuration file"); } config.withUsername(parts[0]); config.withPassword(parts[1]); }
private AuthConfig findExistingAuthConfig(final JsonNode config, final String reposName) throws Exception { final Map.Entry<String, JsonNode> entry = findAuthNode(config, reposName); if (entry != null && entry.getValue() != null && entry.getValue().size() > 0) { final AuthConfig deserializedAuth = OBJECT_MAPPER .treeToValue(entry.getValue(), AuthConfig.class) .withRegistryAddress(entry.getKey()); if (isBlank(deserializedAuth.getUsername()) && isBlank(deserializedAuth.getPassword()) && !isBlank(deserializedAuth.getAuth())) { final String rawAuth = new String(Base64.getDecoder().decode(deserializedAuth.getAuth())); final String[] splitRawAuth = rawAuth.split(":"); if (splitRawAuth.length == 2) { deserializedAuth.withUsername(splitRawAuth[0]); deserializedAuth.withPassword(splitRawAuth[1]); } } return deserializedAuth; } return null; }
.withUsername(helperResponse.at("/Username").asText()) .withPassword(helperResponse.at("/Secret").asText());
@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; }
@Test public void testThatAuthLocatorIsUsed() throws Exception { final DockerImageName expectedName = new DockerImageName(testImageNameWithTag); final AuthConfig authConfig = new AuthConfig() .withUsername("testuser") .withPassword("notasecret") .withRegistryAddress("http://" + testRegistryAddress); // Replace the RegistryAuthLocator singleton with our mock, for the duration of this test final RegistryAuthLocator mockAuthLocator = Mockito.mock(RegistryAuthLocator.class); RegistryAuthLocator.setInstance(mockAuthLocator); when(mockAuthLocator.lookupAuthConfig(eq(expectedName), any())) .thenReturn(authConfig); // a push will use the auth locator for authentication, although that isn't the goal of this test putImageInRegistry(); // actually start a container, which will require an authenticated pull try (final GenericContainer container = new GenericContainer<>(testImageNameWithTag) .withCommand("/bin/sh", "-c", "sleep 10")) { container.start(); assertTrue("container started following an authenticated pull", container.isRunning()); } }
private static void decodeAuth(AuthConfig config) throws IOException { if (config.getAuth() == null) { return; } String str = new String(Base64.decodeBase64(config.getAuth()), StandardCharsets.UTF_8); String[] parts = str.split(":", 2); if (parts.length != 2) { throw new IOException("Invalid auth configuration file"); } config.withUsername(parts[0]); config.withPassword(parts[1]); }
private AuthConfig findExistingAuthConfig(final JsonNode config, final String reposName) throws Exception { final Map.Entry<String, JsonNode> entry = findAuthNode(config, reposName); if (entry != null && entry.getValue() != null && entry.getValue().size() > 0) { final AuthConfig deserializedAuth = OBJECT_MAPPER .treeToValue(entry.getValue(), AuthConfig.class) .withRegistryAddress(entry.getKey()); if (isBlank(deserializedAuth.getUsername()) && isBlank(deserializedAuth.getPassword()) && !isBlank(deserializedAuth.getAuth())) { final String rawAuth = new String(Base64.getDecoder().decode(deserializedAuth.getAuth())); final String[] splitRawAuth = rawAuth.split(":"); if (splitRawAuth.length == 2) { deserializedAuth.withUsername(splitRawAuth[0]); deserializedAuth.withPassword(splitRawAuth[1]); } } return deserializedAuth; } 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; }
@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); } }
if (i > 0) { String username = decode.substring(0, i); auth.withUsername(username);
.withUsername(helperResponse.at("/Username").asText()) .withPassword(helperResponse.at("/Secret").asText());
/** * Pull docker image using the docker java client. * * @param imageTag * @param username * @param password * @param host */ public static void pullImage(String imageTag, String username, String password, String host) throws IOException { final AuthConfig authConfig = new AuthConfig(); authConfig.withUsername(username); authConfig.withPassword(password); DockerClient dockerClient = null; try { dockerClient = getDockerClient(host); dockerClient.pullImageCmd(imageTag).withAuthConfig(authConfig).exec(new PullImageResultCallback()).awaitSuccess(); } finally { closeQuietly(dockerClient); } }
/** * Push docker image using the docker java client. * * @param imageTag * @param username * @param password * @param host */ public static void pushImage(String imageTag, String username, String password, String host) throws IOException { final AuthConfig authConfig = new AuthConfig(); authConfig.withUsername(username); authConfig.withPassword(password); DockerClient dockerClient = null; try { dockerClient = getDockerClient(host); dockerClient.pushImageCmd(imageTag).withAuthConfig(authConfig).exec(new PushImageResultCallback()).awaitSuccess(); } finally { closeQuietly(dockerClient); } }
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; }
.withRegistryAddress(registry.getUrl()) .withEmail(registry.getUserEmail()) .withUsername(registry.getUserName()) .withPassword(registry.getPassword()) );