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

Refactor Config-file-based auth #1051

Merged
merged 15 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confusing that this field is capitialized differently than all the others 😕 I double-checked the format in https://github.com/docker/cli/blob/08cf36daa65e22771cc47365ff1507c156c4a459/man/docker-config-json.5.md to make sure this seems ok though 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't seen that page. All the searches I did for docker config got swamped by the new feature: https://docs.docker.com/engine/reference/commandline/config/.

I should add several of these properties to the object. Not that I think there is any real chance someone will need them, but if we have the thing, it may as well be able to read what we know can be in there.

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