Spring Boot 3 support

* only in main branch, SB2 support will be continued in 1.x branch
This commit is contained in:
Anthony Dahanne
2023-06-05 17:23:22 -04:00
parent be780f7a4b
commit 3b43462fc4
47 changed files with 252 additions and 1231 deletions

128
README.md
View File

@@ -3,6 +3,12 @@ The Spring Cloud Bindings library exposes a rich Java language binding for the [
[s]: https://github.com/servicebinding/spec
## Features
* Java 17
* Spring Boot 3
For Spring Boot 2 compatibility, please have a look at the [1.x releases](https://github.com/spring-cloud/spring-cloud-bindings/tree/1.x).
## Library Usage
While less used, explicit binding access can be achieved through the `Bindings` type.
@@ -38,23 +44,11 @@ Each auto-configuration is triggered by the type of binding. Each auto-configur
Type: `artemis`
Disable Property: `org.springframework.cloud.bindings.boot.artemis.enable`
#### Spring Boot 2 properties
| Property | Value |
| --------------------------------------------------- | -------------------------------------- |
| `spring.artemis.host` | `{host}` |
| `spring.artemis.port` | `{port}` |
#### Spring Boot 3 properties
#### Properties
| Property | Value |
| --------------------------------------------------- | -------------------------------------- |
| `spring.artemis.broker-url` | `{broker-url}` |
#### Common properties
| Property | Value |
| --------------------------------------------------- | -------------------------------------- |
| `spring.artemis.mode` | `{mode}` |
| `spring.artemis.password` | `{password}` |
| `spring.artemis.user` | `{user}` |
@@ -78,24 +72,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.artemis.enable`
Type: `cassandra`
Disable Property: `org.springframework.cloud.bindings.boot.cassandra.enable`
#### Spring Boot 2 properties
| Property | Value |
|-------------------------------------------------------------------|-----------------------------------------------|
| `spring.data.cassandra.cluster-name` | `{cluster-name}` |
| `spring.data.cassandra.compression` | `{compression}` |
| `spring.data.cassandra.contact-points` | `{contact-points}` |
| `spring.data.cassandra.keyspace-name` | `{keyspace-name}` |
| `spring.data.cassandra.password` | `{password}` |
| `spring.data.cassandra.port` | `{port}` |
| `spring.data.cassandra.ssl` | `{ssl}` |
| `spring.data.cassandra.username` | `{username}` |
| `spring.data.cassandra.request.throttler.drain-interval` | `{request.throttler.drain-interval}` |
| `spring.data.cassandra.request.throttler.max-concurrent-requests` | `{request.throttler.max-concurrent-requests}` |
| `spring.data.cassandra.request.throttler.max-queue-size` | `{request.throttler.max-queue-size}` |
| `spring.data.cassandra.request.throttler.max-requests-per-second` | `{request.throttler.max-requests-per-second}` |
#### Spring Boot 3 properties
#### Properties
| Property | Value |
|--------------------------------------------------------------|-----------------------------------------------|
@@ -116,29 +93,14 @@ Disable Property: `org.springframework.cloud.bindings.boot.cassandra.enable`
Type: `couchbase`
Disable Property: `org.springframework.cloud.bindings.boot.couchbase.enable`
#### Spring Boot 2 properties
| Property | Value |
|---------------------------------------------------|------------------------------------|
| `spring.couchbase.bootstrap-hosts` | `{bootstrap-hosts}` |
| `spring.couchbase.bucket.name` | `{bucket.name}` |
| `spring.couchbase.bucket.password` | `{bucket.passsword}` |
| `spring.couchbase.env.bootstrap.http-direct-port` | `{env.bootstrap.http-direct-port}` |
| `spring.couchbase.env.bootstrap.http-ssl-port` | `{env.bootstrap.http-ssl-port}` |
#### Spring Boot 3 properties
#### Properties
| Property | Value |
|--------------------------------------------------|---------------------------|
| `spring.couchbase.connection-string` | `{connection-string}` |
| `spring.data.couchbase.bucket-name` | `{bucket-name}` |
#### Common properties
| Property | Value |
|---------------------------------------------------|---------------------------|
| `spring.couchbase.password` | `{password}` |
| `spring.couchbase.username` | `{username}` |
| `spring.couchbase.password` | `{password}` |
| `spring.couchbase.username` | `{username}` |
### DB2 RDBMS
Type: `db2`
@@ -159,23 +121,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.db2.enable`
Type: `elasticsearch`
Disable Property: `org.springframework.cloud.bindings.boot.elasticsearch.enable`
#### Spring Boot 2 properties
| Property | Value |
| ----------------------------------------------------- | -------------- |
| `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}` |
#### Spring Boot 3 properties
#### Properties
| Property | Value |
|---------------------------------|---------------|
@@ -240,15 +186,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.mysql.enable`
Type: `neo4j`
Disable Property: `org.springframework.cloud.bindings.boot.neo4j.enable`
#### Spring Boot 2 properties
| Property | Value |
| ---------------------------- | ------------ |
| `spring.data.neo4j.uri` | `{uri}` |
| `spring.data.neo4j.username` | `{username}` |
| `spring.data.neo4j.password` | `{password}` |
#### Spring Boot 3 properties
#### Properties
| Property | Value |
|-----------------------------------------|----------------|
@@ -301,23 +239,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.rabbitmq.enable`
Type: `redis`
Disable Property: `org.springframework.cloud.bindings.boot.redis.enable`
#### Spring Boot 2 properties
| Property | Value |
| ------------------------------------ | ------------------------- |
| `spring.redis.client-name` | `{client-name}` |
| `spring.redis.cluster.max-redirects` | `{cluster.max-redirects}` |
| `spring.redis.cluster.nodes` | `{cluster.nodes}` |
| `spring.redis.database` | `{database}` |
| `spring.redis.host` | `{host}` |
| `spring.redis.password` | `{password}` |
| `spring.redis.port` | `{port}` |
| `spring.redis.sentinel.master` | `{sentinel.master}` |
| `spring.redis.sentinel.nodes` | `{sentinel.nodes}` |
| `spring.redis.ssl` | `{ssl}` |
| `spring.redis.url` | `{url}` |
#### Spring Boot 3 properties
#### Properties
| Property | Value |
|-------------------------------------------|---------------------------|
@@ -426,6 +348,7 @@ Type: `vault`
Disable Property: `org.springframework.cloud.bindings.boot.vault.enable`
Any Provider:
| Property | Value |
| ----------------------------------- | ------------------------- |
| `spring.cloud.vault.authentication` | `{authentication-method}` |
@@ -433,6 +356,7 @@ Any Provider:
| `spring.cloud.vault.uri` | `{uri}` |
If `{authentication-method}` is equal to `approle`:
| Property | Value |
| ------------------------------------------- | ----------------- |
| `spring.cloud.vault.app-role.app-role-path` | `{app-role-path}` |
@@ -441,6 +365,7 @@ If `{authentication-method}` is equal to `approle`:
| `spring.cloud.vault.app-role.secret-id` | `{secret-id}` |
If `{authentication-method}` is equal to `aws_ec2`:
| Property | Value |
| ---------------------------------------------- | -------------------------------------- |
| `spring.cloud.vault.aws-ec2.aws-ec2-path` | `{aws-ec2-path}` |
@@ -449,37 +374,41 @@ If `{authentication-method}` is equal to `aws_ec2`:
| `spring.cloud.vault.aws-ec2.role` | `{role}` |
If `{authentication-method}` is equal to `aws_iam`:
| Property | Value |
|-------------------------------------------|----------------------------------------|
| `spring.cloud.vault.aws-iam.aws-path` | `{aws-path}` |
| `spring.cloud.vault.aws-iam.endpoint-uri` | `{aws-sts-endpoint-uri}` |
| `spring.cloud.vault.aws-iam.role` | `{role}` |
| `spring.cloud.vault.aws-iam.server-id` | `{aws-iam-server-id}` Spring Boot 2 |
| `spring.cloud.vault.aws-iam.server-name` | `{aws-iam-server-name}` Spring Boot 3 |
| `spring.cloud.vault.aws-iam.server-name` | `{aws-iam-server-name}` |
If `{authentication-method}` is equal to `azure_msi`:
| Property | Value |
|-------------------------------------------------------|------------------------------------------|
| `spring.cloud.vault.azure-msi.azure-path` | `{azure-path}` |
| `spring.cloud.vault.azure-msi.role` | `{role}` |
| `spring.cloud.vault.azure-msi.metadata-service` | `{metadata-service}` Spring Boot 3 |
| `spring.cloud.vault.azure-msi.identity-token-service` | `{identity-token-service}` Spring Boot 3 |
| `spring.cloud.vault.azure-msi.metadata-service` | `{metadata-service}` |
| `spring.cloud.vault.azure-msi.identity-token-service` | `{identity-token-service}` |
If `{authentication-method}` is equal to `cert`:
| Property | Value |
|-----------------------------------------------|---------------------------------------------------------------|
| `spring.cloud.vault.ssl.cert-auth-path` | `{cert-auth-path}` |
| `spring.cloud.vault.ssl.key-store-password` | `{key-store-password}` |
| `spring.cloud.vault.ssl.key-store` | `${SERVICE_BINDING_ROOT}/{name}/keystore.jks` |
| `spring.cloud.vault.ssl.trust-store` | `${SERVICE_BINDING_ROOT}/{name}/truststore.jks` Spring Boot 3 |
| `spring.cloud.vault.ssl.trust-store-password` | `{trust-store-password}` Spring Boot 3 |
| `spring.cloud.vault.ssl.trust-store` | `${SERVICE_BINDING_ROOT}/{name}/truststore.jks` |
| `spring.cloud.vault.ssl.trust-store-password` | `{trust-store-password}` |
If `{authentication-method}` is equal to `cubbyhole`:
| Property | Value |
| -------------------------- | --------- |
| `spring.cloud.vault.token` | `{token}` |
If `{authentication-method}` is equal to `gcp_gce`:
| Property | Value |
| -------------------------------------------- | ----------------------- |
| `spring.cloud.vault.gcp-gce.gcp-path` | `{gcp-path}` |
@@ -487,6 +416,7 @@ If `{authentication-method}` is equal to `gcp_gce`:
| `spring.cloud.vault.gcp-gce.service-account` | `{gcp-service-account}` |
If `{authentication-method}` is equal to `gcp_iam`:
| Property | Value |
|------------------------------------------------------|----------------------------------------------------|
| `spring.cloud.vault.gcp-iam.credentials.encoded-key` | `{encoded-key}` |
@@ -499,6 +429,7 @@ If `{authentication-method}` is equal to `gcp_iam`:
| `spring.cloud.vault.gcp-iam.service-account-id` | `{gcp-service-account}` Spring Boot 3 |
If `{authentication-method}` is equal to `kubernetes`:
| Property | Value |
|-----------------------------------------------------------------------|---------------------------------------------------------|
| `spring.cloud.vault.kubernetes.role` | `{role}` |
@@ -506,6 +437,7 @@ If `{authentication-method}` is equal to `kubernetes`:
| `spring.cloud.vault.kubernetes.kubernetes-service-account-token-file` | `{kubernetes-service-account-token-file}` Spring Boot 3 |
If `{authentication-method}` is equal to `token`:
| Property | Value |
| -------------------------- | --------- |
| `spring.cloud.vault.token` | `{token}` |

View File

@@ -16,6 +16,10 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<spring-boot.version>3.1.0</spring-boot.version>
</properties>
<licenses>
@@ -27,10 +31,8 @@
<modules>
<module>spring-cloud-bindings</module>
<module>spring-cloud-bindings-tests-boot-2</module>
<module>spring-cloud-bindings-tests-boot-3</module>
<module>spring-cloud-bindings-tests</module>
</modules>
<scm>
<url>https://github.com/spring-cloud/spring-cloud-bindings</url>
</scm>

View File

@@ -1,23 +0,0 @@
# Spring Cloud Bindings Test Boot 2
## Purpose of this module
For several Spring Cloud Bindings integrations, the properties bindings need to be different between Spring Boot 2 and Spring Boot 3.
For example, we can take some Redis properties bindings; with Spring Boot 2, they need to be mapped this way:
| Property | Value |
|---------------------|----------|
| `spring.redis.port` | `{port}` |
| `spring.redis.host` | `{host}` |
But in a Spring Boot 3 application, the mapping needs to be different because of changes with Spring Data Redis:
| Property | Value |
|--------------------------|----------|
| `spring.data.redis.port` | `{port}` |
| `spring.data.redis.host` | `{host}` |
This module runs an application, based on Spring Boot 2, and checks whether the `RedisConnectionFactory` properly picked up the `spring.redis.port` and `spring.redis.host` values.
Pay attention to the 2 environment variables set in the `pom.xml` that set the `JAVA_TOOL_OPTIONS` and `SERVICE_BINDING_ROOT` - they allow Spring Boot Bindings to load the proper configuration in `bindings/redis`

View File

@@ -1,77 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bindings-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>spring-cloud-bindings-tests-boot-2</artifactId>
<description>Test project to verify Spring Cloud Bindings works properly with Spring Boot 2</description>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<spring-boot.version>2.5.14</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bindings</artifactId>
<version>${version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.kstyrc</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.6</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<environmentVariables>
<JAVA_TOOL_OPTIONS>-Dorg.springframework.cloud.bindings.boot.enable=true</JAVA_TOOL_OPTIONS>
<SERVICE_BINDING_ROOT>${basedir}/src/test/resources/bindings</SERVICE_BINDING_ROOT>
</environmentVariables>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,7 +0,0 @@
package org.springframework.cloud;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBoot2Application {
}

View File

@@ -1,21 +0,0 @@
package org.springframework.cloud;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest(classes = RedisServerTestConfiguration.class)
public class IntegrationTest {
@Autowired
private RedisTemplate redisTemplate;
@Test
public void shouldSaveUser_toRedis() {
redisTemplate.opsForValue().set("hello", "world");
assertTrue(redisTemplate.hasKey("hello"));
}
}

View File

@@ -1,33 +0,0 @@
package org.springframework.cloud;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.core.io.ClassPathResource;
import redis.embedded.RedisServer;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.util.Scanner;
@TestConfiguration
public class RedisServerTestConfiguration {
private final RedisServer redisServer;
public RedisServerTestConfiguration() throws IOException {
try (Scanner scanner = new Scanner(new ClassPathResource("bindings/redis/port").getInputStream())) {
int port = scanner.nextInt();
this.redisServer = new RedisServer(port);
}
}
@PostConstruct
public void postConstruct() {
redisServer.start();
}
@PreDestroy
public void preDestroy() {
redisServer.stop();
}
}

View File

@@ -1,23 +1,16 @@
# Spring Cloud Bindings Test Boot 2
# Spring Cloud Bindings Test Boot 3
## Purpose of this module
For several Spring Cloud Bindings integrations, the properties bindings need to be different between Spring Boot 2 and Spring Boot 3.
For example, we can take some Redis properties bindings; with Spring Boot 2, they need to be mapped this way:
| Property | Value |
|---------------------|----------|
| `spring.redis.port` | `{port}` |
| `spring.redis.host` | `{host}` |
But in a Spring Boot 3 application, the mapping needs to be different because of changes with Spring Data Redis:
In a Spring Boot 3 application, the mapping needs to be different because of changes with Spring Data Redis:
| Property | Value |
|--------------------------|----------|
| `spring.data.redis.port` | `{port}` |
| `spring.data.redis.host` | `{host}` |
This module runs an application, based on Spring Boot 2, and checks whether the `RedisConnectionFactory` properly picked up the `spring.data.redis.port` and `spring.data.redis.host` values.
This module runs an application, based on Spring Boot 3, and checks whether the `RedisConnectionFactory` properly picked up the `spring.data.redis.port` and `spring.data.redis.host` values.
Pay attention to the 2 environment variables set in the `pom.xml` that set the `JAVA_TOOL_OPTIONS` and `SERVICE_BINDING_ROOT` - they allow Spring Boot Bindings to load the proper configuration in `bindings/redis`

View File

@@ -8,14 +8,8 @@
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>spring-cloud-bindings-tests-boot-3</artifactId>
<artifactId>spring-cloud-bindings-tests</artifactId>
<description>Test project to verify Spring Cloud Bindings works properly with Spring Boot 2</description>
<properties>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<spring-boot.version>3.0.2</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -36,10 +36,8 @@
</developers>
<properties>
<java.version>1.8</java.version>
<jsr305.version>3.0.2</jsr305.version>
<mariadb-r2dbc.version>1.1.2</mariadb-r2dbc.version>
<spring-boot.version>2.5.14</spring-boot.version>
<!-- Plugins -->
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
@@ -47,9 +45,6 @@
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencyManagement>

View File

@@ -27,105 +27,43 @@ import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}.
*/
public final class ArtemisBindingsPropertiesProcessor {
public final class ArtemisBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} type that this processor is interested in: {@value}.
**/
public static final String TYPE = "artemis";
public final static class Boot2 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 2;
Boot2(int forcedVersion) {
super(forcedVersion);
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
public Boot2() {
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("broker-url").to("spring.artemis.broker-url");
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
map.from("pool.block-if-full").to("spring.artemis.pool.block-if-full");
map.from("pool.block-if-full-timeout").to("spring.artemis.pool.block-if-full-timeout");
map.from("pool.enabled").to("spring.artemis.pool.enabled");
map.from("pool.idle-timeout").to("spring.artemis.pool.idle-timeout");
map.from("pool.max-connections").to("spring.artemis.pool.max-connections");
map.from("pool.max-sessions-per-connection").to("spring.artemis.pool.max-sessions-per-connection");
map.from("pool.time-between-expiration-check").to("spring.artemis.pool.time-between-expiration-check");
map.from("pool.use-anonymous-producers").to("spring.artemis.pool.use-anonymous-producers");
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("host").to("spring.artemis.host");
map.from("port").to("spring.artemis.port");
map.from("mode").to("spring.artemis.mode");
map.from("password").to("spring.artemis.password");
map.from("user").to("spring.artemis.user");
map.from("pool.block-if-full").to("spring.rabbitmq.pool.block-if-full");
map.from("pool.block-if-full-timeout").to("spring.rabbitmq.pool.block-if-full-timeout");
map.from("pool.enabled").to("spring.rabbitmq.pool.enabled");
map.from("pool.idle-timeout").to("spring.rabbitmq.pool.idle-timeout");
map.from("pool.max-connections").to("spring.rabbitmq.pool.max-connections");
map.from("pool.max-sessions-per-connection").to("spring.rabbitmq.pool.max-sessions-per-connection");
map.from("pool.time-between-expiration-check").to("spring.rabbitmq.pool.time-between-expiration-check");
map.from("pool.use-anonymous-producers").to("spring.rabbitmq.pool.use-anonymous-producers");
commonProperties(map);
});
}
map.from("embedded.cluster-password").to("spring.artemis.embedded.cluster-password");
map.from("embedded.data-directory").to("spring.artemis.embedded.data-directory");
map.from("embedded.enabled").to("spring.artemis.embedded.enabled");
map.from("embedded.persistent").to("spring.artemis.embedded.persistent");
map.from("embedded.queues").to("spring.artemis.embedded.queues");
map.from("embedded.server-id").to("spring.artemis.embedded.server-id");
map.from("embedded.topics").to("spring.artemis.embedded.topics");
});
}
/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 3;
Boot3(int forcedVersion) {
super(forcedVersion);
}
public Boot3() {
}
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("broker-url").to("spring.artemis.broker-url");
map.from("pool.block-if-full").to("spring.artemis.pool.block-if-full");
map.from("pool.block-if-full-timeout").to("spring.artemis.pool.block-if-full-timeout");
map.from("pool.enabled").to("spring.artemis.pool.enabled");
map.from("pool.idle-timeout").to("spring.artemis.pool.idle-timeout");
map.from("pool.max-connections").to("spring.artemis.pool.max-connections");
map.from("pool.max-sessions-per-connection").to("spring.artemis.pool.max-sessions-per-connection");
map.from("pool.time-between-expiration-check").to("spring.artemis.pool.time-between-expiration-check");
map.from("pool.use-anonymous-producers").to("spring.artemis.pool.use-anonymous-producers");
commonProperties(map);
});
}
}
private static void commonProperties(MapMapper map) {
map.from("mode").to("spring.artemis.mode");
map.from("password").to("spring.artemis.password");
map.from("user").to("spring.artemis.user");
map.from("embedded.cluster-password").to("spring.artemis.embedded.cluster-password");
map.from("embedded.data-directory").to("spring.artemis.embedded.data-directory");
map.from("embedded.enabled").to("spring.artemis.embedded.enabled");
map.from("embedded.persistent").to("spring.artemis.embedded.persistent");
map.from("embedded.queues").to("spring.artemis.embedded.queues");
map.from("embedded.server-id").to("spring.artemis.embedded.server-id");
map.from("embedded.topics").to("spring.artemis.embedded.topics");
}
}

