Handles k8s style bindings

When a binding is provided as a mounted ConfigMap/Secret pair (containing
metadata and secret values respectively) the files within the metadata and
secret directories will be symlinks to files in a colocated hidden directory
that contains the content. In order to handle bindings presented in this
format a Binding object will ignore hidden files and directories when it is
contructed using a path. This prevents errors that previously occured
when the Binding assumed all metadata and secret entries were regular files, and
attempted to read the content of those directories directly.

Resolves #40

Signed-off-by: Emily Casey <ecasey@pivotal.io>
This commit is contained in:
Emily Casey
2020-05-29 11:47:34 -04:00
parent 05596d901e
commit 32c9629e09
14 changed files with 26 additions and 3 deletions

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.cloud.bindings;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -141,6 +142,8 @@ public final class Binding {
private Map<String, String> createFilePerEntryMap(Path path) {
try {
return Files.list(path)
.filter(p -> !p.getFileName().toString().startsWith("."))
.filter(p -> !new File(p.toString()).isDirectory())
.collect(Collectors.toMap(
p -> p.getFileName().toString(),
p -> {

View File

@@ -39,4 +39,17 @@ final class BindingTest {
.isEqualTo(Paths.get("src/test/resources/test-name-1/secret/test-key"));
}
@Test
@DisplayName("populates k8s style content from filesystem")
void testK8s() {
//When bindings are provided as a k8s configmap secret pairs data files will be symlinks to hidden directories
Binding binding = new Binding(Paths.get("src/test/resources/test-k8s"));
assertThat(binding.getKind()).isEqualTo("test-kind-1");
assertThat(binding.getProvider()).isEqualTo("test-provider-1");
assertThat(binding.getMetadataFilePath("test-key"))
.isEqualTo(Paths.get("src/test/resources/test-k8s/metadata/test-key"));
assertThat(binding.getSecretFilePath("test-key"))
.isEqualTo(Paths.get("src/test/resources/test-k8s/secret/test-key"));
}
}

View File

@@ -65,7 +65,7 @@ final class BindingsTests {
String path = "src/test/resources";
Bindings b = new Bindings(path);
assertThat(b.getBindings()).hasSize(2);
assertThat(b.getBindings()).hasSize(3);
}
}
@@ -102,5 +102,4 @@ final class BindingsTests {
}
}
}

View File

@@ -98,7 +98,7 @@ final class BindingSpecificEnvironmentPostProcessorTest {
@Test
@DisplayName("included implementations are registered")
void includedImplementations() {
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(14);
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(15);
}
}

View File

@@ -0,0 +1 @@
.hidden-data-1

View File

@@ -0,0 +1 @@
test-kind-1

View File

@@ -0,0 +1 @@
test-provider-1

View File

@@ -0,0 +1 @@
.hidden-data/kind

View File

@@ -0,0 +1 @@
.hidden-data/provider

View File

@@ -0,0 +1 @@
.hidden-data-1

View File

@@ -0,0 +1 @@
test-value

View File

@@ -0,0 +1 @@
.hidden-data/test-key