final RegistryAuth empty = RegistryAuth.builder().build(); registryAuth.toBuilder().serverAddress(registry).build());
@JsonCreator public static RegistryAuth create(@JsonProperty("username") final String username, @JsonProperty("password") final String password, @JsonProperty("email") final String email, @JsonProperty("serveraddress") final String serveraddress, @JsonProperty("identitytoken") final String identitytoken, @JsonProperty("auth") final String auth) { final Builder builder; if (auth != null) { builder = forAuth(auth); } else { builder = builder() .username(username) .password(password); } return builder .email(email) .serverAddress(serveraddress) .identityToken(identitytoken) .build(); }
return RegistryAuth.builder().build();
@Override public DefaultDockerClient.Builder configure(TestContext testContext, VirtualResource virtualResource, PropertiesReader configReader) { try { DefaultDockerClient.Builder builder = DefaultDockerClient.fromEnv(); PropertiesReader reader = configReader; if (reader.isEmpty()) { reader = testContext.getPropertiesReader(DEFAULT_CONFIG_KEY); } if (!reader.isEmpty()) { RegistryAuth registryAuth = RegistryAuth.builder() .serverAddress(reader.getProperty("uri")) .email(reader.getProperty("email")) .username(reader.getProperty("username")) .password(reader.getProperty("password")) .build(); RegistryAuthSupplier dockerHubAuthSupplier = new DockerHubRegistryAuthSupplier(registryAuth); //TODO: explore making these configuration configurable via .testify.yml file builder.registryAuthSupplier(dockerHubAuthSupplier) .connectTimeoutMillis(10000) .connectionPoolSize(16); } return builder; } catch (DockerCertificateException e) { throw ExceptionUtil.INSTANCE.propagate(e); } }
@JsonCreator public static RegistryAuth create(@JsonProperty("username") final String username, @JsonProperty("password") final String password, @JsonProperty("email") final String email, @JsonProperty("serveraddress") final String serveraddress, @JsonProperty("identitytoken") final String identitytoken, @JsonProperty("auth") final String auth) { final Builder builder; if (auth != null) { builder = forAuth(auth); } else { builder = builder() .username(username) .password(password); } return builder .email(email) .serverAddress(serveraddress) .identityToken(identitytoken) .build(); }
private static RegistryAuth getRegistryAuth(final DockerClientConfig config) { try { final String[] segments = config.getImageName().split("\\/"); if (segments.length > 0) { try { return RegistryAuth.fromDockerConfig(segments[0]).build(); } catch (IOException e) { return null; } } } catch (Exception ex) { return null; } return null; } }
public DefaultDockerClient build() { if (dockerAuth && registryAuthSupplier == null && registryAuth == null) { try { registryAuth(RegistryAuth.fromDockerConfig().build()); } catch (IOException e) { log.warn("Unable to use Docker auth info", e); } } // read the docker config file for auth info if nothing else was specified if (registryAuthSupplier == null) { registryAuthSupplier(new ConfigFileRegistryAuthSupplier()); } return new DefaultDockerClient(this); } }
/** Construct a Builder based upon the "auth" field of the docker client config file. */ public static Builder forAuth(final String auth) { // split with limit=2 to catch case where password contains a colon final String[] authParams = Base64.decodeAsString(auth).split(":", 2); if (authParams.length != 2) { return builder(); } return builder() .username(authParams[0].trim()) .password(authParams[1].trim()); }
@Provides @Singleton public DockerClient providesDockerClient(SingularityExecutorConfiguration configuration) { Builder dockerClientBuilder = DefaultDockerClient.builder() .uri(URI.create("unix://localhost/var/run/docker.sock")) .connectionPoolSize(configuration.getDockerClientConnectionPoolSize()); if(configuration.getDockerAuthConfig().isPresent()) { SingularityExecutorDockerAuthConfig authConfig = configuration.getDockerAuthConfig().get(); if(authConfig.isFromDockerConfig()) { try { dockerClientBuilder.registryAuth(RegistryAuth.fromDockerConfig().build()); } catch(IOException e) { throw Throwables.propagate(e); } } else { dockerClientBuilder.registryAuth(RegistryAuth.builder() .email(authConfig.getEmail()) .username(authConfig.getUsername()) .password(authConfig.getPassword()) .serverAddress(authConfig.getServerAddress()) .build()); } } return dockerClientBuilder.build(); }
return RegistryAuth.builder().build();
/** * Return a single RegistryAuth from the config file. * If there are multiple RegistryAuth entries, which entry is returned from this method * depends on hashing and should not be considered reliable. * If there is only one entry, however, that will be the one returned. This is the * primary use of this method, as a useful way to extract a RegistryAuth during testing. * In that environment, the contents of the config file are known and controlled. In a * production environment, the contents of the config file are less predictable. * * @param configPath Path to the docker config file. * @return Some registry auth value. */ @VisibleForTesting RegistryAuth anyRegistryAuth(final Path configPath) throws IOException { final ImmutableCollection<RegistryAuth> registryAuths = authForAllRegistries(configPath).configs().values(); return registryAuths.isEmpty() ? RegistryAuth.builder().build() : registryAuths.iterator().next(); }
private RegistryAuth createRegistryAuth(Server server) throws DockerException { SettingsDecryptionRequest decryptionRequest = new DefaultSettingsDecryptionRequest(server); SettingsDecryptionResult decryptionResult = settingsDecrypter.decrypt(decryptionRequest); if (decryptionResult.getProblems().isEmpty()) { log.debug("Successfully decrypted Maven server password"); } else { for (SettingsProblem problem : decryptionResult.getProblems()) { log.error("Settings problem for server {}: {}", server.getId(), problem); } throw new DockerException("Failed to decrypt Maven server password"); } return RegistryAuth.builder() .username(server.getUsername()) .password(decryptionResult.getServer().getPassword()) .build(); } }
private RegistryAuth authForRegistry(final DockerConfig config, final String registry) throws IOException { // If the registry shows up in "auths", return it final Map<String, RegistryAuth> auths = config.auths(); if (auths != null && auths.get(registry) != null) { return auths.get(registry).toBuilder().serverAddress(registry).build(); } // Else, we use a credential helper. final String credsStore = getCredentialStore(config, registry); if (credsStore != null) { return authWithCredentialHelper(credsStore, registry); } return null; }
/** Construct a Builder based upon the "auth" field of the docker client config file. */ public static Builder forAuth(final String auth) { // split with limit=2 to catch case where password contains a colon final String[] authParams = Base64.decodeAsString(auth).split(":", 2); if (authParams.length != 2) { return builder(); } return builder() .username(authParams[0].trim()) .password(authParams[1].trim()); }
@JsonIgnore public RegistryAuth toRegistryAuth() { return RegistryAuth.builder() .username(username()) .password(secret()) .serverAddress(serverUrl()) .build(); } }