View File

@@ -27,92 +27,33 @@ import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}.
*/
public final class CassandraBindingsPropertiesProcessor {
public final class CassandraBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} type that this processor is interested in: {@value}.
**/
public static final String TYPE = "cassandra";
public final static class Boot2 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 2;
Boot2(int forcedVersion) {
super(forcedVersion);
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
public Boot2() {
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("cluster-name").to("spring.cassandra.cluster-name");
map.from("compression").to("spring.cassandra.compression");
map.from("contact-points").to("spring.cassandra.contact-points");
map.from("keyspace-name").to("spring.cassandra.keyspace-name");
map.from("password").to("spring.cassandra.password");
map.from("port").to("spring.cassandra.port");
map.from("ssl").to("spring.cassandra.ssl");
map.from("username").to("spring.cassandra.username");
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("cluster-name").to("spring.data.cassandra.cluster-name");
map.from("compression").to("spring.data.cassandra.compression");
map.from("contact-points").to("spring.data.cassandra.contact-points");
map.from("keyspace-name").to("spring.data.cassandra.keyspace-name");
map.from("password").to("spring.data.cassandra.password");
map.from("port").to("spring.data.cassandra.port");
map.from("ssl").to("spring.data.cassandra.ssl");
map.from("username").to("spring.data.cassandra.username");
map.from("request.throttler.drain-interval").to("spring.data.cassandra.request.throttler.drain-interval");
map.from("request.throttler.max-concurrent-requests").to("spring.data.cassandra.request.throttler.max-concurrent-requests");
map.from("request.throttler.max-queue-size").to("spring.data.cassandra.request.throttler.max-queue-size");
map.from("request.throttler.max-requests-per-second").to("spring.data.cassandra.request.throttler.max-requests-per-second");
});
}
map.from("request.throttler.drain-interval").to("spring.cassandra.request.throttler.drain-interval");
map.from("request.throttler.max-concurrent-requests").to("spring.cassandra.request.throttler.max-concurrent-requests");
map.from("request.throttler.max-queue-size").to("spring.cassandra.request.throttler.max-queue-size");
map.from("request.throttler.max-requests-per-second").to("spring.cassandra.request.throttler.max-requests-per-second");
});
}
/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 3;
Boot3(int forcedVersion) {
super(forcedVersion);
}
public Boot3() {
}
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("cluster-name").to("spring.cassandra.cluster-name");
map.from("compression").to("spring.cassandra.compression");
map.from("contact-points").to("spring.cassandra.contact-points");
map.from("keyspace-name").to("spring.cassandra.keyspace-name");
map.from("password").to("spring.cassandra.password");
map.from("port").to("spring.cassandra.port");
map.from("ssl").to("spring.cassandra.ssl");
map.from("username").to("spring.cassandra.username");
map.from("request.throttler.drain-interval").to("spring.cassandra.request.throttler.drain-interval");
map.from("request.throttler.max-concurrent-requests").to("spring.cassandra.request.throttler.max-concurrent-requests");
map.from("request.throttler.max-queue-size").to("spring.cassandra.request.throttler.max-queue-size");
map.from("request.throttler.max-requests-per-second").to("spring.cassandra.request.throttler.max-requests-per-second");
});
}
}
}

