Merge branch '5-cassandra-binding'

Signed-off-by: Ben Hale <bhale@vmware.com>
This commit is contained in:
Ben Hale
2020-05-11 11:56:03 -07:00
5 changed files with 122 additions and 7 deletions

View File

@@ -38,9 +38,13 @@ Disable Property: `org.springframework.cloud.bindings.boot.cassandra.enable`
| Property | Value
| -------- | -----
| `spring.data.cassandra.contact-points` | `{secret.node_ips}`
| `spring.data.cassandra.cluster-name` | `{secret.cluster-name}`
| `spring.data.cassandra.compression` | `{secret.compression}`
| `spring.data.cassandra.contact-points` | `{secret.contact-points}`
| `spring.data.cassandra.keyspace-name` | `{secret.keyspace-name}`
| `spring.data.cassandra.password` | `{secret.password}`
| `spring.data.cassandra.port` | `{secret.port}`
| `spring.data.cassandra.ssl` | `{secret.ssl}`
| `spring.data.cassandra.username` | `{secret.username}`
### DB2 RDBMS

View File

@@ -22,6 +22,7 @@ import org.springframework.cloud.bindings.Bindings;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled;
import static org.springframework.cloud.bindings.boot.PutIfPresent.put;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
@@ -42,10 +43,14 @@ public final class CassandraBindingsPropertiesProcessor implements BindingsPrope
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();
properties.put("spring.data.cassandra.contact-points", secret.get("node_ips"));
properties.put("spring.data.cassandra.password", secret.get("password"));
properties.put("spring.data.cassandra.port", secret.get("port"));
properties.put("spring.data.cassandra.username", secret.get("username"));
put(properties, "spring.data.cassandra.cluster-name").ifPresent(secret, "cluster-name");
put(properties, "spring.data.cassandra.compression").ifPresent(secret, "compression");
put(properties, "spring.data.cassandra.contact-points").ifPresent(secret, "contact-points");
put(properties, "spring.data.cassandra.keyspace-name").ifPresent(secret, "keyspace-name");
put(properties, "spring.data.cassandra.password").ifPresent(secret, "password");
put(properties, "spring.data.cassandra.port").ifPresent(secret, "port");
put(properties, "spring.data.cassandra.ssl").ifPresent(secret, "ssl");
put(properties, "spring.data.cassandra.username").ifPresent(secret, "username");
});
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2020 the original author or authors.
*
* 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 org.springframework.cloud.bindings.boot;
import java.util.Map;
final class PutIfPresent {
private final Map<String, Object> destination;
private final String key;
PutIfPresent(Map<String, Object> destination, String key) {
this.destination = destination;
this.key = key;
}
static PutIfPresent put(Map<String, Object> destination, String key) {
return new PutIfPresent(destination, key);
}
void ifPresent(Map<String, String> source, String key) {
if (!source.containsKey(key)) {
return;
}
destination.put(this.key, source.get(key));
}
}

View File

@@ -37,9 +37,13 @@ final class CassandraBindingsPropertiesProcessorTest {
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("node_ips", "test-node-ips")
.withEntry("cluster-name", "test-cluster-name")
.withEntry("compression", "test-compression")
.withEntry("contact-points", "test-contact-points")
.withEntry("keyspace-name", "test-keyspace-name")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("ssl", "test-ssl")
.withEntry("username", "test-username")
)
);
@@ -51,9 +55,13 @@ final class CassandraBindingsPropertiesProcessorTest {
void test() {
new CassandraBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.data.cassandra.contact-points", "test-node-ips")
.containsEntry("spring.data.cassandra.cluster-name", "test-cluster-name")
.containsEntry("spring.data.cassandra.compression", "test-compression")
.containsEntry("spring.data.cassandra.contact-points", "test-contact-points")
.containsEntry("spring.data.cassandra.keyspace-name", "test-keyspace-name")
.containsEntry("spring.data.cassandra.password", "test-password")
.containsEntry("spring.data.cassandra.port", "test-port")
.containsEntry("spring.data.cassandra.ssl", "test-ssl")
.containsEntry("spring.data.cassandra.username", "test-username");
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright 2020 the original author or authors.
*
* 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 org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.bindings.boot.PutIfPresent.put;
@DisplayName("Put if present")
final class PutIfPresentTest {
@Test
@DisplayName("puts if present")
void present() {
Map<String, String> source = Collections.singletonMap("test-source-key", "test-source-value");
Map<String, Object> destination = new HashMap<>();
put(destination, "test-destination-key").ifPresent(source, "test-source-key");
assertThat(destination).containsEntry("test-destination-key", "test-source-value");
}
@Test
@DisplayName("does not put if not present")
void notPresent() {
Map<String, String> source = Collections.emptyMap();
Map<String, Object> destination = new HashMap<>();
put(destination, "test-destination-key").ifPresent(source, "test-source-key");
assertThat(destination).doesNotContainKey("test-destination-key");
}
}