Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11' ]
java: [ '8', '11', '17' ]
name: Java ${{ matrix.Java }} build
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
buildscript {
ext {
jmockitVersion = "1.49"
springBootVersion = "2.6.6"
springBootVersion = "2.6.14"
springBoot3Version = "3.0.4"
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
48 changes: 48 additions & 0 deletions java-cfenv-boot/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
=== Redis
Type: `redis`
Disable Property: `cfenv.service.redis.enabled`

==== Spring Boot 2 properties

| Property | Value |
| ------------------------------------ | ------------------------- |
| `spring.redis.host` | `{host}` |
| `spring.redis.password` | `{password}` |
| `spring.redis.port` | `{port}` |
| `spring.redis.ssl` | `{ssl}` |


Not supported, compared to `spring-cloud-bindings`:

| 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.sentinel.master` | `{sentinel.master}` |
| `spring.redis.sentinel.nodes` | `{sentinel.nodes}` |
| `spring.redis.url` | `{url}` |



==== Spring Boot 3 properties

| Property | Value |
|-------------------------------------------|---------------------------|
| `spring.data.redis.host` | `{host}` |
| `spring.data.redis.password` | `{password}` |
| `spring.data.redis.port` | `{port}` |
| `spring.data.redis.ssl` | `{ssl}` |

Not supported, compared to `spring-cloud-bindings`:

| Property | Value |
|-------------------------------------------|---------------------------|
| `spring.data.redis.client-name` | `{client-name}` |
| `spring.data.redis.cluster.max-redirects` | `{cluster.max-redirects}` |
| `spring.data.redis.cluster.nodes` | `{cluster.nodes}` |
| `spring.data.redis.database` | `{database}` |
| `spring.data.redis.sentinel.master` | `{sentinel.master}` |
| `spring.data.redis.sentinel.nodes` | `{sentinel.nodes}` |
| `spring.data.redis.url` | `{url}` |
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,60 @@
/**
* @author Mark Pollack
*/
public class CassandraCfEnvProcessor implements CfEnvProcessor {
public class CassandraCfEnvProcessor {

@Override
public boolean accept(CfService service) {
public final static class Boot2 implements CfEnvProcessor {

private static final int BOOT_VERSION = 2;
private static final String PREFIX = "spring.data.cassandra";

@Override
public boolean accept(CfService service) {
if (!SpringBootVersionResolver.isBootMajorVersionEnabled(BOOT_VERSION)) {
return false;
}
return CassandraCfEnvProcessor.accept(service);
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
CassandraCfEnvProcessor.process(cfCredentials, properties, PREFIX);
}

@Override
public CfEnvProcessorProperties getProperties() {
return CassandraCfEnvProcessor.getProperties(PREFIX);
}
}

/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements CfEnvProcessor {

private static final int BOOT_VERSION = 3;
private static final String PREFIX = "spring.cassandra";

@Override
public boolean accept(CfService service) {
if (!SpringBootVersionResolver.isBootMajorVersionEnabled(BOOT_VERSION)) {
return false;
}
return CassandraCfEnvProcessor.accept(service);
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
CassandraCfEnvProcessor.process(cfCredentials, properties, PREFIX);
}

@Override
public CfEnvProcessorProperties getProperties() {
return CassandraCfEnvProcessor.getProperties(PREFIX);
}
}

static boolean accept(CfService service) {
boolean serviceIsBound = service.existsByTagIgnoreCase("cassandra") &&
cassandraCredentialsPresent(service.getCredentials().getMap());
if (serviceIsBound) {
Expand All @@ -38,26 +88,24 @@ public boolean accept(CfService service) {
return serviceIsBound;
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
properties.put("spring.data.cassandra.username", cfCredentials.getUsername());
properties.put("spring.data.cassandra.password", cfCredentials.getPassword());
properties.put("spring.data.cassandra.port", cfCredentials.getMap().get("cqlsh_port"));
static void process(CfCredentials cfCredentials, Map<String, Object> properties, String prefix) {
properties.put(prefix + ".username", cfCredentials.getUsername());
properties.put(prefix + ".password", cfCredentials.getPassword());
properties.put(prefix + ".port", cfCredentials.getMap().get("cqlsh_port"));
ArrayList<String> contactPoints = (ArrayList<String>) cfCredentials.getMap().get("node_ips");
properties.put("spring.data.cassandra.contact-points",
properties.put(prefix + ".contact-points",
StringUtils.collectionToCommaDelimitedString(contactPoints));

}

private boolean cassandraCredentialsPresent(Map<String, Object> credentials) {
static boolean cassandraCredentialsPresent(Map<String, Object> credentials) {
return credentials != null &&
credentials.containsKey("cqlsh_port") &&
credentials.containsKey("node_ips");
}

@Override
public CfEnvProcessorProperties getProperties() {
return CfEnvProcessorProperties.builder().propertyPrefixes("spring.data.cassandra")
static CfEnvProcessorProperties getProperties(String prefix) {
return CfEnvProcessorProperties.builder().propertyPrefixes(prefix)
.serviceName("Cassandra").build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,62 @@
* @author Mark Pollack
* @author Scott Frederick
*/
public class RedisCfEnvProcessor implements CfEnvProcessor {
public class RedisCfEnvProcessor {

private static String[] redisSchemes = { "redis", "rediss" };
private final static String[] redisSchemes = { "redis", "rediss" };

@Override
public boolean accept(CfService service) {
public final static class Boot2 implements CfEnvProcessor {

private static final int BOOT_VERSION = 2;
private static final String PREFIX = "spring.redis";

@Override
public boolean accept(CfService service) {
if (!SpringBootVersionResolver.isBootMajorVersionEnabled(BOOT_VERSION)) {
return false;
}
return RedisCfEnvProcessor.accept(service);
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
RedisCfEnvProcessor.process(cfCredentials, properties, PREFIX);
}

@Override
public CfEnvProcessorProperties getProperties() {
return RedisCfEnvProcessor.getProperties(PREFIX);
}
}

/**
* This is a special case for Boot 3.
*/
public final static class Boot3 extends SpringBootVersionResolver implements CfEnvProcessor {

private static final int BOOT_VERSION = 3;
private static final String PREFIX = "spring.data.redis";

@Override
public boolean accept(CfService service) {
if (!SpringBootVersionResolver.isBootMajorVersionEnabled(BOOT_VERSION)) {
return false;
}
return RedisCfEnvProcessor.accept(service);
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
RedisCfEnvProcessor.process(cfCredentials, properties, PREFIX);
}

@Override
public CfEnvProcessorProperties getProperties() {
return RedisCfEnvProcessor.getProperties(PREFIX);
}
}

public static boolean accept(CfService service) {
boolean serviceIsBound = service.existsByTagIgnoreCase("redis") ||
service.existsByLabelStartsWith("rediscloud") ||
service.existsByUriSchemeStartsWith(redisSchemes) ||
Expand All @@ -45,38 +95,36 @@ public boolean accept(CfService service) {
return serviceIsBound;
}

@Override
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
private static void process(CfCredentials cfCredentials, Map<String, Object> properties, String prefix) {
String uri = cfCredentials.getUri(redisSchemes);

if (uri == null) {
properties.put("spring.redis.host", cfCredentials.getHost());
properties.put("spring.redis.password", cfCredentials.getPassword());
properties.put(prefix + ".host", cfCredentials.getHost());
properties.put(prefix + ".password", cfCredentials.getPassword());

Optional<String> tlsPort = Optional.ofNullable(cfCredentials.getString("tls_port"));
if (tlsPort.isPresent()) {
properties.put("spring.redis.port", tlsPort.get());
properties.put("spring.redis.ssl", "true");
properties.put(prefix + ".port", tlsPort.get());
properties.put(prefix + ".ssl", "true");
}
else {
properties.put("spring.redis.port", cfCredentials.getPort());
properties.put(prefix + ".port", cfCredentials.getPort());
}
}
else {
UriInfo uriInfo = new UriInfo(uri);
properties.put("spring.redis.host", uriInfo.getHost());
properties.put("spring.redis.port", uriInfo.getPort());
properties.put("spring.redis.password", uriInfo.getPassword());
properties.put(prefix + ".host", uriInfo.getHost());
properties.put(prefix + ".port", uriInfo.getPort());
properties.put(prefix + ".password", uriInfo.getPassword());
if (uriInfo.getScheme().equals("rediss")) {
properties.put("spring.redis.ssl", "true");
properties.put(prefix + ".ssl", "true");
}
}
}

@Override
public CfEnvProcessorProperties getProperties() {
static CfEnvProcessorProperties getProperties(String prefix) {
return CfEnvProcessorProperties.builder()
.propertyPrefixes("spring.redis")
.propertyPrefixes(prefix)
.serviceName("Redis")
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 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
*
* https://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 io.pivotal.cfenv.spring.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 {
static int forcedVersion = -1;

static boolean isBootMajorVersionEnabled(int bootVersion) {
if (forcedVersion != -1) {
return forcedVersion == bootVersion;
}
int major = Integer.parseInt(SpringBootVersion.getVersion().split("\\.")[0]);
return major == bootVersion;
}
}
6 changes: 4 additions & 2 deletions java-cfenv-boot/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ org.springframework.context.ApplicationListener=\
io.pivotal.cfenv.spring.boot.CfEnvironmentPostProcessor
# CfEnvironmentPostProcessor delegates to these CfEnvProcessors for each CF service
io.pivotal.cfenv.spring.boot.CfEnvProcessor=\
io.pivotal.cfenv.spring.boot.RedisCfEnvProcessor,\
io.pivotal.cfenv.spring.boot.RedisCfEnvProcessor.Boot2,\
io.pivotal.cfenv.spring.boot.RedisCfEnvProcessor.Boot3,\
io.pivotal.cfenv.spring.boot.MongoCfEnvProcessor,\
io.pivotal.cfenv.spring.boot.AmqpCfEnvProcessor,\
io.pivotal.cfenv.spring.boot.CredHubCfEnvProcessor,\
io.pivotal.cfenv.spring.boot.CassandraCfEnvProcessor,\
io.pivotal.cfenv.spring.boot.CassandraCfEnvProcessor.Boot2,\
io.pivotal.cfenv.spring.boot.CassandraCfEnvProcessor.Boot3,\
io.pivotal.cfenv.spring.boot.VaultCfEnvProcessor


Loading