View File

@@ -27,82 +27,25 @@ import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}.
*/
final class CouchbaseBindingsPropertiesProcessor {
final class CouchbaseBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} type that this processor is interested in: {@value}.
**/
public static final String TYPE = "couchbase";
public final static class Boot2 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 2;
Boot2(int forcedVersion) {
super(forcedVersion);
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
public Boot2() {
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("bucket-name").to("spring.data.couchbase.bucket-name");
map.from("connection-string").to("spring.couchbase.connection-string");
map.from("password").to("spring.couchbase.password");
map.from("username").to("spring.couchbase.username");
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("bootstrap-hosts").to("spring.couchbase.bootstrap-hosts");
map.from("bucket.name").to("spring.couchbase.bucket.name");
map.from("bucket.password").to("spring.couchbase.bucket.password");
map.from("env.bootstrap.http-direct-port").to("spring.couchbase.env.bootstrap.http-direct-port");
map.from("env.bootstrap.http-ssl-port").to("spring.couchbase.env.bootstrap.http-ssl-port");
commonProperties(map);
});
}
});
}
/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 3;
Boot3(int forcedVersion) {
super(forcedVersion);
}
public Boot3() {
}
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("bucket-name").to("spring.data.couchbase.bucket-name");
map.from("connection-string").to("spring.couchbase.connection-string");
commonProperties(map);
});
}
}
private static void commonProperties(MapMapper map) {
map.from("password").to("spring.couchbase.password");
map.from("username").to("spring.couchbase.username");
}
}

