Java Code Examples for com.github.dockerjava.api.model.AuthConfig#withPassword()
The following examples show how to use
com.github.dockerjava.api.model.AuthConfig#withPassword() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryAuthLocator.java From testcontainers-java with MIT License | 6 votes |
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(":", 2); if (splitRawAuth.length == 2) { deserializedAuth.withUsername(splitRawAuth[0]); deserializedAuth.withPassword(splitRawAuth[1]); } } return deserializedAuth; } return null; }
Example 2
Source File: DockerConfigFile.java From docker-java with Apache License 2.0 | 5 votes |
private static void decodeAuth(AuthConfig config) throws IOException { if (config.getAuth() == null) { return; } String str = new String(Base64.getDecoder().decode(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]); }
Example 3
Source File: DockerCloud.java From docker-plugin with MIT License | 5 votes |
@Restricted(NoExternalUse.class) public static AuthConfig getAuthConfig(DockerRegistryEndpoint registry, ItemGroup context) { AuthConfig auth = new AuthConfig(); // we can't use DockerRegistryEndpoint#getToken as this one do check domainRequirement based on registry URL // but in some context (typically, passing registry auth for `docker build`) we just can't guess this one. final Credentials c = firstOrNull(CredentialsProvider.lookupCredentials( IdCredentials.class, context, ACL.SYSTEM, Collections.EMPTY_LIST), withId(registry.getCredentialsId())); final DockerRegistryToken t = c == null ? null : AuthenticationTokens.convert(DockerRegistryToken.class, c); if (t == null) { throw new IllegalArgumentException("Invalid Credential ID " + registry.getCredentialsId()); } final String token = t.getToken(); // What docker-commons claim to be a "token" is actually configuration storage // see https://github.com/docker/docker-ce/blob/v17.09.0-ce/components/cli/cli/config/configfile/file.go#L214 // i.e base64 encoded username : password final String decode = new String(Base64.decodeBase64(token), StandardCharsets.UTF_8); int i = decode.indexOf(':'); if (i > 0) { String username = decode.substring(0, i); auth.withUsername(username); } auth.withPassword(decode.substring(i+1)); if (registry.getUrl() != null) { auth.withRegistryAddress(registry.getUrl()); } return auth; }