com.spotify.docker.client.auth.ConfigFileRegistryAuthSupplier Java Examples

The following examples show how to use com.spotify.docker.client.auth.ConfigFileRegistryAuthSupplier. 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: AbstractDockerMojo.java    From dockerfile-maven with Apache License 2.0 5 votes vote down vote up
@Nonnull
private RegistryAuthSupplier createRegistryAuthSupplier() {
  final List<RegistryAuthSupplier> suppliers = new ArrayList<>();

  if (useMavenSettingsForAuth) {
    suppliers.add(new MavenRegistryAuthSupplier(session.getSettings(), settingsDecrypter));
  }

  if (dockerConfigFile == null || "".equals(dockerConfigFile.getName())) {
    suppliers.add(new ConfigFileRegistryAuthSupplier());
  } else {
    suppliers.add(
        new ConfigFileRegistryAuthSupplier(
          new DockerConfigReader(),
          dockerConfigFile.toPath()
        )
    );
  }
  if (googleContainerRegistryEnabled) {
    try {
      final RegistryAuthSupplier googleSupplier = googleContainerRegistryAuthSupplier();
      if (googleSupplier != null) {
        suppliers.add(0, googleSupplier);
      }
    } catch (IOException ex) {
      getLog().info("Ignoring exception while loading Google credentials", ex);
    }
  } else {
    getLog().info("Google Container Registry support is disabled");
  }

  MavenPomAuthSupplier pomSupplier = new MavenPomAuthSupplier(this.username, this.password);
  if (pomSupplier.hasUserName()) {
    suppliers.add(pomSupplier);
  }

  return new MultiRegistryAuthSupplier(suppliers);
}
 
Example #2
Source File: DefaultDockerClient.java    From docker-client with Apache License 2.0 5 votes vote down vote up
public DefaultDockerClient build() {
  // read the docker config file for auth info if nothing else was specified
  if (registryAuthSupplier == null) {
    registryAuthSupplier(new ConfigFileRegistryAuthSupplier());
  }

  return new DefaultDockerClient(this);
}
 
Example #3
Source File: PushPullIT.java    From docker-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testPushHubPublicImageWithAuthFromConfig() throws Exception {
  // Push an image to a public repo on Docker Hub and check it succeeds
  final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new ConfigFileRegistryAuthSupplier(
          new DockerConfigReader(),
          Paths.get(Resources.getResource("dockerConfig/dxia4Config.json").toURI())))
      .build();

  client.build(Paths.get(dockerDirectory), HUB_PUBLIC_IMAGE);
  client.push(HUB_PUBLIC_IMAGE);
}
 
Example #4
Source File: AbstractDockerMojo.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private RegistryAuthSupplier authSupplier() throws MojoExecutionException {

    final List<RegistryAuthSupplier> suppliers = new ArrayList<>();

    // prioritize the docker config file
    suppliers.add(new ConfigFileRegistryAuthSupplier());

    // then Google Container Registry support
    final RegistryAuthSupplier googleRegistrySupplier = googleContainerRegistryAuthSupplier();
    if (googleRegistrySupplier != null) {
      suppliers.add(googleRegistrySupplier);
    }

    // lastly, use any explicitly configured RegistryAuth as a catch-all
    final RegistryAuth registryAuth = registryAuth();
    if (registryAuth != null) {
      final RegistryConfigs configsForBuild = RegistryConfigs.create(ImmutableMap.of(
          serverIdFor(registryAuth), registryAuth
      ));
      suppliers.add(new FixedRegistryAuthSupplier(registryAuth, configsForBuild));
    }

    getLog().info("Using authentication suppliers: " +
                  Lists.transform(suppliers, new SupplierToClassNameFunction()));

    return new MultiRegistryAuthSupplier(suppliers);
  }