View File

@@ -27,80 +27,24 @@ import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}.
*/
final class ElasticsearchBindingsPropertiesProcessor {
final class ElasticsearchBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} type that this processor is interested in: {@value}.
**/
public static final String TYPE = "elasticsearch";
public final static class Boot2 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 2;
Boot2(int forcedVersion) {
super(forcedVersion);
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
public Boot2() {
}
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).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");
});
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("password").to("spring.elasticsearch.password");
map.from("uris").to("spring.elasticsearch.uris");
map.from("username").to("spring.elasticsearch.username");
});
}
/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 3;
Boot3(int forcedVersion) {
super(forcedVersion);
}
public Boot3() {
}
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("password").to("spring.elasticsearch.password");
map.from("uris").to("spring.elasticsearch.uris");
map.from("username").to("spring.elasticsearch.username");
});
}
}
}

View File

@@ -27,73 +27,25 @@ import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}.
*/
final class Neo4JBindingsPropertiesProcessor {
final class Neo4JBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} type that this processor is interested in: {@value}.
**/
public static final String TYPE = "neo4j";
public final static class Boot2 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 2;
Boot2(int forcedVersion) {
super(forcedVersion);
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
public Boot2() {
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("password").to("spring.neo4j.authentication.password");
map.from("uri").to("spring.neo4j.uri");
map.from("username").to("spring.neo4j.authentication.username");
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("password").to("spring.data.neo4j.password");
map.from("uri").to("spring.data.neo4j.uri");
map.from("username").to("spring.data.neo4j.username");
});
}
});
}
/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 3;
Boot3(int forcedVersion) {
super(forcedVersion);
}
public Boot3() {
}
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("password").to("spring.neo4j.authentication.password");
map.from("uri").to("spring.neo4j.uri");
map.from("username").to("spring.neo4j.authentication.username");
});
}
}
}

View File

@@ -27,93 +27,34 @@ import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}.
*/
public final class RedisBindingsPropertiesProcessor {
public final class RedisBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} type that this processor is interested in: {@value}.
**/
public static final String TYPE = "redis";
/**
* This is a special case for Boot 2.
*/
public final static class Boot2 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 2;
Boot2(int forcedVersion) {
super(forcedVersion);
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
public Boot2() {
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("client-name").to("spring.redis.client-name");
map.from("cluster.max-redirects").to("spring.redis.cluster.max-redirects");
map.from("cluster.nodes").to("spring.redis.cluster.nodes");
map.from("database").to("spring.redis.database");
map.from("host").to("spring.redis.host");
map.from("password").to("spring.redis.password");
map.from("port").to("spring.redis.port");
map.from("sentinel.master").to("spring.redis.sentinel.master");
map.from("sentinel.nodes").to("spring.redis.sentinel.nodes");
map.from("ssl").to("spring.redis.ssl");
map.from("url").to("spring.redis.url");
});
}
}
/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements BindingsPropertiesProcessor {
private static final int BOOT_VERSION = 3;
Boot3(int forcedVersion) {
super(forcedVersion);
}
public Boot3() {
}
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("client-name").to("spring.data.redis.client-name");
map.from("cluster.max-redirects").to("spring.data.redis.cluster.max-redirects");
map.from("cluster.nodes").to("spring.data.redis.cluster.nodes");
map.from("database").to("spring.data.redis.database");
map.from("host").to("spring.data.redis.host");
map.from("password").to("spring.data.redis.password");
map.from("port").to("spring.data.redis.port");
map.from("sentinel.master").to("spring.data.redis.sentinel.master");
map.from("sentinel.nodes").to("spring.data.redis.sentinel.nodes");
map.from("ssl").to("spring.data.redis.ssl");
map.from("url").to("spring.data.redis.url");
});
}
map.from("client-name").to("spring.data.redis.client-name");
map.from("cluster.max-redirects").to("spring.data.redis.cluster.max-redirects");
map.from("cluster.nodes").to("spring.data.redis.cluster.nodes");
map.from("database").to("spring.data.redis.database");
map.from("host").to("spring.data.redis.host");
map.from("password").to("spring.data.redis.password");
map.from("port").to("spring.data.redis.port");
map.from("sentinel.master").to("spring.data.redis.sentinel.master");
map.from("sentinel.nodes").to("spring.data.redis.sentinel.nodes");
map.from("ssl").to("spring.data.redis.ssl");
map.from("url").to("spring.data.redis.url");
});
}
}

View File

@@ -1,27 +0,0 @@
package org.springframework.cloud.bindings.boot;
import org.springframework.boot.SpringBootVersion;
/**
* This class is used to allow, in unit tests for example,
* to fake the resolution of which major version of spring boot is used
*/
class SpringBootVersionResolver {
private int forcedVersion = -1;
SpringBootVersionResolver() {
}
protected SpringBootVersionResolver(int forcedVersion) {
this.forcedVersion = forcedVersion;
}
protected boolean isBootMajorVersionEnabled(int bootVersion) {
if (forcedVersion != -1) {
return forcedVersion == bootVersion;
}
int major = Integer.parseInt(SpringBootVersion.getVersion().split("\\.")[0]);
return major == bootVersion;
}
}

