Class DockerCredentialHelper

java.lang.Object
org.mandas.docker.client.DockerCredentialHelper

public class DockerCredentialHelper extends Object
This class interacts with a docker credential helper. See https://github.com/docker/docker-credential-helpers.

The credential helpers are platform-specific ways of storing and retrieving registry auth information. Docker ships with OS-specific implementations, such as osxkeychain and wincred, as well as others. But they also allow third parties to implement their own credential helpers; for instance, Google (https://github.com/GoogleCloudPlatform/docker-credential-gcr) and Amazon (https://github.com/awslabs/amazon-ecr-credential-helper) have implementations for their cloud registries.

The main interface to this class is in four static methods, which perform the four operations of a credential helper: get(String, String), list(String), store(String, DockerCredentialHelperAuth), and erase(String, String). They all take the name of the credential helper as an argument; this value is usually read as the credsStore or a credsHelper from a docker config file (see DockerConfig).

The static methods all pass their operations down to a DockerCredentialHelper.CredentialHelperDelegate instance. By default this instance executes a command on the system. However, the delegate is modifiable with setCredentialHelperDelegate(CredentialHelperDelegate) and restoreSystemCredentialHelperDelegate() to facilitate testing.

  • Constructor Details

    • DockerCredentialHelper

      public DockerCredentialHelper()
  • Method Details

    • store

      public static int store(String credsStore, DockerCredentialHelperAuth auth) throws IOException, InterruptedException
      Store an auth value in the credsStore.
      Parameters:
      credsStore - Name of the docker credential helper
      auth - Auth object to store
      Returns:
      Exit code of the process
      Throws:
      IOException - When we cannot read from the credential helper
      InterruptedException - When writing to the credential helper is interrupted
    • erase

      public static int erase(String credsStore, String registry) throws IOException, InterruptedException
      Erase an auth value from a credsStore matching a registry.
      Parameters:
      credsStore - Name of the docker credential helper
      registry - The registry for which you want to erase the auth
      Returns:
      Exit code of the process
      Throws:
      IOException - When we cannot read from the credential helper
      InterruptedException - When writing to the credential helper is interrupted
    • get

      public static DockerCredentialHelperAuth get(String credsStore, String registry) throws IOException
      Get an auth value from a credsStore for a registry.
      Parameters:
      credsStore - Name of the docker credential helper
      registry - The registry for which you want to auth
      Returns:
      A DockerCredentialHelperAuth auth object
      Throws:
      IOException - When we cannot read from the credential helper
    • list

      public static Map<String,String> list(String credsStore) throws IOException
      Lists credentials stored in the credsStore.
      Parameters:
      credsStore - Name of the docker credential helper
      Returns:
      Map of registries to auth identifiers. (For instance, usernames for which you have signed in.)
      Throws:
      IOException - When we cannot read from the credential helper