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

Commit

Permalink
Merge pull request #1051 from johnflavin/creds
Browse files Browse the repository at this point in the history
Refactor Config-file-based auth
  • Loading branch information
mattnworb authored Aug 23, 2018
2 parents 91dd548 + d2ede02 commit 6ea96c5
Show file tree
Hide file tree
Showing 17 changed files with 753 additions and 364 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
Not released yet

- Make ContainerState.exitCode() return a Long instead of Integer ([1052][])
- Refactor authentication with docker config.json file ([1051][])
- Add support for `credsHelper` (Fixes [1037][])
- Improve support for authenticating with multiple registries (Fixes [1042][])

[1037]: https://github.com/spotify/docker-client/issues/1037
[1042]: https://github.com/spotify/docker-client/issues/1042
[1051]: https://github.com/spotify/docker-client/issues/1051
[1052]: https://github.com/spotify/docker-client/issues/1052

## 8.11.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3166,14 +3166,6 @@ public RequestEntityProcessing getRequestEntityProcessing() {
}

public DefaultDockerClient build() {
if (dockerAuth && registryAuthSupplier == null && registryAuth == null) {
try {
registryAuth(RegistryAuth.fromDockerConfig().build());
} catch (IOException e) {
log.warn("Unable to use Docker auth info", e);
}
}

// read the docker config file for auth info if nothing else was specified
if (registryAuthSupplier == null) {
registryAuthSupplier(new ConfigFileRegistryAuthSupplier());
Expand Down
101 changes: 101 additions & 0 deletions src/main/java/com/spotify/docker/client/DockerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*-
* -\-\-
* docker-client
* --
* Copyright (C) 2016 - 2018 Spotify AB
* --
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* -/-/-
*/

package com.spotify.docker.client;

import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
import com.spotify.docker.client.messages.RegistryAuth;

import java.util.Map;
import javax.annotation.Nullable;

/**
* Represents the contents of the docker config.json file.
*/
@AutoValue
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE)
public abstract class DockerConfig {

@Nullable
@JsonProperty("credsHelpers")
public abstract ImmutableMap<String, String> credsHelpers();

@Nullable
@JsonProperty("auths")
public abstract ImmutableMap<String, RegistryAuth> auths();

@Nullable
@JsonProperty("HttpHeaders")
public abstract ImmutableMap<String, String> httpHeaders();

@Nullable
@JsonProperty("credsStore")
public abstract String credsStore();

@Nullable
@JsonProperty("detachKeys")
public abstract String detachKeys();

@Nullable
@JsonProperty("stackOrchestrator")
public abstract String stackOrchestrator();

@Nullable
@JsonProperty("psFormat")
public abstract String psFormat();

@Nullable
@JsonProperty("imagesFormat")
public abstract String imagesFormat();

@JsonCreator
public static DockerConfig create(
@JsonProperty("credsHelpers") final Map<String, String> credsHelpers,
@JsonProperty("auths") final Map<String, RegistryAuth> auths,
@JsonProperty("HttpHeaders") final Map<String, String> httpHeaders,
@JsonProperty("credsStore") final String credsStore,
@JsonProperty("detachKeys") final String detachKeys,
@JsonProperty("stackOrchestrator") final String stackOrchestrator,
@JsonProperty("psFormat") final String psFormat,
@JsonProperty("imagesFormat") final String imagesFormat) {
return new AutoValue_DockerConfig(
credsHelpers == null
? ImmutableMap.<String, String>of()
: ImmutableMap.copyOf(credsHelpers),
auths == null
? ImmutableMap.<String, RegistryAuth>of()
: ImmutableMap.copyOf(auths),
httpHeaders == null
? ImmutableMap.<String, String>of()
: ImmutableMap.copyOf(httpHeaders),
credsStore,
detachKeys,
stackOrchestrator,
psFormat,
imagesFormat);
}
}
Loading

0 comments on commit 6ea96c5

Please sign in to comment.