View File

@@ -30,8 +30,7 @@ import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}.
*/
public final class VaultBindingsPropertiesProcessor {
public final class VaultBindingsPropertiesProcessor implements BindingsPropertiesProcessor, ApplicationListener<ApplicationPreparedEvent> {
/**
* The {@link Binding} type that this processor is interested in: {@value}.
**/
@@ -39,190 +38,90 @@ public final class VaultBindingsPropertiesProcessor {
private static final DeferredLog LOG = new DeferredLog();
public final static class Boot2 extends SpringBootVersionResolver implements BindingsPropertiesProcessor, ApplicationListener<ApplicationPreparedEvent> {
private static final int BOOT_VERSION = 2;
Boot2(int forcedVersion) {
super(forcedVersion);
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
public Boot2() {
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("uri").to("spring.cloud.vault.uri");
map.from("namespace").to("spring.cloud.vault.namespace"); // vault enterprise feature
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
String authenticationMethod = binding.getSecret().get("authentication-method");
if (authenticationMethod == null) {
LOG.warn(String.format("Key 'method' is missing from secret of binding '%s'", binding.getName()));
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
properties.put("spring.cloud.vault.authentication", authenticationMethod);
switch (authenticationMethod.toUpperCase()) {
case "TOKEN":
case "CUBBYHOLE":
map.from("token").to("spring.cloud.vault.token");
break;
case "APPROLE":
map.from("role-id").to("spring.cloud.vault.app-role.role-id");
map.from("secret-id").to("spring.cloud.vault.app-role.secret-id");
map.from("role").to("spring.cloud.vault.app-role.role");
map.from("app-role-path").to("spring.cloud.vault.app-role.app-role-path");
break;
case "AWS_EC2":
map.from("role").to("spring.cloud.vault.aws-ec2.role");
map.from("aws-ec2-path").to("spring.cloud.vault.aws-ec2.aws-ec2-path");
map.from("aws-ec2-instance-identity-document").to("spring.cloud.vault.aws-ec2.identity-document");
map.from("nonce").to("spring.cloud.vault.aws-ec2.nonce");
break;
case "GCP_GCE":
map.from("role").to("spring.cloud.vault.gcp-gce.role");
map.from("gcp-path").to("spring.cloud.vault.gcp-gce.gcp-path");
map.from("gcp-service-account").to("spring.cloud.vault.gcp-gce.service-account");
break;
case "AWS_IAM":
map.from("role").to("spring.cloud.vault.aws-iam.role");
map.from("aws-path").to("spring.cloud.vault.aws-iam.aws-path");
map.from("aws-sts-endpoint-uri").to("spring.cloud.vault.aws-iam.endpoint-uri");
map.from("aws-iam-server-name").to("spring.cloud.vault.aws-iam.server-name");
break;
case "AZURE_MSI":
map.from("role").to("spring.cloud.vault.azure-msi.role");
map.from("azure-path").to("spring.cloud.vault.azure-msi.azure-path");
map.from("metadata-service").to("spring.cloud.vault.azure-msi.metadata-service");
map.from("identity-token-service").to("spring.cloud.vault.azure-msi.identity-token-service");
break;
case "CERT":
properties.put("spring.cloud.vault.ssl.key-store", binding.getSecretFilePath("keystore.jks").toString());
map.from("key-store-password").to("spring.cloud.vault.ssl.key-store-password");
map.from("cert-auth-path").to("spring.cloud.vault.ssl.cert-auth-path");
properties.put("spring.cloud.vault.ssl.trust-store", binding.getSecretFilePath("truststore.jks").toString());
map.from("trust-store").to("spring.cloud.vault.ssl.trust-store");
map.from("trust-store-password").to("spring.cloud.vault.ssl.trust-store-password");
break;
case "GCP_IAM":
if (binding.getSecret().containsKey("credentials.json")) {
properties.put("spring.cloud.vault.gcp-iam.credentials.location", binding.getSecretFilePath("credentials.json").toString());
}
map.from("role").to("spring.cloud.vault.gcp-iam.role");
map.from("encoded-key").to("spring.cloud.vault.gcp-iam.credentials.encoded-key");
map.from("gcp-path").to("spring.cloud.vault.gcp-iam.gcp-path");
map.from("jwt-validity").to("spring.cloud.vault.gcp-iam.jwt-validity");
map.from("gcp-project-id").to("spring.cloud.vault.gcp-iam.project-id");
map.from("gcp-service-account").to("spring.cloud.vault.gcp-iam.service-account-id");
break;
case "KUBERNETES":
map.from("role").to("spring.cloud.vault.kubernetes.role");
map.from("kubernetes-path").to("spring.cloud.vault.kubernetes.kubernetes-path");
map.from("kubernetes-service-account-token-file").to("spring.cloud.vault.kubernetes.kubernetes-service-account-token-file");
break;
default:
LOG.warn(String.format("Binding '%s' contains unrecognized 'method'", binding.getName()));
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("uri").to("spring.cloud.vault.uri");
map.from("namespace").to("spring.cloud.vault.namespace"); // vault enterprise feature
String authenticationMethod = binding.getSecret().get("authentication-method");
if (authenticationMethod == null) {
LOG.warn(String.format("Key 'method' is missing from secret of binding '%s'", binding.getName()));
return;
}
properties.put("spring.cloud.vault.authentication", authenticationMethod);
switchCommonProperties(map, authenticationMethod);
switch (authenticationMethod.toUpperCase()) {
case "AWS_IAM":
map.from("role").to("spring.cloud.vault.aws-iam.role");
map.from("aws-path").to("spring.cloud.vault.aws-iam.aws-path");
map.from("aws-sts-endpoint-uri").to("spring.cloud.vault.aws-iam.endpoint-uri");
map.from("aws-iam-server-id").to("spring.cloud.vault.aws-iam.server-id");
break;
case "AZURE_MSI":
map.from("role").to("spring.cloud.vault.azure-msi.role");
map.from("azure-path").to("spring.cloud.vault.azure-msi.azure-path");
break;
case "CERT":
properties.put("spring.cloud.vault.ssl.key-store", binding.getSecretFilePath("keystore.jks").toString());
map.from("key-store-password").to("spring.cloud.vault.ssl.key-store-password");
map.from("cert-auth-path").to("spring.cloud.vault.ssl.cert-auth-path");
break;
case "GCP_IAM":
if (binding.getSecret().containsKey("credentials.json")) {
properties.put("spring.cloud.vault.gcp-iam.credentials.location", binding.getSecretFilePath("credentials.json").toString());
}
map.from("role").to("spring.cloud.vault.gcp-iam.role");
map.from("encoded-key").to("spring.cloud.vault.gcp-iam.credentials.encoded-key");
map.from("gcp-path").to("spring.cloud.vault.gcp-iam.gcp-path");
map.from("jwt-validity").to("spring.cloud.vault.gcp-iam.jwt-validity");
map.from("gcp-project-id").to("spring.cloud.vault.gcp-iam.project-id");
map.from("gcp-service-account").to("spring.cloud.vault.gcp-iam.service-account");
break;
case "KUBERNETES":
map.from("role").to("spring.cloud.vault.kubernetes.role");
map.from("kubernetes-path").to("spring.cloud.vault.kubernetes.kubernetes-path");
break;
default:
LOG.warn(String.format("Binding '%s' contains unrecognized 'method'", binding.getName()));
}
});
}
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
LOG.replayTo(getClass());
}
});
}
/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements BindingsPropertiesProcessor, ApplicationListener<ApplicationPreparedEvent> {
private static final int BOOT_VERSION = 3;
Boot3(int forcedVersion) {
super(forcedVersion);
}
public Boot3() {
}
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isTypeEnabled(environment, TYPE)) {
return;
}
if (!isBootMajorVersionEnabled(BOOT_VERSION)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("uri").to("spring.cloud.vault.uri");
map.from("namespace").to("spring.cloud.vault.namespace"); // vault enterprise feature
String authenticationMethod = binding.getSecret().get("authentication-method");
if (authenticationMethod == null) {
LOG.warn(String.format("Key 'method' is missing from secret of binding '%s'", binding.getName()));
return;
}
properties.put("spring.cloud.vault.authentication", authenticationMethod);
switchCommonProperties(map, authenticationMethod);
switch (authenticationMethod.toUpperCase()) {
case "AWS_IAM":
map.from("role").to("spring.cloud.vault.aws-iam.role");
map.from("aws-path").to("spring.cloud.vault.aws-iam.aws-path");
map.from("aws-sts-endpoint-uri").to("spring.cloud.vault.aws-iam.endpoint-uri");
map.from("aws-iam-server-name").to("spring.cloud.vault.aws-iam.server-name");
break;
case "AZURE_MSI":
map.from("role").to("spring.cloud.vault.azure-msi.role");
map.from("azure-path").to("spring.cloud.vault.azure-msi.azure-path");
map.from("metadata-service").to("spring.cloud.vault.azure-msi.metadata-service");
map.from("identity-token-service").to("spring.cloud.vault.azure-msi.identity-token-service");
break;
case "CERT":
properties.put("spring.cloud.vault.ssl.key-store", binding.getSecretFilePath("keystore.jks").toString());
map.from("key-store-password").to("spring.cloud.vault.ssl.key-store-password");
map.from("cert-auth-path").to("spring.cloud.vault.ssl.cert-auth-path");
properties.put("spring.cloud.vault.ssl.trust-store", binding.getSecretFilePath("truststore.jks").toString());
map.from("trust-store").to("spring.cloud.vault.ssl.trust-store");
map.from("trust-store-password").to("spring.cloud.vault.ssl.trust-store-password");
break;
case "GCP_IAM":
if (binding.getSecret().containsKey("credentials.json")) {
properties.put("spring.cloud.vault.gcp-iam.credentials.location", binding.getSecretFilePath("credentials.json").toString());
}
map.from("role").to("spring.cloud.vault.gcp-iam.role");
map.from("encoded-key").to("spring.cloud.vault.gcp-iam.credentials.encoded-key");
map.from("gcp-path").to("spring.cloud.vault.gcp-iam.gcp-path");
map.from("jwt-validity").to("spring.cloud.vault.gcp-iam.jwt-validity");
map.from("gcp-project-id").to("spring.cloud.vault.gcp-iam.project-id");
map.from("gcp-service-account").to("spring.cloud.vault.gcp-iam.service-account-id");
break;
case "KUBERNETES":
map.from("role").to("spring.cloud.vault.kubernetes.role");
map.from("kubernetes-path").to("spring.cloud.vault.kubernetes.kubernetes-path");
map.from("kubernetes-service-account-token-file").to("spring.cloud.vault.kubernetes.kubernetes-service-account-token-file");
break;
default:
LOG.warn(String.format("Binding '%s' contains unrecognized 'method'", binding.getName()));
}
});
}
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
LOG.replayTo(getClass());
}
}
private static void switchCommonProperties(MapMapper map, String authenticationMethod) {
switch (authenticationMethod.toUpperCase()) {
case "TOKEN":
case "CUBBYHOLE":
map.from("token").to("spring.cloud.vault.token");
break;
case "APPROLE":
map.from("role-id").to("spring.cloud.vault.app-role.role-id");
map.from("secret-id").to("spring.cloud.vault.app-role.secret-id");
map.from("role").to("spring.cloud.vault.app-role.role");
map.from("app-role-path").to("spring.cloud.vault.app-role.app-role-path");
break;
case "AWS_EC2":
map.from("role").to("spring.cloud.vault.aws-ec2.role");
map.from("aws-ec2-path").to("spring.cloud.vault.aws-ec2.aws-ec2-path");
map.from("aws-ec2-instance-identity-document").to("spring.cloud.vault.aws-ec2.identity-document");
map.from("nonce").to("spring.cloud.vault.aws-ec2.nonce");
break;
case "GCP_GCE":
map.from("role").to("spring.cloud.vault.gcp-gce.role");
map.from("gcp-path").to("spring.cloud.vault.gcp-gce.gcp-path");
map.from("gcp-service-account").to("spring.cloud.vault.gcp-gce.service-account");
break;
}
@Override
public void onApplicationEvent(ApplicationPreparedEvent event) {
LOG.replayTo(getClass());
}
}

