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), anderase(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 (seeDockerConfig).The static methods all pass their operations down to a
DockerCredentialHelper.CredentialHelperDelegateinstance. By default this instance executes a command on the system. However, the delegate is modifiable withsetCredentialHelperDelegate(CredentialHelperDelegate)andrestoreSystemCredentialHelperDelegate()to facilitate testing.
-
-
Constructor Summary
Constructors Constructor Description DockerCredentialHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static interase(String credsStore, String registry)Erase an auth value from a credsStore matching a registry.static DockerCredentialHelperAuthget(String credsStore, String registry)Get an auth value from a credsStore for a registry.static Map<String,String>list(String credsStore)Lists credentials stored in the credsStore.static intstore(String credsStore, DockerCredentialHelperAuth auth)Store an auth value in the credsStore.
-
-
-
Method Detail
-
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 helperauth- Auth object to store- Returns:
- Exit code of the process
- Throws:
IOException- When we cannot read from the credential helperInterruptedException- 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 helperregistry- 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 helperInterruptedException- 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 helperregistry- The registry for which you want to auth- Returns:
- A
DockerCredentialHelperAuthauth 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
-
-