Skip to content

Commit 27662f8

Browse files
dgageotcoollog
authored andcommitted
Ignore unknown properties in .docker/config.json (GoogleContainerTools#524)
Also search the auth information with an `https://` prefix the same way we do for credential helpers
1 parent 1495946 commit 27662f8

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎jib-core/src/main/java/com/google/cloud/tools/jib/registry/credentials/json/DockerConfigTemplate.java‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
public class DockerConfigTemplate implements JsonTemplate {
6363

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

6768
@Nullable private String auth;
@@ -82,10 +83,15 @@ private static class AuthTemplate implements JsonTemplate {
8283
*/
8384
@Nullable
8485
public String getAuthFor(String registry) {
85-
if (!auths.containsKey(registry)) {
86-
return null;
86+
AuthTemplate registryAuth = auths.get(registry);
87+
if (registryAuth == null) {
88+
// The registry could be prefixed with the HTTPS protocol.
89+
registryAuth = auths.get("https://" + registry);
90+
}
91+
if (registryAuth != null) {
92+
return registryAuth.auth;
8793
}
88-
return auths.get(registry).auth;
94+
return null;
8995
}
9096

9197
/**

‎jib-core/src/test/java/com/google/cloud/tools/jib/registry/credentials/json/DockerConfigTemplateTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public void test_fromJson() throws URISyntaxException, IOException {
3939

4040
Assert.assertEquals("some auth", dockerConfigTemplate.getAuthFor("some registry"));
4141
Assert.assertEquals("some other auth", dockerConfigTemplate.getAuthFor("some other registry"));
42+
Assert.assertEquals("token", dockerConfigTemplate.getAuthFor("registry"));
43+
Assert.assertEquals("token", dockerConfigTemplate.getAuthFor("https://registry"));
4244
Assert.assertEquals(null, dockerConfigTemplate.getAuthFor("just registry"));
4345

4446
Assert.assertEquals(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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"}}
1+
{"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"}}

0 commit comments

Comments
 (0)