View File

@@ -2,38 +2,30 @@ org.springframework.context.ApplicationListener=\
org.springframework.cloud.bindings.boot.BindingFlattenedEnvironmentPostProcessor, \
org.springframework.cloud.bindings.boot.BindingSpecificEnvironmentPostProcessor, \
org.springframework.cloud.bindings.boot.SpringSecurityOAuth2BindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor.Boot2, \
org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor.Boot3
org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.cloud.bindings.boot.BindingFlattenedEnvironmentPostProcessor, \
org.springframework.cloud.bindings.boot.BindingSpecificEnvironmentPostProcessor
# Included implementations
org.springframework.cloud.bindings.boot.BindingsPropertiesProcessor=\
org.springframework.cloud.bindings.boot.ArtemisBindingsPropertiesProcessor.Boot2, \
org.springframework.cloud.bindings.boot.ArtemisBindingsPropertiesProcessor.Boot3, \
org.springframework.cloud.bindings.boot.CassandraBindingsPropertiesProcessor.Boot2, \
org.springframework.cloud.bindings.boot.CassandraBindingsPropertiesProcessor.Boot3, \
org.springframework.cloud.bindings.boot.ArtemisBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.CassandraBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.ConfigServerBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.CouchbaseBindingsPropertiesProcessor.Boot2, \
org.springframework.cloud.bindings.boot.CouchbaseBindingsPropertiesProcessor.Boot3, \
org.springframework.cloud.bindings.boot.CouchbaseBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.Db2BindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor.Boot2, \
org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor.Boot3, \
org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.EurekaBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.KafkaBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.LDAPBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.MongoDbBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.MySqlBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.Neo4JBindingsPropertiesProcessor.Boot2, \
org.springframework.cloud.bindings.boot.Neo4JBindingsPropertiesProcessor.Boot3, \
org.springframework.cloud.bindings.boot.Neo4JBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.OracleBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.PostgreSqlBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.RabbitMqBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.RedisBindingsPropertiesProcessor.Boot2, \
org.springframework.cloud.bindings.boot.RedisBindingsPropertiesProcessor.Boot3, \
org.springframework.cloud.bindings.boot.RedisBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.SapHanaBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.SpringSecurityOAuth2BindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.SqlServerBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor.Boot2, \
org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor.Boot3, \
org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.WavefrontBindingsPropertiesProcessor

View File

