use of com.google.cloud.tools.jib.registry.credentials.NonexistentDockerCredentialHelperException in project jib by google.
the class RetrieveRegistryCredentialsStep method call.
@Override
@Nullable
public Authorization call() throws IOException, NonexistentDockerCredentialHelperException {
try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), String.format(DESCRIPTION, buildConfiguration.getTargetRegistry()))) {
// Tries to get registry credentials from Docker credential helpers.
for (String credentialHelperSuffix : buildConfiguration.getCredentialHelperNames()) {
Authorization authorization = retrieveFromCredentialHelper(credentialHelperSuffix);
if (authorization != null) {
return authorization;
}
}
// Tries to get registry credentials from known registry credentials.
String credentialSource = buildConfiguration.getKnownRegistryCredentials().getCredentialSource(registry);
if (credentialSource != null) {
logGotCredentialsFrom(credentialSource);
return buildConfiguration.getKnownRegistryCredentials().getAuthorization(registry);
}
// Tries to get registry credentials from the Docker config.
try {
Authorization dockerConfigAuthorization = dockerConfigCredentialRetriever.retrieve();
if (dockerConfigAuthorization != null) {
buildConfiguration.getBuildLogger().info("Using credentials from Docker config for " + registry);
return dockerConfigAuthorization;
}
} catch (IOException ex) {
buildConfiguration.getBuildLogger().info("Unable to parse Docker config");
}
// Tries to infer common credential helpers for known registries.
for (String registrySuffix : COMMON_CREDENTIAL_HELPERS.keySet()) {
if (registry.endsWith(registrySuffix)) {
try {
String commonCredentialHelper = COMMON_CREDENTIAL_HELPERS.get(registrySuffix);
if (commonCredentialHelper == null) {
throw new IllegalStateException("No COMMON_CREDENTIAL_HELPERS should be null");
}
Authorization authorization = retrieveFromCredentialHelper(commonCredentialHelper);
if (authorization != null) {
return authorization;
}
} catch (NonexistentDockerCredentialHelperException ex) {
if (ex.getMessage() != null) {
// Warns the user that the specified (or inferred) credential helper is not on the
// system.
buildConfiguration.getBuildLogger().warn(ex.getMessage());
}
}
}
}
/*
* If no credentials found, give an info (not warning because in most cases, the base image is
* public and does not need extra credentials) and return null.
*/
buildConfiguration.getBuildLogger().info("No credentials could be retrieved for registry " + registry);
return null;
}
}
Aggregations