Elasticsearch

This change adds support for Elasticsearch bindings.

[resolves #18]

Signed-off-by: Ben Hale <bhale@vmware.com>
This commit is contained in:
Ben Hale
2020-05-11 16:42:14 -07:00
parent 831d7616f6
commit 9f99fbc8fb
5 changed files with 165 additions and 2 deletions

View File

@@ -72,6 +72,25 @@ Disable Property: `org.springframework.cloud.bindings.boot.db2.enable`
| `spring.datasource.url` | `jdbc:db2://{host}:{port}/{database}`
| `spring.datasource.username` | `{username}`
### Elasticsearch
Kind: `Elasticsearch`
Disable Property: `org.springframework.cloud.bindings.boot.elasticsearch.enable`
| Property | Value (`{secret}`)
| -------- | ------------------
| `spring.data.elasticsearch.client.reactive.endpoints` | `{endpoints}`
| `spring.data.elasticsearch.client.reactive.password` | `{password}`
| `spring.data.elasticsearch.client.reactive.use-ssl` | `{use-ssl}`
| `spring.data.elasticsearch.client.reactive.username` | `{username}`
| `spring.elasticsearch.jest.password` | `{password}`
| `spring.elasticsearch.jest.proxy.host` | `{proxy.host}`
| `spring.elasticsearch.jest.proxy.port` | `{proxy.port}`
| `spring.elasticsearch.jest.username` | `{username}`
| `spring.elasticsearch.rest.password` | `{password}`
| `spring.elasticsearch.rest.uris` | `{uris}`
| `spring.elasticsearch.rest.username` | `{username}`
### MongoDB
Kind: `MongoDB`
Disable Property: `org.springframework.cloud.bindings.boot.mongodb.enable`
@@ -138,7 +157,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.redis.enable`
| `spring.redis.ssl` | `{ssl}`
| `spring.redis.url` | `{url}`
### Oracle RDBMS
### SQLServer RDBMS
Kind: `SQLServer`
Disable Property: `org.springframework.cloud.bindings.boot.sqlserver.enable`

View File

@@ -0,0 +1,61 @@
/*
* 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.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*/
final class ElasticsearchBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} kind that this processor is interested in: {@value}.
**/
public static final String KIND = "Elasticsearch";
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("endpoints").to("spring.data.elasticsearch.client.reactive.endpoints");
map.from("password").to("spring.data.elasticsearch.client.reactive.password");
map.from("use-ssl").to("spring.data.elasticsearch.client.reactive.use-ssl");
map.from("username").to("spring.data.elasticsearch.client.reactive.username");
map.from("password").to("spring.elasticsearch.jest.password");
map.from("proxy.host").to("spring.elasticsearch.jest.proxy.host");
map.from("proxy.port").to("spring.elasticsearch.jest.proxy.port");
map.from("username").to("spring.elasticsearch.jest.username");
map.from("password").to("spring.elasticsearch.rest.password");
map.from("uris").to("spring.elasticsearch.rest.uris");
map.from("username").to("spring.elasticsearch.rest.username");
});
}
}

View File

@@ -6,6 +6,7 @@ org.springframework.cloud.bindings.boot.BindingsPropertiesProcessor=\
org.springframework.cloud.bindings.boot.CassandraBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.CouchbaseBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.Db2BindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.MongoDbBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.MySqlBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.OracleBindingsPropertiesProcessor, \

View File

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

View File

@@ -0,0 +1,82 @@
/*
* 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 org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor.KIND;
@DisplayName("Elasticsearch BindingsPropertiesProcessor")
final class ElasticsearchBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("endpoints", "test-endpoints")
.withEntry("password", "test-password")
.withEntry("use-ssl", "test-use-ssl")
.withEntry("username", "test-username")
.withEntry("proxy.host", "test-proxy-host")
.withEntry("proxy.port", "test-proxy-port")
.withEntry("uris", "test-uris")
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new ElasticsearchBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.data.elasticsearch.client.reactive.endpoints", "test-endpoints")
.containsEntry("spring.data.elasticsearch.client.reactive.password", "test-password")
.containsEntry("spring.data.elasticsearch.client.reactive.use-ssl", "test-use-ssl")
.containsEntry("spring.data.elasticsearch.client.reactive.username", "test-username")
.containsEntry("spring.elasticsearch.jest.password", "test-password")
.containsEntry("spring.elasticsearch.jest.proxy.host", "test-proxy-host")
.containsEntry("spring.elasticsearch.jest.proxy.port", "test-proxy-port")
.containsEntry("spring.elasticsearch.jest.username", "test-username")
.containsEntry("spring.elasticsearch.rest.password", "test-password")
.containsEntry("spring.elasticsearch.rest.uris", "test-uris")
.containsEntry("spring.elasticsearch.rest.username", "test-username");
}
@Test
@DisplayName("can be disabled")
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.elasticsearch.enable", "false");
new ElasticsearchBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}
}