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

Commit

Permalink
RegistryAuth: add method for building from auth token
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnworb committed May 23, 2017
1 parent 246f6a1 commit 9d65790
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/main/java/com/spotify/docker/client/messages/RegistryAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,13 @@ public static RegistryAuth create(@JsonProperty("username") String username,
@JsonProperty("identityToken") final String identityToken,
@JsonProperty("auth") final String auth) {

final Builder builder;
if (auth != null) {
final String[] authParams = Base64.decodeAsString(auth).split(":");

if (authParams.length == 2) {
username = authParams[0].trim();
password = authParams[1].trim();
}
builder = forAuthToken(auth);
} else {
builder = builder();
}
return builder()
return builder
.username(username)
.password(password)
.email(email)
Expand All @@ -161,6 +159,21 @@ public static RegistryAuth create(@JsonProperty("username") String username,
.build();
}

/** Construct a Builder based upon the "auth" field of the docker client config file. */
public static Builder forAuthToken(String auth) {
final String[] authParams = Base64.decodeAsString(auth).split(":");

if (authParams.length != 2) {
throw new IllegalArgumentException(
"auth token does not appear to be properly formatted after base64 decoding, "
+ "did not find two values separated by a colon: "
+ auth);
}
return builder()
.username(authParams[0].trim())
.password(authParams[1].trim());
}

public static Builder builder() {
return new AutoValue_RegistryAuth.Builder();
}
Expand Down

0 comments on commit 9d65790

Please sign in to comment.