Skip to content

Commit 91f39d7

Browse files
committed
Polish
Signed-off-by: Dmytro Nosan <[email protected]>
1 parent 1d2fbb2 commit 91f39d7

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Credential extends MappedObject {
4040

4141
private final String secret;
4242

43-
private String serverUrl;
43+
private final String serverUrl;
4444

4545
Credential(JsonNode node) {
4646
super(node, MethodHandles.lookup());

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CredentialHelper {
3939

4040
private static final String USR_LOCAL_BIN = "/usr/local/bin/";
4141

42-
Set<String> CREDENTIAL_NOT_FOUND_MESSAGES = Set.of("credentials not found in native keychain",
42+
private static final Set<String> CREDENTIAL_NOT_FOUND_MESSAGES = Set.of("credentials not found in native keychain",
4343
"no credentials server URL", "no credentials username");
4444

4545
private final String executable;
@@ -73,12 +73,12 @@ Credential get(String serverUrl) throws IOException {
7373
}
7474
}
7575

76-
private ProcessBuilder processBuilder(String string) {
76+
private ProcessBuilder processBuilder(String action) {
7777
ProcessBuilder processBuilder = new ProcessBuilder().redirectErrorStream(true);
7878
if (Platform.isWindows()) {
7979
processBuilder.command("cmd", "/c");
8080
}
81-
processBuilder.command(this.executable, string);
81+
processBuilder.command(this.executable, action);
8282
return processBuilder;
8383
}
8484

@@ -87,17 +87,23 @@ private Process start(ProcessBuilder processBuilder) throws IOException {
8787
return processBuilder.start();
8888
}
8989
catch (IOException ex) {
90-
if (!Platform.isMac()) {
91-
throw ex;
90+
if (Platform.isMac()) {
91+
try {
92+
List<String> command = new ArrayList<>(processBuilder.command());
93+
command.set(0, USR_LOCAL_BIN + command.get(0));
94+
return processBuilder.command(command).start();
95+
}
96+
catch (Exception suppressed) {
97+
// Suppresses the exception and rethrows the original exception
98+
ex.addSuppressed(suppressed);
99+
}
92100
}
93-
List<String> command = new ArrayList<>(processBuilder.command());
94-
command.set(0, USR_LOCAL_BIN + command.get(0));
95-
return processBuilder.command(command).start();
101+
throw ex;
96102
}
97103
}
98104

99-
private boolean isCredentialsNotFoundError(String message) {
100-
return this.CREDENTIAL_NOT_FOUND_MESSAGES.contains(message.trim());
105+
private static boolean isCredentialsNotFoundError(String message) {
106+
return CREDENTIAL_NOT_FOUND_MESSAGES.contains(message.trim());
101107
}
102108

103109
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.function.BiConsumer;
2020

2121
import org.springframework.boot.buildpack.platform.docker.type.ImageReference;
22+
import org.springframework.util.Assert;
2223

2324
/**
2425
* Docker registry authentication configuration.
@@ -105,6 +106,7 @@ static DockerRegistryAuthentication configuration(DockerRegistryAuthentication f
105106
*/
106107
static DockerRegistryAuthentication configuration(DockerRegistryAuthentication fallback,
107108
BiConsumer<String, Exception> credentialHelperExceptionHandler) {
109+
Assert.notNull(credentialHelperExceptionHandler, "'credentialHelperExceptionHandler' must not be null");
108110
return new DockerRegistryConfigAuthentication(fallback, credentialHelperExceptionHandler);
109111
}
110112

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelperTests.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ class CredentialHelperTests {
3838

3939
@BeforeAll
4040
static void setUp() throws Exception {
41-
String executableName = "docker-credential-test" + ((Platform.isWindows()) ? ".bat" : ".sh");
42-
String executable = new ClassPathResource(executableName, CredentialHelperTests.class).getFile()
43-
.getAbsolutePath();
44-
helper = new CredentialHelper(executable);
41+
String executable = "docker-credential-test" + (Platform.isWindows() ? ".bat" : ".sh");
42+
helper = new CredentialHelper(
43+
new ClassPathResource(executable, CredentialHelperTests.class).getFile().getAbsolutePath());
4544
}
4645

4746
@Test
@@ -89,10 +88,17 @@ void getWhenUnknownErrorThrowsException() {
8988
}
9089

9190
@Test
92-
void getWhenCommandDoesNotExistErrorThrowsException() {
93-
String name = "docker-credential-%s".formatted(UUID.randomUUID().toString());
94-
assertThatIOException().isThrownBy(() -> new CredentialHelper(name).get("invalid.example.com"))
95-
.withMessageContaining(name);
91+
void getWhenExecutableDoesNotExistErrorThrowsException() {
92+
String executable = "docker-credential-%s".formatted(UUID.randomUUID().toString());
93+
assertThatIOException().isThrownBy(() -> new CredentialHelper(executable).get("invalid.example.com"))
94+
.withMessageContaining(executable)
95+
.satisfies((ex) -> {
96+
if (Platform.isMac()) {
97+
assertThat(ex.getMessage()).doesNotContain("/usr/local/bin/");
98+
assertThat(ex.getSuppressed()).allSatisfy((suppressed) -> assertThat(suppressed)
99+
.hasMessageContaining("/usr/local/bin/" + executable));
100+
}
101+
});
96102
}
97103

98104
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* @author Dmytro Nosan
3434
*/
35-
class CredentialsTests {
35+
class CredentialTests {
3636

3737
@Test
3838
@WithResource(name = "credentials.json", content = """

0 commit comments

Comments
 (0)