Skip to content

Commit 27095d9

Browse files
committed
Polish
1 parent 10ad53a commit 27095d9

File tree

7 files changed

+74
-22
lines changed

7 files changed

+74
-22
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/Builder.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,36 @@ public class Builder {
4545

4646
private final DockerApi docker;
4747

48+
/**
49+
* Create a new builder instance.
50+
*/
4851
public Builder() {
4952
this(BuildLog.toSystemOut());
5053
}
5154

55+
/**
56+
* Create a new builder instance.
57+
* @param dockerConfiguration the docker configuration
58+
* @since 2.4.0
59+
*/
5260
public Builder(DockerConfiguration dockerConfiguration) {
5361
this(BuildLog.toSystemOut(), dockerConfiguration);
5462
}
5563

64+
/**
65+
* Create a new builder instance.
66+
* @param log a logger used to record output
67+
*/
5668
public Builder(BuildLog log) {
5769
this(log, new DockerApi());
5870
}
5971

72+
/**
73+
* Create a new builder instance.
74+
* @param log a logger used to record output
75+
* @param dockerConfiguration the docker configuration
76+
* @since 2.4.0
77+
*/
6078
public Builder(BuildLog log, DockerConfiguration dockerConfiguration) {
6179
this(log, new DockerApi(dockerConfiguration));
6280
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public DockerApi() {
7474

7575
/**
7676
* Create a new {@link DockerApi} instance.
77-
* @param dockerConfiguration the Docker configuration options
77+
* @param dockerConfiguration the docker configuration
78+
* @since 2.4.0
7879
*/
7980
public DockerApi(DockerConfiguration dockerConfiguration) {
8081
this(HttpTransport.create(dockerConfiguration));

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryAuthentication.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,18 @@
1616

1717
package org.springframework.boot.buildpack.platform.docker.configuration;
1818

19-
import com.fasterxml.jackson.core.JsonProcessingException;
20-
21-
import org.springframework.boot.buildpack.platform.json.SharedObjectMapper;
22-
import org.springframework.util.Base64Utils;
23-
2419
/**
2520
* Docker registry authentication configuration.
2621
*
2722
* @author Scott Frederick
2823
* @since 2.4.0
2924
*/
30-
public abstract class DockerRegistryAuthentication {
25+
public interface DockerRegistryAuthentication {
3126

32-
public String createAuthHeader() {
33-
try {
34-
return Base64Utils.encodeToUrlSafeString(SharedObjectMapper.get().writeValueAsBytes(this));
35-
}
36-
catch (JsonProcessingException ex) {
37-
throw new IllegalStateException("Error creating Docker registry authentication header", ex);
38-
}
39-
}
27+
/**
28+
* Create the auth header that should be used for docker authentication.
29+
* @return the auth header
30+
*/
31+
String createAuthHeader();
4032

4133
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryTokenAuthentication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author Scott Frederick
2525
*/
26-
class DockerRegistryTokenAuthentication extends DockerRegistryAuthentication {
26+
class DockerRegistryTokenAuthentication extends JsonEncodedDockerRegistryAuthentication {
2727

2828
@JsonProperty("identitytoken")
2929
private final String token;

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryUserAuthentication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author Scott Frederick
2525
*/
26-
class DockerRegistryUserAuthentication extends DockerRegistryAuthentication {
26+
class DockerRegistryUserAuthentication extends JsonEncodedDockerRegistryAuthentication {
2727

2828
@JsonProperty
2929
private final String username;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.buildpack.platform.docker.configuration;
18+
19+
import com.fasterxml.jackson.core.JsonProcessingException;
20+
21+
import org.springframework.boot.buildpack.platform.json.SharedObjectMapper;
22+
import org.springframework.util.Base64Utils;
23+
24+
/**
25+
* {@link DockerRegistryAuthentication} that uses creates a Base64 encoded auth header
26+
* value based on the JSON created from the instance.
27+
*
28+
* @author Scott Frederick
29+
*/
30+
class JsonEncodedDockerRegistryAuthentication implements DockerRegistryAuthentication {
31+
32+
@Override
33+
public String createAuthHeader() {
34+
try {
35+
return Base64Utils.encodeToUrlSafeString(SharedObjectMapper.get().writeValueAsBytes(this));
36+
}
37+
catch (JsonProcessingException ex) {
38+
throw new IllegalStateException("Error creating Docker registry authentication header", ex);
39+
}
40+
}
41+
42+
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransport.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.http.impl.client.CloseableHttpClient;
3838

3939
import org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration;
40+
import org.springframework.boot.buildpack.platform.docker.configuration.DockerRegistryAuthentication;
4041
import org.springframework.boot.buildpack.platform.io.Content;
4142
import org.springframework.boot.buildpack.platform.io.IOConsumer;
4243
import org.springframework.boot.buildpack.platform.json.SharedObjectMapper;
@@ -122,11 +123,9 @@ public Response delete(URI uri) {
122123
}
123124

124125
private String buildRegistryAuthHeader(DockerConfiguration dockerConfiguration) {
125-
if (dockerConfiguration == null || dockerConfiguration.getRegistryAuthentication() == null) {
126-
return null;
127-
}
128-
129-
String authHeader = dockerConfiguration.getRegistryAuthentication().createAuthHeader();
126+
DockerRegistryAuthentication authentication = (dockerConfiguration != null)
127+
? dockerConfiguration.getRegistryAuthentication() : null;
128+
String authHeader = (authentication != null) ? authentication.createAuthHeader() : null;
130129
return (StringUtils.hasText(authHeader)) ? authHeader : null;
131130
}
132131

0 commit comments

Comments
 (0)