Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
Fixes #580 - support identityToken based repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
scheerer authored and mattnworb committed Feb 3, 2017
1 parent c6e752d commit 55b993d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ public abstract class RegistryAuth {
@JsonProperty("ServerAddress")
public abstract String serverAddress();

@Override
@Nullable
@JsonProperty("IdentityToken")
public abstract String identityToken();

public final String toString() {
return MoreObjects.toStringHelper(this)
.add("username", username())
// don't log the password or email
.add("serverAddress", serverAddress())
.add("identityToken", identityToken())
.toString();
}

Expand Down Expand Up @@ -187,6 +191,9 @@ private static RegistryAuth.Builder parseDockerConfig(final Path configPath, Str
if (authParams.length == 2) {
authBuilder.username(authParams[0].trim());
authBuilder.password(authParams[1].trim());
} else if (serverAuth.has("identityToken")) {
authBuilder.identityToken(serverAuth.get("identityToken").asText());
return authBuilder;
} else {
LOG.warn("Failed to parse auth string for {}", serverAddress);
return authBuilder;
Expand Down Expand Up @@ -230,6 +237,8 @@ public abstract static class Builder {

public abstract Builder serverAddress(final String serverAddress);

public abstract Builder identityToken(final String token);

public abstract RegistryAuth build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ public class RegistryAuthTest {
.password("sw4gy0lo")
.email("[email protected]")
.build();

private static final RegistryAuth MY_AUTH_CONFIG = RegistryAuth.builder()
.serverAddress("https://narnia.mydock.io/v1/")
.username("megaman")
.password("riffraff")
.email("[email protected]")
.build();

private static final RegistryAuth IDENTITY_TOKEN_AUTH_CONFIG = RegistryAuth.builder()
.serverAddress("docker.customdomain.com")
.identityToken("52ce5fd5-eb60-42bf-931f-5eeec128211a")
.build();

private static final RegistryAuth EMPTY_AUTH_CONFIG = RegistryAuth.builder().build();

@Rule
Expand All @@ -69,6 +76,13 @@ public void testFromDockerConfig_FullDockerCfg() throws Exception {
assertThat(registryAuth, equalTo(DOCKER_AUTH_CONFIG));
}

@Test
public void testFromDockerConfig_IdentityToken() throws Exception {
final RegistryAuth authConfig = RegistryAuth.fromDockerConfig(getTestFilePath(
"dockerConfig/identityTokenConfig.json")).build();
assertThat(authConfig, equalTo(IDENTITY_TOKEN_AUTH_CONFIG));
}

@Test
public void testFromDockerConfig_IncompleteConfig() throws Exception {
final RegistryAuth registryAuth = RegistryAuth.fromDockerConfig(getTestFilePath(
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/dockerConfig/identityTokenConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"auths": {
"docker.customdomain.com": {
"auth": "ZG9ja2VybWFuOg==",
"email": "[email protected]",
"identityToken": "52ce5fd5-eb60-42bf-931f-5eeec128211a"
}
}
}

0 comments on commit 55b993d

Please sign in to comment.