Per-kind Disabling

Previously, auto-configuration of all kinds of bindings were either enabled or
disabled en-mass.  This level of granularity wasn't really appropriate in
practice as it many use-cases could be served with some bindings but not
others.  This change updates each auto-configuration to watch for a particular
key to be disabled.

[resolves #29]

Signed-off-by: Ben Hale <bhale@vmware.com>
This commit is contained in:
Ben Hale
2020-05-11 09:36:54 -07:00
parent 09332e92ff
commit de2422fdf5
20 changed files with 331 additions and 119 deletions

View File

@@ -23,6 +23,8 @@ import org.springframework.lang.NonNull;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*/
@@ -35,6 +37,10 @@ public final class CassandraBindingsPropertiesProcessor implements BindingsPrope
@Override
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();

View File

@@ -23,6 +23,8 @@ import org.springframework.lang.NonNull;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*
@@ -37,6 +39,10 @@ public final class Db2BindingsPropertiesProcessor implements BindingsPropertiesP
@Override
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.bindings.boot;
import org.jetbrains.annotations.NotNull;
final class KindGuard {
static boolean isKindEnabled(@NotNull String kind) {
String property = String.format("org.springframework.cloud.bindings.boot.%s.enable", kind.toLowerCase());
String value = System.getProperty(property, "true");
return Boolean.parseBoolean(value);
}
}

View File

@@ -22,6 +22,8 @@ import org.springframework.lang.NonNull;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*/
@@ -34,6 +36,10 @@ public final class MongoDbBindingsPropertiesProcessor implements BindingsPropert
@Override
public void process(@NonNull Bindings bindings, @NonNull Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();

View File

@@ -23,6 +23,8 @@ import org.springframework.lang.NonNull;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*
@@ -37,6 +39,10 @@ public final class MySqlBindingsPropertiesProcessor implements BindingsPropertie
@Override
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();

View File

@@ -23,6 +23,8 @@ import org.springframework.lang.NonNull;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*
@@ -37,6 +39,10 @@ public final class OracleBindingsPropertiesProcessor implements BindingsProperti
@Override
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();

View File

@@ -23,6 +23,8 @@ import org.springframework.lang.NonNull;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*
@@ -37,6 +39,10 @@ public final class PostgreSqlBindingsPropertiesProcessor implements BindingsProp
@Override
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();

View File

@@ -23,6 +23,8 @@ import org.springframework.lang.NonNull;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*/
@@ -35,6 +37,10 @@ public final class RedisBindingsPropertiesProcessor implements BindingsPropertie
@Override
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();

View File

@@ -23,6 +23,8 @@ import org.springframework.lang.NonNull;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*
@@ -37,6 +39,10 @@ public final class SqlServerBindingsPropertiesProcessor implements BindingsPrope
@Override
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
Map<String, String> secret = binding.getSecret();