Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore unknown properties in .docker/config.json #524

Merged
merged 1 commit into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
public class DockerConfigTemplate implements JsonTemplate {

/** Template for an {@code auth} defined for a registry under {@code auths}. */
@JsonIgnoreProperties(ignoreUnknown = true)
private static class AuthTemplate implements JsonTemplate {

@Nullable private String auth;
Expand All @@ -82,10 +83,15 @@ private static class AuthTemplate implements JsonTemplate {
*/
@Nullable
public String getAuthFor(String registry) {
if (!auths.containsKey(registry)) {
return null;
AuthTemplate registryAuth = auths.get(registry);
if (registryAuth == null) {
// The registry could be prefixed with the HTTPS protocol.
registryAuth = auths.get("https://" + registry);
}
if (registryAuth != null) {
return registryAuth.auth;
}
return auths.get(registry).auth;
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public void test_fromJson() throws URISyntaxException, IOException {

Assert.assertEquals("some auth", dockerConfigTemplate.getAuthFor("some registry"));
Assert.assertEquals("some other auth", dockerConfigTemplate.getAuthFor("some other registry"));
Assert.assertEquals("token", dockerConfigTemplate.getAuthFor("registry"));
Assert.assertEquals("token", dockerConfigTemplate.getAuthFor("https://registry"));
Assert.assertEquals(null, dockerConfigTemplate.getAuthFor("just registry"));

Assert.assertEquals(
Expand Down
2 changes: 1 addition & 1 deletion jib-core/src/test/resources/json/dockerconfig.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"auths":{"some other registry":{"auth":"some other auth"},"some registry":{"auth":"some auth"},"just registry":{},"https://with.protocol":{}},"credsStore":"some credential store","credHelpers":{"another registry":"another credential helper","some registry":"some credential helper"}}
{"auths":{"some other registry":{"auth":"some other auth"},"some registry":{"auth":"some auth","password":"ignored"},"https://registry":{"auth":"token"},"just registry":{},"https://with.protocol":{}},"credsStore":"some credential store","credHelpers":{"another registry":"another credential helper","some registry":"some credential helper"}}