Class ContainerRegistryAuthSupplier
- java.lang.Object
-
- org.mandas.docker.client.auth.gcr.ContainerRegistryAuthSupplier
-
- All Implemented Interfaces:
RegistryAuthSupplier
public class ContainerRegistryAuthSupplier extends Object implements RegistryAuthSupplier
A RegistryAuthSupplier for getting access tokens from a Google Cloud Platform service or user account. This implementation uses the google-auth-library-oauth2-http library to get an access token given an account's credentials, and will refresh the token if it expires within a configurable amount of time.To construct a new instance, use
fromStream(InputStream)
to get aContainerRegistryAuthSupplier.Builder
if you have credentials for the account to use, or you can useforApplicationDefaultCredentials()
if you would like to use the Application Default Credentials.The scopes used to fetch an access token and the minimum expiry time can be configured via the Builder before calling
ContainerRegistryAuthSupplier.Builder.build()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ContainerRegistryAuthSupplier.Builder
A Builder of ContainerRegistryAuthSupplier.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistryAuth
authFor(String imageName)
Returns a RegistryAuth object that works with a given registry's API [e.g.RegistryConfigs
authForBuild()
Authentication info to pass in the X-Registry-Config header when building an image.RegistryAuth
authForSwarm()
Returns a RegistryAuth object that is valid for a Docker Swarm context [i.e.static ContainerRegistryAuthSupplier.Builder
forApplicationDefaultCredentials()
Constructs a ContainerRegistryAuthSupplier using the Application Default Credentials.static ContainerRegistryAuthSupplier.Builder
forCredentials(com.google.auth.oauth2.GoogleCredentials credentials)
Constructs a ContainerRegistryAuthSupplier using the specified credentials.static ContainerRegistryAuthSupplier.Builder
fromStream(InputStream credentialsStream)
Constructs a ContainerRegistryAuthSupplier for the account with the given credentials.
-
-
-
Method Detail
-
fromStream
public static ContainerRegistryAuthSupplier.Builder fromStream(InputStream credentialsStream) throws IOException
Constructs a ContainerRegistryAuthSupplier for the account with the given credentials.- Parameters:
credentialsStream
- the credentials stream- Returns:
- a new
ContainerRegistryAuthSupplier.Builder
- Throws:
IOException
- when an error occured when reading from stream- See Also:
ContainerRegistryAuthSupplier.Builder
-
forApplicationDefaultCredentials
public static ContainerRegistryAuthSupplier.Builder forApplicationDefaultCredentials() throws IOException
Constructs a ContainerRegistryAuthSupplier using the Application Default Credentials.- Returns:
- a new
ContainerRegistryAuthSupplier.Builder
- Throws:
IOException
- when an error occured when reading from stream- See Also:
ContainerRegistryAuthSupplier.Builder
-
forCredentials
public static ContainerRegistryAuthSupplier.Builder forCredentials(com.google.auth.oauth2.GoogleCredentials credentials)
Constructs a ContainerRegistryAuthSupplier using the specified credentials.- Parameters:
credentials
- the google credentials- Returns:
- a new
ContainerRegistryAuthSupplier.Builder
- See Also:
ContainerRegistryAuthSupplier.Builder
-
authFor
public RegistryAuth authFor(String imageName) throws DockerException
Description copied from interface:RegistryAuthSupplier
Returns a RegistryAuth object that works with a given registry's API [e.g. GCR].- Specified by:
authFor
in interfaceRegistryAuthSupplier
- Returns:
- the RegistryAuth to use when working with the image, or else
null
if no authentication info applies for this image - Throws:
DockerException
-
authForSwarm
public RegistryAuth authForSwarm() throws DockerException
Description copied from interface:RegistryAuthSupplier
Returns a RegistryAuth object that is valid for a Docker Swarm context [i.e. not tied to specific image]. It's unnecessary if it's not planned to use this AuthSupplier to pull images for Swarm.- Specified by:
authForSwarm
in interfaceRegistryAuthSupplier
- Returns:
- the RegistryAuth to use in Swarn, or else
null
for no authentication info - Throws:
DockerException
-
authForBuild
public RegistryConfigs authForBuild() throws DockerException
Description copied from interface:RegistryAuthSupplier
Authentication info to pass in the X-Registry-Config header when building an image.- Specified by:
authForBuild
in interfaceRegistryAuthSupplier
- Returns:
- the registry configs
- Throws:
DockerException
-
-