Skip to content

Commit

Permalink
refactor: Minor cleanup + added to changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Nov 3, 2017
1 parent cd6545e commit d42f766
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

* **0.22-SNAPSHOT**
- Support relative paths when binding volumes in `docker-compose.yml` (#846)
- Allo the session token for AWS authetication to be oncluded in order to allow temporary security credentials provided by the AWS Security Token Service (AWS STS) to sign requests (#883)
- Allow the session token for AWS authetication to be oncluded in order to allow temporary security credentials provided by the AWS Security Token Service (AWS STS) to sign requests (#883)
- Add support for credential helper to authenticate against a registry (#821)

* **0.22.1** (2017-08-28)
- Allow Docker compose version "2", too ([#829](https://github.com/fabric8io/docker-maven-plugin/issues/829))
Expand Down
38 changes: 21 additions & 17 deletions src/main/java/io/fabric8/maven/docker/util/AuthConfigFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,36 +317,40 @@ private AuthConfig getAuthConfigFromDockerConfig(String registry) throws MojoExe
if (dockerConfig.has("credHelpers")) {
final JSONObject credHelpers = dockerConfig.getJSONObject("credHelpers");
if (credHelpers.has(registryToLookup)) {
CredentialHelperClient credentialHelper = new CredentialHelperClient(log,credHelpers.getString(registryToLookup));
log.debug("AuthConfig: credentials from credential helper %s version %s",credentialHelper.getName(),credentialHelper.getVersion());

// "The default credential store will not be used for operations concerning credentials of the specified registries."
return credentialHelper.getCredentialNode(registryToLookup);
return extractAuthConfigFromCredentialsHelper(registryToLookup, credHelpers.getString(registryToLookup));
}
}
if (dockerConfig.has("credsStore")) {
CredentialHelperClient credentialStore = new CredentialHelperClient(log,dockerConfig.getString("credsStore"));
log.debug("AuthConfig: credentials from credentials store %s version %s",credentialStore.getName(),credentialStore.getVersion());

return credentialStore.getCredentialNode(registryToLookup);
return extractAuthConfigFromCredentialsHelper(registryToLookup, dockerConfig.getString("credsStore"));
}
return null;
}

if (dockerConfig.has("auths")) {
JSONObject auths = dockerConfig.getJSONObject("auths");
JSONObject credentials = getCredentialsNode(auths,registryToLookup);
if (credentials == null || !credentials.has("auth")) {
return null;
}
String auth = credentials.getString("auth");
String email = credentials.has("email") ? credentials.getString("email") : null;
return new AuthConfig(auth,email);
return extractAuthConfigFromAuths(registryToLookup, dockerConfig.getJSONObject("auths"));
}

return null;
}

private AuthConfig extractAuthConfigFromAuths(String registryToLookup, JSONObject auths) {
JSONObject credentials = getCredentialsNode(auths,registryToLookup);
if (credentials == null || !credentials.has("auth")) {
return null;
}
String auth = credentials.getString("auth");
String email = credentials.has("email") ? credentials.getString("email") : null;
return new AuthConfig(auth,email);
}

private AuthConfig extractAuthConfigFromCredentialsHelper(String registryToLookup, String credConfig) throws MojoExecutionException {
CredentialHelperClient credentialHelper = new CredentialHelperClient(log, credConfig);
log.debug("AuthConfig: credentials from credential helper/store %s version %s",
credentialHelper.getName(),
credentialHelper.getVersion());
return credentialHelper.getAuthConfig(registryToLookup);
}

private JSONObject getCredentialsNode(JSONObject auths,String registryToLookup) {
if (auths.has(registryToLookup)) {
return auths.getJSONObject(registryToLookup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CredentialHelperClient {
private final String credentialHelperName;
private final Logger log;

public CredentialHelperClient(Logger log,String credentialsStore) {
public CredentialHelperClient(Logger log, String credentialsStore) {
this.log = log;
credentialHelperName = "docker-credential-" + credentialsStore;
}
Expand All @@ -32,7 +32,7 @@ public String getVersion() throws MojoExecutionException {
}
}

public AuthConfig getCredentialNode(String registryToLookup) throws MojoExecutionException {
public AuthConfig getAuthConfig(String registryToLookup) throws MojoExecutionException {
try {
final GetCommand getCommand = new GetCommand();
return toAuthConfig(getCommand.getCredentialNode("https://" + registryToLookup));
Expand Down

0 comments on commit d42f766

Please sign in to comment.