@@ -32,18 +32,6 @@ import static org.springframework.cloud.bindings.boot.ArtemisBindingsPropertiesP
@DisplayName("ActiveMQ Artemis BindingsPropertiesProcessor")
final class ArtemisBindingsPropertiesProcessorTest {
private final Bindings bindingsSpringBoot2 = new Bindings(
new Binding("test-name", Paths.get("test-path"),
new FluentMap()
.withEntry(Binding.TYPE, TYPE)
.withEntry("mode", "EMBEDDED")
.withEntry("host", "test-host")
.withEntry("port", "test-port")
.withEntry("user", "test-user")
.withEntry("password", "test-password")
)
);
private final Bindings bindingsSpringBoot3 = new Bindings(
new Binding("test-name", Paths.get("test-path"),
new FluentMap()
@@ -60,21 +48,9 @@ final class ArtemisBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties - Spring Boot 2 flavor")
void testSb2() {
new ArtemisBindingsPropertiesProcessor.Boot2(2).process(environment, bindingsSpringBoot2, properties);
assertThat(properties)
.containsEntry("spring.artemis.mode", "EMBEDDED")
.containsEntry("spring.artemis.host", "test-host")
.containsEntry("spring.artemis.password", "test-password")
.containsEntry("spring.artemis.port", "test-port")
.containsEntry("spring.artemis.user", "test-user");
}
@Test
@DisplayName("contributes properties - Spring Boot 3 flavor")
@DisplayName("contributes properties")
void testSb3() {
new ArtemisBindingsPropertiesProcessor.Boot3(3).process(environment, bindingsSpringBoot3, properties);
new ArtemisBindingsPropertiesProcessor().process(environment, bindingsSpringBoot3, properties);
assertThat(properties)
.containsEntry("spring.artemis.mode", "EMBEDDED")
.containsEntry("spring.artemis.broker-url", "tcp://test-host:test-port")
@@ -87,10 +63,7 @@ final class ArtemisBindingsPropertiesProcessorTest {
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.artemis.enable", "false");
new ArtemisBindingsPropertiesProcessor.Boot2(2).process(environment, bindingsSpringBoot2, properties);
assertThat(properties).isEmpty();
new ArtemisBindingsPropertiesProcessor.Boot3(3).process(environment, bindingsSpringBoot2, properties);
new ArtemisBindingsPropertiesProcessor().process(environment, bindingsSpringBoot3, properties);
assertThat(properties).isEmpty();
}

View File

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

View File

@@ -56,28 +56,9 @@ final class CassandraBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties - Spring Boot 2 flavor")
void testSb2() {
new CassandraBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.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")
.containsEntry("spring.data.cassandra.request.throttler.drain-interval", "test-drain-interval")
.containsEntry("spring.data.cassandra.request.throttler.max-concurrent-requests", "test-max-concurrent-requests")
.containsEntry("spring.data.cassandra.request.throttler.max-queue-size", "test-max-queue-size")
.containsEntry("spring.data.cassandra.request.throttler.max-requests-per-second", "test-max-requests-per-second");
}
@Test
@DisplayName("contributes properties - Spring Boot 3 flavor")
@DisplayName("contributes properties")
void testSb3() {
new CassandraBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new CassandraBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cassandra.cluster-name", "test-cluster-name")
.containsEntry("spring.cassandra.compression", "test-compression")
@@ -98,10 +79,7 @@ final class CassandraBindingsPropertiesProcessorTest {
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.cassandra.enable", "false");
new CassandraBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties).isEmpty();
new CassandraBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new CassandraBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -32,20 +32,6 @@ import static org.springframework.cloud.bindings.boot.CouchbaseBindingsPropertie
@DisplayName("Couchbase BindingsPropertiesProcessor")
final class CouchbaseBindingsPropertiesProcessorTest {
private final Bindings bindingsSpringBoot2 = new Bindings(
new Binding("test-name", Paths.get("test-path"),
new FluentMap()
.withEntry(Binding.TYPE, TYPE)
.withEntry("bootstrap-hosts", "test-bootstrap-hosts")
.withEntry("bucket.name", "test-bucket-name")
.withEntry("bucket.password", "test-bucket-password")
.withEntry("env.bootstrap.http-direct-port", "test-env-bootstrap-http-direct-port")
.withEntry("env.bootstrap.http-ssl-port", "test-env-bootstrap-http-ssl-port")
.withEntry("password", "test-password")
.withEntry("username", "test-username")
)
);
private final Bindings bindingsSpringBoot3 = new Bindings(
new Binding("test-name", Paths.get("test-path"),
new FluentMap()
@@ -62,23 +48,9 @@ final class CouchbaseBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties - Spring Boot 2 flavor")
void testSb2() {
new CouchbaseBindingsPropertiesProcessor.Boot2(2).process(environment, bindingsSpringBoot2, properties);
assertThat(properties)
.containsEntry("spring.couchbase.bootstrap-hosts", "test-bootstrap-hosts")
.containsEntry("spring.couchbase.bucket.name", "test-bucket-name")
.containsEntry("spring.couchbase.bucket.password", "test-bucket-password")
.containsEntry("spring.couchbase.env.bootstrap.http-direct-port", "test-env-bootstrap-http-direct-port")
.containsEntry("spring.couchbase.env.bootstrap.http-ssl-port", "test-env-bootstrap-http-ssl-port")
.containsEntry("spring.couchbase.password", "test-password")
.containsEntry("spring.couchbase.username", "test-username");
}
@Test
@DisplayName("contributes properties - Spring Boot 3 flavor")
@DisplayName("contributes properties")
void testSb3() {
new CouchbaseBindingsPropertiesProcessor.Boot3(3).process(environment, bindingsSpringBoot3, properties);
new CouchbaseBindingsPropertiesProcessor().process(environment, bindingsSpringBoot3, properties);
assertThat(properties)
.containsEntry("spring.couchbase.connection-string", "test-connection-string")
.containsEntry("spring.data.couchbase.bucket-name", "test-bucket-name")
@@ -91,10 +63,7 @@ final class CouchbaseBindingsPropertiesProcessorTest {
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.couchbase.enable", "false");
new CouchbaseBindingsPropertiesProcessor.Boot2(2).process(environment, bindingsSpringBoot2, properties);
assertThat(properties).isEmpty();
new CouchbaseBindingsPropertiesProcessor.Boot3(3).process(environment, bindingsSpringBoot3, properties);
new CouchbaseBindingsPropertiesProcessor().process(environment, bindingsSpringBoot3, properties);
assertThat(properties).isEmpty();
}

View File

@@ -32,20 +32,6 @@ import static org.springframework.cloud.bindings.boot.ElasticsearchBindingsPrope
@DisplayName("Elasticsearch BindingsPropertiesProcessor")
final class ElasticsearchBindingsPropertiesProcessorTest {
private final Bindings bindingsSpringBoot2 = new Bindings(
new Binding("test-name", Paths.get("test-path"),
new FluentMap()
.withEntry(Binding.TYPE, TYPE)
.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 Bindings bindingsSpringBoot3 = new Bindings(
new Binding("test-name", Paths.get("test-path"),
new FluentMap()
@@ -61,28 +47,10 @@ final class ElasticsearchBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties - Spring Boot 2 flavor")
void testSb2() {
new ElasticsearchBindingsPropertiesProcessor.Boot2(2).process(environment, bindingsSpringBoot2, 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("contributes properties - Spring Boot 2 flavor")
void testSb3() {
new ElasticsearchBindingsPropertiesProcessor.Boot3(3).process(environment, bindingsSpringBoot3, properties);
new ElasticsearchBindingsPropertiesProcessor().process(environment, bindingsSpringBoot3, properties);
assertThat(properties)
.containsEntry("spring.elasticsearch.password", "test-password")
.containsEntry("spring.elasticsearch.uris", "test-uris")
@@ -94,10 +62,7 @@ final class ElasticsearchBindingsPropertiesProcessorTest {
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.elasticsearch.enable", "false");
new ElasticsearchBindingsPropertiesProcessor.Boot2(2).process(environment, bindingsSpringBoot2, properties);
assertThat(properties).isEmpty();
new ElasticsearchBindingsPropertiesProcessor.Boot3(3).process(environment, bindingsSpringBoot3, properties);
new ElasticsearchBindingsPropertiesProcessor().process(environment, bindingsSpringBoot3, properties);
assertThat(properties).isEmpty();
}

View File

@@ -47,19 +47,9 @@ final class Neo4JBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties - Spring Boot 2 flavor")
void testSb2() {
new Neo4JBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.data.neo4j.password", "test-password")
.containsEntry("spring.data.neo4j.uri", "test-uri")
.containsEntry("spring.data.neo4j.username", "test-username");
}
@Test
@DisplayName("contributes properties - Spring Boot 3 flavor")
@DisplayName("contributes properties")
void testSb3() {
new Neo4JBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new Neo4JBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.neo4j.authentication.password", "test-password")
.containsEntry("spring.neo4j.uri", "test-uri")
@@ -71,10 +61,7 @@ final class Neo4JBindingsPropertiesProcessorTest {
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.neo4j.enable", "false");
new Neo4JBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties).isEmpty();
new Neo4JBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new Neo4JBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -55,27 +55,9 @@ final class RedisBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties - Spring Boot 2 flavor")
void testSb2() {
new RedisBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.redis.client-name", "test-client-name")
.containsEntry("spring.redis.cluster.max-redirects", "test-cluster-max-redirects")
.containsEntry("spring.redis.cluster.nodes", "test-cluster-nodes")
.containsEntry("spring.redis.database", "test-database")
.containsEntry("spring.redis.host", "test-host")
.containsEntry("spring.redis.password", "test-password")
.containsEntry("spring.redis.port", "test-port")
.containsEntry("spring.redis.sentinel.master", "test-sentinel-master")
.containsEntry("spring.redis.sentinel.nodes", "test-sentinel-nodes")
.containsEntry("spring.redis.ssl", "test-ssl")
.containsEntry("spring.redis.url", "test-url");
}
@Test
@DisplayName("contributes properties - Spring Boot 3 flavor")
@DisplayName("contributes properties")
void testSb3() {
new RedisBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new RedisBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.data.redis.client-name", "test-client-name")
@@ -96,12 +78,8 @@ final class RedisBindingsPropertiesProcessorTest {
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.redis.enable", "false");
new RedisBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
new RedisBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
new RedisBindingsPropertiesProcessor.Boot2(3).process(environment, bindings, properties);
assertThat(properties).isEmpty();
}
}

View File

@@ -1,33 +0,0 @@
package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class SpringBootVersionResolverTest {
@Test
@DisplayName("Should return Spring Boot 2 as Major Version since it's the provided runtime")
void isBootMajorVersionEnabled() {
SpringBootVersionResolver springBootVersionResolver = new SpringBootVersionResolver();
assertTrue(springBootVersionResolver.isBootMajorVersionEnabled(2));
assertFalse(springBootVersionResolver.isBootMajorVersionEnabled(3));
}
@Test
@DisplayName("Should return the forced version 2")
void isBootMajorVersionEnabled_forced_version2() {
SpringBootVersionResolver springBootVersionResolver = new SpringBootVersionResolver(2);
assertTrue(springBootVersionResolver.isBootMajorVersionEnabled(2));
assertFalse(springBootVersionResolver.isBootMajorVersionEnabled(3));
}
@Test
@DisplayName("Should return the forced version 3")
void isBootMajorVersionEnabled_forced_version3() {
SpringBootVersionResolver springBootVersionResolver = new SpringBootVersionResolver(3);
assertFalse(springBootVersionResolver.isBootMajorVersionEnabled(2));
assertTrue(springBootVersionResolver.isBootMajorVersionEnabled(3));
}
}

View File

@@ -47,12 +47,6 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
.containsEntry("spring.cloud.vault.authentication", "token")
.containsEntry("spring.cloud.vault.token", "test-token");
}
@Test
@@ -69,7 +63,7 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
@@ -91,7 +85,7 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
@@ -114,16 +108,7 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
.containsEntry("spring.cloud.vault.authentication", "cert")
.containsEntry("spring.cloud.vault.ssl.key-store", "test-path/keystore.jks")
.containsEntry("spring.cloud.vault.ssl.key-store-password", "test-key-store-password")
.containsEntry("spring.cloud.vault.ssl.cert-auth-path", "test-cert-auth-path");
new VaultBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
@@ -149,15 +134,6 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
.containsEntry("spring.cloud.vault.authentication", "aws_ec2")
.containsEntry("spring.cloud.vault.aws-ec2.role", "test-role")
.containsEntry("spring.cloud.vault.aws-ec2.aws-ec2-path", "test-aws-ec2-path")
.containsEntry("spring.cloud.vault.aws-ec2.identity-document", "test-identity-document")
.containsEntry("spring.cloud.vault.aws-ec2.nonce", "test-nonce");
}
@Test
@@ -175,17 +151,7 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
.containsEntry("spring.cloud.vault.authentication", "aws_iam")
.containsEntry("spring.cloud.vault.aws-iam.role", "test-role")
.containsEntry("spring.cloud.vault.aws-iam.aws-path", "test-aws-path")
.containsEntry("spring.cloud.vault.aws-iam.server-id", "test-server-id")
.containsEntry("spring.cloud.vault.aws-iam.endpoint-uri", "test-endpoint-uri");
new VaultBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
@@ -210,15 +176,7 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
.containsEntry("spring.cloud.vault.authentication", "azure_msi")
.containsEntry("spring.cloud.vault.azure-msi.role", "test-role")
.containsEntry("spring.cloud.vault.azure-msi.azure-path", "test-azure-path");
new VaultBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
@@ -242,14 +200,6 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
.containsEntry("spring.cloud.vault.authentication", "gcp_gce")
.containsEntry("spring.cloud.vault.gcp-gce.role", "test-role")
.containsEntry("spring.cloud.vault.gcp-gce.gcp-path", "test-gcp-path")
.containsEntry("spring.cloud.vault.gcp-gce.service-account", "test-service-account");
}
@Test
@@ -269,20 +219,7 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
.containsEntry("spring.cloud.vault.authentication", "gcp_iam")
.containsEntry("spring.cloud.vault.gcp-iam.role", "test-role")
.containsEntry("spring.cloud.vault.gcp-iam.credentials.location", "test-path/credentials.json")
.containsEntry("spring.cloud.vault.gcp-iam.credentials.encoded-key", "test-encoded-key")
.containsEntry("spring.cloud.vault.gcp-iam.gcp-path", "test-gcp-path")
.containsEntry("spring.cloud.vault.gcp-iam.jwt-validity", "test-jwt-validity")
.containsEntry("spring.cloud.vault.gcp-iam.project-id", "test-project-id")
.containsEntry("spring.cloud.vault.gcp-iam.service-account", "test-service-account");
new VaultBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
@@ -309,15 +246,7 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
.containsEntry("spring.cloud.vault.authentication", "kubernetes")
.containsEntry("spring.cloud.vault.kubernetes.role", "test-role")
.containsEntry("spring.cloud.vault.kubernetes.kubernetes-path", "test-kubernetes-path");
new VaultBindingsPropertiesProcessor.Boot3(3).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
@@ -336,7 +265,7 @@ final class VaultBindingsPropertiesProcessorTest {
)
);
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.cloud.vault.uri", "test-uri")
.containsEntry("spring.cloud.vault.namespace", "test-namespace")
@@ -376,7 +305,7 @@ final class VaultBindingsPropertiesProcessorTest {
environment.setProperty("org.springframework.cloud.bindings.boot.vault.enable", "false");
new VaultBindingsPropertiesProcessor.Boot2(2).process(environment, bindings, properties);
new VaultBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}