From fe843860f70bdb14cda22e77442c592a7c9003b5 Mon Sep 17 00:00:00 2001 From: Ben Hale Date: Tue, 14 Jul 2020 10:52:49 -0700 Subject: [PATCH] Support Kubernetes Service Bindings This change updates the library to support the new Kubernetes Service Bindings[1]. [1]: https://github.com/k8s-service-bindings/spec#application-projection Signed-off-by: Ben Hale --- README.md | 50 +-- .../cloud/bindings/Binding.java | 172 ++++++---- .../cloud/bindings/Bindings.java | 46 ++- ...dingFlattenedEnvironmentPostProcessor.java | 5 +- .../CassandraBindingsPropertiesProcessor.java | 12 +- ...nfigServerBindingsPropertiesProcessor.java | 12 +- .../CouchbaseBindingsPropertiesProcessor.java | 12 +- .../boot/Db2BindingsPropertiesProcessor.java | 12 +- ...sticsearchBindingsPropertiesProcessor.java | 12 +- .../EurekaBindingsPropertiesProcessor.java | 12 +- .../cloud/bindings/boot/Guards.java | 4 +- .../KafkaBindingsPropertiesProcessor.java | 12 +- .../boot/LDAPBindingsPropertiesProcessor.java | 12 +- .../MongoDbBindingsPropertiesProcessor.java | 12 +- .../MySqlBindingsPropertiesProcessor.java | 12 +- .../Neo4JBindingsPropertiesProcessor.java | 12 +- .../OracleBindingsPropertiesProcessor.java | 12 +- ...PostgreSqlBindingsPropertiesProcessor.java | 12 +- .../RabbitMqBindingsPropertiesProcessor.java | 12 +- .../RedisBindingsPropertiesProcessor.java | 12 +- ...rityOAuth2BindingsPropertiesProcessor.java | 12 +- .../SqlServerBindingsPropertiesProcessor.java | 12 +- .../VaultBindingsPropertiesProcessor.java | 12 +- .../WavefrontBindingsPropertiesProcessor.java | 12 +- .../cloud/bindings/BindingTest.java | 84 +++-- .../cloud/bindings/BindingsTest.java | 199 ++++++++++++ .../cloud/bindings/BindingsTests.java | 105 ------ ...FlattenedEnvironmentPostProcessorTest.java | 10 +- ...gSpecificEnvironmentPostProcessorTest.java | 9 +- ...sandraBindingsPropertiesProcessorTest.java | 5 +- ...ServerBindingsPropertiesProcessorTest.java | 5 +- ...chbaseBindingsPropertiesProcessorTest.java | 5 +- .../Db2BindingsPropertiesProcessorTest.java | 5 +- ...searchBindingsPropertiesProcessorTest.java | 5 +- ...EurekaBindingsPropertiesProcessorTest.java | 5 +- .../cloud/bindings/boot/GuardsTest.java | 12 +- .../KafkaBindingsPropertiesProcessorTest.java | 5 +- .../LDAPBindingsPropertiesProcessorTest.java | 5 +- ...ongoDbBindingsPropertiesProcessorTest.java | 5 +- .../MySqlBindingsPropertiesProcessorTest.java | 5 +- .../Neo4JBindingsPropertiesProcessorTest.java | 5 +- ...OracleBindingsPropertiesProcessorTest.java | 5 +- ...greSqlBindingsPropertiesProcessorTest.java | 5 +- ...bbitMqBindingsPropertiesProcessorTest.java | 5 +- .../RedisBindingsPropertiesProcessorTest.java | 5 +- ...OAuth2BindingsPropertiesProcessorTest.java | 20 +- ...ServerBindingsPropertiesProcessorTest.java | 5 +- ...VaultBindingsPropertiesProcessorTest.java} | 298 ++++++++++-------- ...frontBindingsPropertiesProcessorTest.java} | 7 +- .../{ => cnb}/test-k8s/metadata/.hidden-data | 0 .../test-k8s/metadata/.hidden-data-1/kind | 0 .../test-k8s/metadata/.hidden-data-1/provider | 0 .../metadata/.hidden-data-1/test-metadata-key | 1 + .../{ => cnb}/test-k8s/metadata/kind | 0 .../{ => cnb}/test-k8s/metadata/provider | 0 .../cnb/test-k8s/metadata/test-metadata-key | 1 + .../{ => cnb}/test-k8s/secret/.hidden-data | 0 .../secret/.hidden-data-1/test-secret-key | 1 + .../cnb/test-k8s/secret/test-secret-key | 1 + .../{ => cnb}/test-name-1/metadata/kind | 0 .../{ => cnb}/test-name-1/metadata/provider | 0 .../test-name-1/metadata/test-metadata-key | 1 + .../cnb/test-name-1/secret/test-secret-key | 1 + .../{ => cnb}/test-name-2/metadata/kind | 0 .../{ => cnb}/test-name-2/metadata/provider | 0 .../test-name-2/metadata/test-metadata-key | 1 + .../cnb/test-name-2/secret/test-secret-key | 1 + src/test/resources/k8s/test-k8s/.hidden-data | 1 + .../k8s/test-k8s/.hidden-data-1/provider | 1 + .../test-k8s/.hidden-data-1/test-secret-key | 1 + .../k8s/test-k8s/.hidden-data-1/type | 1 + src/test/resources/k8s/test-k8s/provider | 1 + .../resources/k8s/test-k8s/test-secret-key | 1 + src/test/resources/k8s/test-k8s/type | 1 + src/test/resources/k8s/test-name-1/provider | 1 + .../resources/k8s/test-name-1/test-secret-key | 1 + src/test/resources/k8s/test-name-1/type | 1 + src/test/resources/k8s/test-name-2/provider | 1 + .../resources/k8s/test-name-2/test-secret-key | 1 + src/test/resources/k8s/test-name-2/type | 1 + .../test-k8s/metadata/.hidden-data-1/.gitkeep | 0 .../test-k8s/secret/.hidden-data-1/.gitkeep | 0 .../test-k8s/secret/.hidden-data-1/test-key | 1 - src/test/resources/test-k8s/secret/test-key | 1 - .../resources/test-name-1/secret/test-key | 1 - .../resources/test-name-2/secret/test-key | 1 - 86 files changed, 787 insertions(+), 567 deletions(-) create mode 100644 src/test/java/org/springframework/cloud/bindings/BindingsTest.java delete mode 100644 src/test/java/org/springframework/cloud/bindings/BindingsTests.java rename src/test/java/org/springframework/cloud/bindings/boot/{VaultPropertiesProcessorTest.java => VaultBindingsPropertiesProcessorTest.java} (56%) rename src/test/java/org/springframework/cloud/bindings/boot/{WavefrontPropertiesProcessorTest.java => WavefrontBindingsPropertiesProcessorTest.java} (93%) rename src/test/resources/{ => cnb}/test-k8s/metadata/.hidden-data (100%) rename src/test/resources/{ => cnb}/test-k8s/metadata/.hidden-data-1/kind (100%) rename src/test/resources/{ => cnb}/test-k8s/metadata/.hidden-data-1/provider (100%) create mode 100644 src/test/resources/cnb/test-k8s/metadata/.hidden-data-1/test-metadata-key rename src/test/resources/{ => cnb}/test-k8s/metadata/kind (100%) rename src/test/resources/{ => cnb}/test-k8s/metadata/provider (100%) create mode 120000 src/test/resources/cnb/test-k8s/metadata/test-metadata-key rename src/test/resources/{ => cnb}/test-k8s/secret/.hidden-data (100%) create mode 100644 src/test/resources/cnb/test-k8s/secret/.hidden-data-1/test-secret-key create mode 120000 src/test/resources/cnb/test-k8s/secret/test-secret-key rename src/test/resources/{ => cnb}/test-name-1/metadata/kind (100%) rename src/test/resources/{ => cnb}/test-name-1/metadata/provider (100%) create mode 100644 src/test/resources/cnb/test-name-1/metadata/test-metadata-key create mode 100644 src/test/resources/cnb/test-name-1/secret/test-secret-key rename src/test/resources/{ => cnb}/test-name-2/metadata/kind (100%) rename src/test/resources/{ => cnb}/test-name-2/metadata/provider (100%) create mode 100644 src/test/resources/cnb/test-name-2/metadata/test-metadata-key create mode 100644 src/test/resources/cnb/test-name-2/secret/test-secret-key create mode 120000 src/test/resources/k8s/test-k8s/.hidden-data create mode 100644 src/test/resources/k8s/test-k8s/.hidden-data-1/provider create mode 100644 src/test/resources/k8s/test-k8s/.hidden-data-1/test-secret-key create mode 100644 src/test/resources/k8s/test-k8s/.hidden-data-1/type create mode 120000 src/test/resources/k8s/test-k8s/provider create mode 120000 src/test/resources/k8s/test-k8s/test-secret-key create mode 120000 src/test/resources/k8s/test-k8s/type create mode 100644 src/test/resources/k8s/test-name-1/provider create mode 100644 src/test/resources/k8s/test-name-1/test-secret-key create mode 100644 src/test/resources/k8s/test-name-1/type create mode 100644 src/test/resources/k8s/test-name-2/provider create mode 100644 src/test/resources/k8s/test-name-2/test-secret-key create mode 100644 src/test/resources/k8s/test-name-2/type delete mode 100644 src/test/resources/test-k8s/metadata/.hidden-data-1/.gitkeep delete mode 100644 src/test/resources/test-k8s/secret/.hidden-data-1/.gitkeep delete mode 100644 src/test/resources/test-k8s/secret/.hidden-data-1/test-key delete mode 120000 src/test/resources/test-k8s/secret/test-key delete mode 100644 src/test/resources/test-name-1/secret/test-key delete mode 100644 src/test/resources/test-name-2/secret/test-key diff --git a/README.md b/README.md index bb86112..39d0400 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Spring Cloud Bindings -The Spring Cloud Bindings library exposes a rich Java language binding for the [Cloud Native Buildpacks Binding Specification][s]. In addition, if opted-in, it configures Spring Boot application configuration properties appropriate for the kind of binding encountered. +The Spring Cloud Bindings library exposes a rich Java language binding for the [Cloud Native Buildpacks Binding Specification][s]. In addition, if opted-in, it configures Spring Boot application configuration properties appropriate for the type of binding encountered. [s]: https://github.com/buildpacks/spec/blob/master/extensions/bindings.md @@ -30,10 +30,10 @@ The more common usage of the library is opt-in automatic Spring Boot configurati * Adds a `PropertySource` with binding-specific Spring Boot configuration properties. ## Auto-Configurations -Each auto-configuration is triggered by the kind of binding. Each auto-configuration can be disabled using a System Property specific to that kind and defaults to enable. Auto-configuration is disabled by default and can be enabled by setting the `org.springframework.cloud.bindings.boot.enable` System Property to `true`. +Each auto-configuration is triggered by the type of binding. Each auto-configuration can be disabled using a System Property specific to that type and defaults to enable. Auto-configuration is disabled by default and can be enabled by setting the `org.springframework.cloud.bindings.boot.enable` System Property to `true`. ### Cassandra -Kind: `cassandra` +Type: `cassandra` Disable Property: `org.springframework.cloud.bindings.boot.cassandra.enable` | Property | Value @@ -48,7 +48,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.cassandra.enable` | `spring.data.cassandra.username` | `{secret/username}` ### Couchbase -Kind: `couchbase` +Type: `couchbase` Disable Property: `org.springframework.cloud.bindings.boot.couchbase.enable` | Property | Value @@ -62,7 +62,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.couchbase.enable` | `spring.couchbase.username` | `{secret/username}` ### DB2 RDBMS -Kind: `DB2` +Type: `DB2` Disable Property: `org.springframework.cloud.bindings.boot.db2.enable` | Property | Value @@ -77,7 +77,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.db2.enable` ### Elasticsearch -Kind: `Elasticsearch` +Type: `Elasticsearch` Disable Property: `org.springframework.cloud.bindings.boot.elasticsearch.enable` | Property | Value @@ -95,7 +95,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.elasticsearch.enable` | `spring.elasticsearch.rest.username` | `{secret/username}` ### Kafka -Kind: `kafka` +Type: `kafka` Disable Property: `org.springframework.cloud.bindings.boot.kafka.enable` | Property | Value @@ -106,7 +106,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.kafka.enable` | `spring.kafka.streams.bootstrap-servers` | `{secret/streams.bootstrap-servers}` ### LDAP -Kind: `LDAP` +Type: `LDAP` Disable Property: `org.springframework.cloud.bindings.boot.ldap.enable` | Property | Value @@ -117,7 +117,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.ldap.enable` | `spring.ldap.username` | `{secret/username}` ### MongoDB -Kind: `MongoDB` +Type: `MongoDB` Disable Property: `org.springframework.cloud.bindings.boot.mongodb.enable` | Property | Value @@ -132,7 +132,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.mongodb.enable` | `spring.mongodb.username` | `{secret/username}` ### MySQL RDBMS -Kind: `MySQL` +Type: `MySQL` Disable Property: `org.springframework.cloud.bindings.boot.mysql.enable` | Property | Value @@ -146,7 +146,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.mysql.enable` | `spring.r2dbc.username` | `{secret/username}` ### Neo4J -Kind: `Neo4J` +Type: `Neo4J` Disable Property: `org.springframework.cloud.bindings.boot.neo4j.enable` | Property | Value @@ -156,7 +156,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.neo4j.enable` | `spring.data.neo4j.username` | `{secret/username}` ### Oracle RDBMS -Kind: `Oracle` +Type: `Oracle` Disable Property: `org.springframework.cloud.bindings.boot.oracle.enable` | Property | Value @@ -170,7 +170,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.oracle.enable` | `spring.r2dbc.username` | `{secret/username}` ### PostgreSQL RDBMS -Kind: `PostgreSQL` +Type: `PostgreSQL` Disable Property: `org.springframework.cloud.bindings.boot.postgresql.enable` | Property | Value @@ -184,7 +184,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.postgresql.enable` | `spring.r2dbc.username` | `{secret/username}` ### RabbitMQ RDBMS -Kind: `RabbitMQ` +Type: `RabbitMQ` Disable Property: `org.springframework.cloud.bindings.boot.rabbitmq.enable` | Property | Value @@ -197,7 +197,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.rabbitmq.enable` | `spring.rabbitmq.virtual-host` | `{secret/virtual-host}` ### Redis RDBMS -Kind: `Redis` +Type: `Redis` Disable Property: `org.springframework.cloud.bindings.boot.redis.enable` | Property | Value @@ -215,7 +215,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.redis.enable` | `spring.redis.url` | `{secret/url}` ## SCS Config Server -Kind: `Config` +Type: `Config` Disable Property: `org.springframework.cloud.bindings.boot.config.enable` | Property | Value @@ -226,7 +226,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.config.enable` | `spring.cloud.config.client.oauth2.accessTokenUri` | `{secret/access-token-uri}` ### SCS Eureka -Kind: `Eureka` +Type: `Eureka` Disable Property: `org.springframework.cloud.bindings.boot.eureka.enable` | Property | Value @@ -237,7 +237,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.eureka.enable` | `eureka.client.serviceUrl.defaultZone` | `{secret/uri}/eureka/` ## Spring Security OAuth2 -Kind: `OAuth2` +Type: `OAuth2` Disable Property: `org.springframework.cloud.bindings.boot.oauth2.enable` | Property | Value @@ -254,7 +254,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.oauth2.enable` | `spring.security.oauth2.client.provider.{metadata/provider}.user-name-attribute` | `{secret/user-name-attribute}` ### SQLServer RDBMS -Kind: `SQLServer` +Type: `SQLServer` Disable Property: `org.springframework.cloud.bindings.boot.sqlserver.enable` | Property | Value @@ -269,7 +269,7 @@ Disable Property: `org.springframework.cloud.bindings.boot.sqlserver.enable` ### Vault -Kind: `Vault` +Type: `Vault` Disable Property: `org.springframework.cloud.bindings.boot.vault.enable` Any Provider: @@ -354,7 +354,7 @@ If `{secret/authentication-method}` is equal to `token`: ### Wavefront -Kind: `Wavefront` +Type: `Wavefront` Disable Property: `org.springframework.cloud.bindings.boot.wavefront.enable` | Property | Value @@ -367,9 +367,9 @@ Disable Property: `org.springframework.cloud.bindings.boot.wavefront.enable` Consumers can extend the `BindingSpecificEnvironmentPostProcessor` with support for additional bindings by registering additional implementations of the `BindingsPropertiesProcessor`. -Within the `process` method, custom processors should make desired modifications to the application properties, using the contents of the bindings to compute property values as appropriate. Custom processors are strongly encouraged to use the `kind` of each binding to filter for bindings intended for that processor. +Within the `process` method, custom processors should make desired modifications to the application properties, using the contents of the bindings to compute property values as appropriate. Custom processors are strongly encouraged to use the `type` of each binding to filter for bindings intended for that processor. -Below is an example that processes a single binding of `kind` `myservice`. If such a binding exists this processor sets `my.service.enabled=true` and sets `my.service.uri` to the value of `uri` found in the binding secret. +Below is an example that processes a single binding of `type` `myservice`. If such a binding exists this processor sets `my.service.enabled=true` and sets `my.service.uri` to the value of `uri` found in the binding secret. ``` package com.example; @@ -385,14 +385,14 @@ import java.util.Map; public final class MyServiceBindingsPropertiesProcessor implements BindingsPropertiesProcessor { - public static final String KIND = "myservice"; + public static final String TYPE = "myservice"; @Override public void process(Environment environment, Bindings bindings, Map properties) { if (!environment.getProperty("com.example.bindings.myservice.enable", Boolean.class, true)) { return; } - List myBindings = bindings.filterBindings(KIND); + List myBindings = bindings.filterBindings(TYPE); if (myBindings.size() == 0) { return; } diff --git a/src/main/java/org/springframework/cloud/bindings/Binding.java b/src/main/java/org/springframework/cloud/bindings/Binding.java index 5cfe378..3351c07 100644 --- a/src/main/java/org/springframework/cloud/bindings/Binding.java +++ b/src/main/java/org/springframework/cloud/bindings/Binding.java @@ -15,52 +15,121 @@ */ package org.springframework.cloud.bindings; -import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** * A representation of a binding as defined by the - * Cloud Native Buildpacks Specification. + * Kubernetes Service Binding Specification. */ public final class Binding { + /** + * The key for the kind of a binding. + */ + public static final String KIND = "kind"; + + /** + * The key for the provider of a binding. + */ + public static final String PROVIDER = "provider"; + + /** + * The key for the type of a binding. + */ + public static final String TYPE = "type"; + private final String name; private final Path path; - private final Map metadata; + private final String provider; private final Map secret; + private final String type; + /** * Creates a new {@code Binding} instance using the specified file system root. */ public Binding(Path path) { - this.name = path.getFileName().toString(); - this.path = path; - this.metadata = createFilePerEntryMap(path.resolve("metadata")); - this.secret = createFilePerEntryMap(path.resolve("secret")); + this(path.getFileName().toString(), path, createSecretMap(path)); } /** * Creates a new {@code Binding} instance using the specified content. * - * @param name the name of the {@code Binding}. - * @param path the path to the {@code Binding}. - * @param metadata the metadata of the {@code Binding}. - * @param secret the secret of the {@code Binding}. + * @param name the name of the {@code Binding}. + * @param path the path to the {@code Binding}. + * @param secret the secret of the {@code Binding}. */ - public Binding(String name, Path path, Map metadata, Map secret) { + public Binding(String name, Path path, Map secret) { this.name = name; this.path = path; - this.metadata = metadata; - this.secret = secret; + this.secret = new HashMap<>(); + + String provider = null; + String type = null; + for (Map.Entry entry : secret.entrySet()) { + switch (entry.getKey()) { + case TYPE: + case KIND: // TODO: Remove as CNB_BINDINGS ages out + type = entry.getValue(); + break; + case PROVIDER: + provider = entry.getValue(); + break; + default: + this.secret.put(entry.getKey(), entry.getValue()); + } + } + + this.provider = provider; + this.type = type; + } + + private static Map createSecretMap(Path path) { + Map secret = createFilePerEntryMap(path); + + // TODO: Remove as CNB_BINDINGS ages out + Arrays.asList("metadata", "secret") + .forEach(d -> secret.putAll(createFilePerEntryMap(path.resolve(d)))); + + return secret; + } + + private static Map createFilePerEntryMap(Path path) { + if (!Files.exists(path)) { + return Collections.emptyMap(); + } + + try { + return Files.list(path) + .filter(p -> { + try { + return !Files.isHidden(p); + } catch (IOException e) { + throw new IllegalStateException(String.format("unable to determin id file '%s' is hidden", p), e); + } + }) + .filter(p -> !Files.isDirectory(p)) + .collect(Collectors.toMap( + p -> p.getFileName().toString(), + p -> { + try { + return new String(Files.readAllBytes(p), StandardCharsets.UTF_8).trim(); + } catch (IOException e) { + throw new IllegalStateException(String.format("unable to read file '%s'", p), e); + } + } + )); + } catch (IOException e) { + throw new IllegalStateException(String.format("unable to list children of '%s'", path), e); + } } /** @@ -77,41 +146,25 @@ public final class Binding { return path; } - /** - * Returns the metadata of the binding. - */ - public Map getMetadata() { - return metadata; - } - /** * Returns the secret of the binding. */ public Map getSecret() { - return secret; + return Collections.unmodifiableMap(secret); } /** - * Returns the kind of the binding. Equivalent to {@code getMetadata().get("kind")}. + * Returns the type of the binding. */ - public String getKind() { - return metadata.get("kind"); + public String getType() { + return type; } /** - * Returns the provider of the binding. Equivalent to {@code getMetadata().get("provider")}. + * Returns the provider of the binding. */ public String getProvider() { - return metadata.get("provider"); - } - - /** - * Returns the {@link Path} to a metadata file on disk. - * - * @param name the name of the metadata key. - */ - public Path getMetadataFilePath(String name) { - return this.path.resolve("metadata").resolve(name); + return provider; } /** @@ -120,7 +173,14 @@ public final class Binding { * @param name the name of the secret key. */ public Path getSecretFilePath(String name) { - return this.path.resolve("secret").resolve(name); + for (String d : Arrays.asList("metadata", "secret")) { + Path file = path.resolve(d).resolve(name); + if (Files.exists(file)) { + return file; + } + } + + return this.path.resolve(name); } @Override @@ -130,33 +190,25 @@ public final class Binding { Binding binding = (Binding) o; return name.equals(binding.name) && path.equals(binding.path) && - metadata.equals(binding.metadata) && - secret.equals(binding.secret); + Objects.equals(provider, binding.provider) && + secret.equals(binding.secret) && + Objects.equals(type, binding.type); } @Override public int hashCode() { - return Objects.hash(name, path, metadata, secret); + return Objects.hash(name, path, provider, secret, type); } - private Map createFilePerEntryMap(Path path) { - try { - return Files.list(path) - .filter(p -> !p.getFileName().toString().startsWith(".")) - .filter(p -> !new File(p.toString()).isDirectory()) - .collect(Collectors.toMap( - p -> p.getFileName().toString(), - p -> { - try { - return new String(Files.readAllBytes(p), StandardCharsets.UTF_8).trim(); - } catch (IOException e) { - throw new IllegalStateException(String.format("unable to read file '%s'", p), e); - } - } - )); - } catch (IOException e) { - throw new IllegalStateException(String.format("unable to list children of '%s'", path), e); - } + @Override + public String toString() { + return "Binding{" + + "name='" + name + '\'' + + ", path=" + path + + ", provider='" + provider + '\'' + + ", secret=" + new TreeSet<>(secret.keySet()) + + ", type='" + type + '\'' + + '}'; } } diff --git a/src/main/java/org/springframework/cloud/bindings/Bindings.java b/src/main/java/org/springframework/cloud/bindings/Bindings.java index 356028e..2e8a5dd 100644 --- a/src/main/java/org/springframework/cloud/bindings/Bindings.java +++ b/src/main/java/org/springframework/cloud/bindings/Bindings.java @@ -24,21 +24,28 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** * A representation of a collection of bindings as defined by the - * Cloud Native Buildpacks Specification. + * Kubernetes Service Binding Specification. */ public final class Bindings { /** - * The name of the environment variable to read to determine the bindings file system root. Specified by the Cloud - * Native Buildpacks Specification. + * The name of the environment variable to read to determine the bindings file system root. Specified by the + * Cloud Native Buildpacks Specification */ public static final String CNB_BINDINGS = "CNB_BINDINGS"; + /** + * The name of the environment variable to read to determine the bindings file system root. Specified by the + * Kubernetes Service Binding Specification. + */ + public static final String SERVICE_BINDING_ROOT = "SERVICE_BINDING_ROOT"; + private final List bindings; /** @@ -47,7 +54,7 @@ public final class Bindings { * returned. If the directory does not exist, an empty {@code Bindings} is returned. */ public Bindings() { - this(System.getenv(CNB_BINDINGS)); + this(getBindingRoot()); } /** @@ -91,6 +98,17 @@ public final class Bindings { this.bindings = Arrays.asList(bindings); } + private static String getBindingRoot() { + Map environment = System.getenv(); + + // TODO: Remove as CNB_BINDINGS ages out + if (environment.containsKey(CNB_BINDINGS)) { + return environment.get(CNB_BINDINGS); + } + + return System.getenv(SERVICE_BINDING_ROOT); + } + /** * Returns all the {@link Binding}s that were found during construction. */ @@ -113,27 +131,27 @@ public final class Bindings { } /** - * Returns zero or more {@link Binding}s with a given kind. Equivalent to {@link #filterBindings(String, String)}. + * Returns zero or more {@link Binding}s with a given type. Equivalent to {@link #filterBindings(String, String)}. * - * @param kind the kind of the {@code Binding} to find. - * @return the collection of {@code Binding}s with a given kind. + * @param type the type of the {@code Binding} to find. + * @return the collection of {@code Binding}s with a given type. */ - public List filterBindings(@Nullable String kind) { - return filterBindings(kind, null); + public List filterBindings(@Nullable String type) { + return filterBindings(type, null); } /** - * Return zero or more {@link Binding}s with a given kind and provider. If {@code kind} or {@code provider} are + * Return zero or more {@link Binding}s with a given type and provider. If {@code type} or {@code provider} are * {@code null}, the result is not filtered on that argument. * - * @param kind the kind of {@code Binding} to find. + * @param type the type of {@code Binding} to find. * @param provider the provider of {@code Binding} to find - * @return the collection of {@code Binding}s with a given kind and provider. + * @return the collection of {@code Binding}s with a given type and provider. */ - public List filterBindings(@Nullable String kind, @Nullable String provider) { + public List filterBindings(@Nullable String type, @Nullable String provider) { return bindings.stream() .filter(binding -> - (kind == null || binding.getKind().equalsIgnoreCase(kind)) && + (type == null || binding.getType().equalsIgnoreCase(type)) && (provider == null || binding.getProvider().equalsIgnoreCase(provider))) .collect(Collectors.toList()); } diff --git a/src/main/java/org/springframework/cloud/bindings/boot/BindingFlattenedEnvironmentPostProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/BindingFlattenedEnvironmentPostProcessor.java index c1d6267..16b23bb 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/BindingFlattenedEnvironmentPostProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/BindingFlattenedEnvironmentPostProcessor.java @@ -71,11 +71,8 @@ public final class BindingFlattenedEnvironmentPostProcessor implements Applicati public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { Map properties = new HashMap<>(); bindings.getBindings().forEach(binding -> { - binding.getMetadata().forEach((key, value) -> { - properties.put(String.format("cnb.bindings.%s.metadata.%s", binding.getName(), key), value); - }); binding.getSecret().forEach((key, value) -> { - properties.put(String.format("cnb.bindings.%s.secret.%s", binding.getName(), key), value); + properties.put(String.format("cnb.bindings.%s.%s", binding.getName(), key), value); }); }); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/CassandraBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/CassandraBindingsPropertiesProcessor.java index db4bc90..d4df638 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/CassandraBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/CassandraBindingsPropertiesProcessor.java @@ -22,25 +22,25 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ public final class CassandraBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Cassandra"; + public static final String TYPE = "Cassandra"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("cluster-name").to("spring.data.cassandra.cluster-name"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/ConfigServerBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/ConfigServerBindingsPropertiesProcessor.java index 924bfe2..e1ba91e 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/ConfigServerBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/ConfigServerBindingsPropertiesProcessor.java @@ -22,24 +22,24 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ final class ConfigServerBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Config"; + public static final String TYPE = "Config"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("uri").to("spring.cloud.config.uri"); map.from("client-id").to("spring.cloud.config.client.oauth2.clientId"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/CouchbaseBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/CouchbaseBindingsPropertiesProcessor.java index 7c7c03b..8122df1 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/CouchbaseBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/CouchbaseBindingsPropertiesProcessor.java @@ -22,25 +22,25 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ final class CouchbaseBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Couchbase"; + public static final String TYPE = "Couchbase"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("bootstrap-hosts").to("spring.couchbase.bootstrap-hosts"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/Db2BindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/Db2BindingsPropertiesProcessor.java index e0abe0e..589e0ab 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/Db2BindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/Db2BindingsPropertiesProcessor.java @@ -22,27 +22,27 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. * * @see JDBC URL Format */ public final class Db2BindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "DB2"; + public static final String TYPE = "DB2"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); //jdbc properties diff --git a/src/main/java/org/springframework/cloud/bindings/boot/ElasticsearchBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/ElasticsearchBindingsPropertiesProcessor.java index 5e402b0..9af1a1b 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/ElasticsearchBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/ElasticsearchBindingsPropertiesProcessor.java @@ -22,26 +22,26 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ final class ElasticsearchBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Elasticsearch"; + public static final String TYPE = "Elasticsearch"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("endpoints").to("spring.data.elasticsearch.client.reactive.endpoints"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/EurekaBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/EurekaBindingsPropertiesProcessor.java index f3cc229..1ddcd16 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/EurekaBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/EurekaBindingsPropertiesProcessor.java @@ -22,24 +22,24 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ final class EurekaBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Eureka"; + public static final String TYPE = "Eureka"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("client-id").to("eureka.client.oauth2.client-id"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/Guards.java b/src/main/java/org/springframework/cloud/bindings/boot/Guards.java index d36a8fd..95c2af1 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/Guards.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/Guards.java @@ -24,9 +24,9 @@ final class Guards { return environment.getProperty("org.springframework.cloud.bindings.boot.enable", Boolean.class, false); } - static boolean isKindEnabled(Environment environment, String kind) { + static boolean isTypeEnabled(Environment environment, String type) { return environment.getProperty( - String.format("org.springframework.cloud.bindings.boot.%s.enable", kind.toLowerCase()), + String.format("org.springframework.cloud.bindings.boot.%s.enable", type.toLowerCase()), Boolean.class, true); } diff --git a/src/main/java/org/springframework/cloud/bindings/boot/KafkaBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/KafkaBindingsPropertiesProcessor.java index 37519ee..7f2d434 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/KafkaBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/KafkaBindingsPropertiesProcessor.java @@ -22,24 +22,24 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ final class KafkaBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Kafka"; + public static final String TYPE = "Kafka"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("bootstrap-servers").to("spring.kafka.bootstrap-servers"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/LDAPBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/LDAPBindingsPropertiesProcessor.java index 1bdbde6..79a859b 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/LDAPBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/LDAPBindingsPropertiesProcessor.java @@ -22,24 +22,24 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ public final class LDAPBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "LDAP"; + public static final String TYPE = "LDAP"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("base").to("spring.ldap.base"); map.from("password").to("spring.ldap.password"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/MongoDbBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/MongoDbBindingsPropertiesProcessor.java index 6b51030..53c6e78 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/MongoDbBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/MongoDbBindingsPropertiesProcessor.java @@ -22,25 +22,25 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ public final class MongoDbBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "MongoDB"; + public static final String TYPE = "MongoDB"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("authentication-database").to("spring.mongodb.authentication-database"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/MySqlBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/MySqlBindingsPropertiesProcessor.java index dbf3f1e..593213e 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/MySqlBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/MySqlBindingsPropertiesProcessor.java @@ -22,27 +22,27 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. * * @see JDBC URL Format */ public final class MySqlBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "MySQL"; + public static final String TYPE = "MySQL"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); //jdbc properties diff --git a/src/main/java/org/springframework/cloud/bindings/boot/Neo4JBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/Neo4JBindingsPropertiesProcessor.java index 72b8750..0393b2d 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/Neo4JBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/Neo4JBindingsPropertiesProcessor.java @@ -22,24 +22,24 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ final class Neo4JBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Neo4J"; + public static final String TYPE = "Neo4J"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("password").to("spring.data.neo4j.password"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/OracleBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/OracleBindingsPropertiesProcessor.java index e4544eb..97c490f 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/OracleBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/OracleBindingsPropertiesProcessor.java @@ -22,27 +22,27 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. * * @see JDBC URL Format */ public final class OracleBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Oracle"; + public static final String TYPE = "Oracle"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); //jdbc properties diff --git a/src/main/java/org/springframework/cloud/bindings/boot/PostgreSqlBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/PostgreSqlBindingsPropertiesProcessor.java index 4fb26e5..ab6b896 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/PostgreSqlBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/PostgreSqlBindingsPropertiesProcessor.java @@ -22,27 +22,27 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. * * @see JDBC URL Format */ public final class PostgreSqlBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "PostgreSQL"; + public static final String TYPE = "PostgreSQL"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); //jdbc properties diff --git a/src/main/java/org/springframework/cloud/bindings/boot/RabbitMqBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/RabbitMqBindingsPropertiesProcessor.java index b49ff3e..70d956b 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/RabbitMqBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/RabbitMqBindingsPropertiesProcessor.java @@ -22,25 +22,25 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ final class RabbitMqBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "RabbitMQ"; + public static final String TYPE = "RabbitMQ"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("addresses").to("spring.rabbitmq.addresses"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessor.java index 7a30317..0569adc 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessor.java @@ -22,25 +22,25 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ public final class RedisBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Redis"; + public static final String TYPE = "Redis"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("client-name").to("spring.redis.client-name"); diff --git a/src/main/java/org/springframework/cloud/bindings/boot/SpringSecurityOAuth2BindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/SpringSecurityOAuth2BindingsPropertiesProcessor.java index bc28f59..0b2371e 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/SpringSecurityOAuth2BindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/SpringSecurityOAuth2BindingsPropertiesProcessor.java @@ -25,27 +25,27 @@ import org.springframework.core.env.Environment; import java.util.*; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ public final class SpringSecurityOAuth2BindingsPropertiesProcessor implements BindingsPropertiesProcessor, ApplicationListener { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "OAuth2"; + public static final String TYPE = "OAuth2"; private static final DeferredLog LOG = new DeferredLog(); @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); String provider = binding.getProvider(); if (provider == null) { diff --git a/src/main/java/org/springframework/cloud/bindings/boot/SqlServerBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/SqlServerBindingsPropertiesProcessor.java index 553eb71..9b13627 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/SqlServerBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/SqlServerBindingsPropertiesProcessor.java @@ -22,27 +22,27 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. * * @see JDBC URL Format */ public final class SqlServerBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "SQLServer"; + public static final String TYPE = "SQLServer"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); //jdbc properties diff --git a/src/main/java/org/springframework/cloud/bindings/boot/VaultBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/VaultBindingsPropertiesProcessor.java index 88b99b3..92e032d 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/VaultBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/VaultBindingsPropertiesProcessor.java @@ -25,27 +25,27 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ public final class VaultBindingsPropertiesProcessor implements BindingsPropertiesProcessor, ApplicationListener { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Vault"; + public static final String TYPE = "Vault"; private static final DeferredLog LOG = new DeferredLog(); @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + 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 diff --git a/src/main/java/org/springframework/cloud/bindings/boot/WavefrontBindingsPropertiesProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/WavefrontBindingsPropertiesProcessor.java index 9d1e1c7..23f16d8 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/WavefrontBindingsPropertiesProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/WavefrontBindingsPropertiesProcessor.java @@ -22,25 +22,25 @@ import org.springframework.core.env.Environment; import java.util.Map; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; /** - * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}. + * An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of type: {@value TYPE}. */ public final class WavefrontBindingsPropertiesProcessor implements BindingsPropertiesProcessor { /** - * The {@link Binding} kind that this processor is interested in: {@value}. + * The {@link Binding} type that this processor is interested in: {@value}. **/ - public static final String KIND = "Wavefront"; + public static final String TYPE = "Wavefront"; @Override public void process(Environment environment, Bindings bindings, Map properties) { - if (!isKindEnabled(environment, KIND)) { + if (!isTypeEnabled(environment, TYPE)) { return; } - bindings.filterBindings(KIND).forEach(binding -> { + bindings.filterBindings(TYPE).forEach(binding -> { MapMapper map = new MapMapper(binding.getSecret(), properties); map.from("api-token").to("management.metrics.export.wavefront.api-token"); map.from("uri").to("management.metrics.export.wavefront.uri"); diff --git a/src/test/java/org/springframework/cloud/bindings/BindingTest.java b/src/test/java/org/springframework/cloud/bindings/BindingTest.java index 228c67c..77a03cf 100644 --- a/src/test/java/org/springframework/cloud/bindings/BindingTest.java +++ b/src/test/java/org/springframework/cloud/bindings/BindingTest.java @@ -17,8 +17,10 @@ package org.springframework.cloud.bindings; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import java.nio.file.Path; import java.nio.file.Paths; import static org.assertj.core.api.Assertions.assertThat; @@ -26,30 +28,70 @@ import static org.assertj.core.api.Assertions.assertThat; @DisplayName("Binding") final class BindingTest { - @Test - @DisplayName("populates content from filesystem") - void test() { - Binding binding = new Binding(Paths.get("src/test/resources/test-name-1")); + @Nested + @DisplayName("CNB Bindings") + final class CNBBindings { + + private final Path root = Paths.get("src/test/resources/cnb"); + + @Test + @DisplayName("populates content from filesystem") + void test() { + Binding binding = new Binding(root.resolve("test-name-1")); + + assertThat(binding.getType()).isEqualTo("test-kind-1"); + assertThat(binding.getProvider()).isEqualTo("test-provider-1"); + assertThat(binding.getSecretFilePath("test-metadata-key")) + .isEqualTo(root.resolve("test-name-1/metadata/test-metadata-key")); + assertThat(binding.getSecretFilePath("test-secret-key")) + .isEqualTo(root.resolve("test-name-1/secret/test-secret-key")); + } + + @Test + @DisplayName("populates k8s style content from filesystem") + void testK8s() { + //When bindings are provided as a k8s configmap secret pairs data files will be symlinks to hidden directories + Binding binding = new Binding(root.resolve("test-k8s")); + + assertThat(binding.getType()).isEqualTo("test-kind-1"); + assertThat(binding.getProvider()).isEqualTo("test-provider-1"); + assertThat(binding.getSecretFilePath("test-metadata-key")) + .isEqualTo(root.resolve("test-k8s/metadata/test-metadata-key")); + assertThat(binding.getSecretFilePath("test-secret-key")) + .isEqualTo(root.resolve("test-k8s/secret/test-secret-key")); + } - assertThat(binding.getKind()).isEqualTo("test-kind-1"); - assertThat(binding.getProvider()).isEqualTo("test-provider-1"); - assertThat(binding.getMetadataFilePath("test-key")) - .isEqualTo(Paths.get("src/test/resources/test-name-1/metadata/test-key")); - assertThat(binding.getSecretFilePath("test-key")) - .isEqualTo(Paths.get("src/test/resources/test-name-1/secret/test-key")); } - @Test - @DisplayName("populates k8s style content from filesystem") - void testK8s() { - //When bindings are provided as a k8s configmap secret pairs data files will be symlinks to hidden directories - Binding binding = new Binding(Paths.get("src/test/resources/test-k8s")); + @Nested + @DisplayName("Kubernetes Bindings") + final class KubernetesBindings { + + private final Path root = Paths.get("src/test/resources/k8s"); + + @Test + @DisplayName("populates content from filesystem") + void test() { + Binding binding = new Binding(root.resolve("test-name-1")); + + assertThat(binding.getType()).isEqualTo("test-type-1"); + assertThat(binding.getProvider()).isEqualTo("test-provider-1"); + assertThat(binding.getSecretFilePath("test-secret-key")) + .isEqualTo(root.resolve("test-name-1/test-secret-key")); + } + + @Test + @DisplayName("populates k8s style content from filesystem") + void testK8s() { + //When bindings are provided as a k8s configmap secret pairs data files will be symlinks to hidden directories + Binding binding = new Binding(root.resolve("test-k8s")); + + assertThat(binding.getType()).isEqualTo("test-type-1"); + assertThat(binding.getProvider()).isEqualTo("test-provider-1"); + assertThat(binding.getSecretFilePath("test-secret-key")) + .isEqualTo(root.resolve("test-k8s/test-secret-key")); + } - assertThat(binding.getKind()).isEqualTo("test-kind-1"); - assertThat(binding.getProvider()).isEqualTo("test-provider-1"); - assertThat(binding.getMetadataFilePath("test-key")) - .isEqualTo(Paths.get("src/test/resources/test-k8s/metadata/test-key")); - assertThat(binding.getSecretFilePath("test-key")) - .isEqualTo(Paths.get("src/test/resources/test-k8s/secret/test-key")); } + } diff --git a/src/test/java/org/springframework/cloud/bindings/BindingsTest.java b/src/test/java/org/springframework/cloud/bindings/BindingsTest.java new file mode 100644 index 0000000..60d5dc2 --- /dev/null +++ b/src/test/java/org/springframework/cloud/bindings/BindingsTest.java @@ -0,0 +1,199 @@ +/* + * 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; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; + +@DisplayName("Bindings") +final class BindingsTest { + + @Nested + @DisplayName("CNB Bindings") + final class CNBBindings { + + private final Path root = Paths.get("src/test/resources/cnb"); + + @Nested + @DisplayName("when constructed") + final class Constructor { + + @Test + @DisplayName("empty if path is null") + void nullPath() { + Bindings b = new Bindings((String) null); + + assertThat(b.getBindings()).isEmpty(); + } + + @Test + @DisplayName("empty if path does not exist") + void nonExistentDirectory() { + Bindings b = new Bindings(root.resolve("non-existent").toString()); + + assertThat(b.getBindings()).isEmpty(); + } + + @Test + @DisplayName("throws exception if path is not a directory") + void nonDirectory() throws IOException { + Path path = File.createTempFile("bindings", "").toPath(); + + assertThatIllegalArgumentException().isThrownBy(() -> new Bindings(path.toString())); + } + + @Test + @DisplayName("populates content") + void construct() { + Bindings b = new Bindings(root.toString()); + + assertThat(b.getBindings()).hasSize(3); + } + + } + + @Nested + @DisplayName("with content") + final class Content { + + private final Bindings bindings = new Bindings( + new Binding("test-name-1", root.resolve("test-name-1"), + new FluentMap() + .withEntry("kind", "test-kind-1") + .withEntry("provider", "test-provider-1") + ), + new Binding("test-name-2", root.resolve("test-name-2"), + new FluentMap() + .withEntry("kind", "test-kind-2") + .withEntry("provider", "test-provider-2") + ) + ); + + @Test + @DisplayName("returns content") + void getBindings() { + assertThat(bindings.getBindings()).hasSize(2); + } + + @Test + @DisplayName("filters bindings by kind") + void filterBindingsByKind() { + assertThat(bindings.filterBindings("test-kind-1", null)).hasSize(1); + } + + @Test + @DisplayName("filters bindings by provider") + void filterBindingsByProvider() { + assertThat(bindings.filterBindings(null, "test-provider-1")).hasSize(1); + } + + } + + } + + @Nested + @DisplayName("Kubernetes Bindings") + final class KubernetesBindings { + + private final Path root = Paths.get("src/test/resources/k8s"); + + @Nested + @DisplayName("when constructed") + final class Constructor { + + @Test + @DisplayName("empty if path is null") + void nullPath() { + Bindings b = new Bindings((String) null); + + assertThat(b.getBindings()).isEmpty(); + } + + @Test + @DisplayName("empty if path does not exist") + void nonExistentDirectory() { + Bindings b = new Bindings(root.resolve("non-existent").toString()); + + assertThat(b.getBindings()).isEmpty(); + } + + @Test + @DisplayName("throws exception if path is not a directory") + void nonDirectory() throws IOException { + Path path = File.createTempFile("bindings", "").toPath(); + + assertThatIllegalArgumentException().isThrownBy(() -> new Bindings(path.toString())); + } + + @Test + @DisplayName("populates content") + void construct() { + Bindings b = new Bindings(root.toString()); + + assertThat(b.getBindings()).hasSize(3); + } + + } + + @Nested + @DisplayName("with content") + final class Content { + + private final Bindings bindings = new Bindings( + new Binding("test-name-1", root.resolve("test-name-1"), + new FluentMap() + .withEntry("type", "test-type-1") + .withEntry("provider", "test-provider-1") + ), + new Binding("test-name-2", root.resolve("test-name-2"), + new FluentMap() + .withEntry("type", "test-type-2") + .withEntry("provider", "test-provider-2") + ) + ); + + @Test + @DisplayName("returns content") + void getBindings() { + assertThat(bindings.getBindings()).hasSize(2); + } + + @Test + @DisplayName("filters bindings by kind") + void filterBindingsByKind() { + assertThat(bindings.filterBindings("test-type-1", null)).hasSize(1); + } + + @Test + @DisplayName("filters bindings by provider") + void filterBindingsByProvider() { + assertThat(bindings.filterBindings(null, "test-provider-1")).hasSize(1); + } + + } + + } + +} diff --git a/src/test/java/org/springframework/cloud/bindings/BindingsTests.java b/src/test/java/org/springframework/cloud/bindings/BindingsTests.java deleted file mode 100644 index 67b943c..0000000 --- a/src/test/java/org/springframework/cloud/bindings/BindingsTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Paths; -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; - -@DisplayName("Bindings") -final class BindingsTests { - - @Nested - @DisplayName("when constructed") - final class Constructor { - - @Test - @DisplayName("empty if path is null") - void nullPath() { - Bindings b = new Bindings((String) null); - - assertThat(b.getBindings()).isEmpty(); - } - - @Test - @DisplayName("empty if path does not exist") - void nonExistentDirectory() { - String path = "src/test/resources/non-existent"; - Bindings b = new Bindings(path); - - assertThat(b.getBindings()).isEmpty(); - } - - @Test - @DisplayName("throws exception if path is not a directory") - void nonDirectory() throws IOException { - String path = File.createTempFile("bindings", "").getPath(); - - assertThatIllegalArgumentException().isThrownBy(() -> new Bindings(path)); - } - - @Test - @DisplayName("populates content") - void construct() { - String path = "src/test/resources"; - Bindings b = new Bindings(path); - - assertThat(b.getBindings()).hasSize(3); - } - - } - - @Nested - @DisplayName("with content") - final class Content { - - private final Bindings bindings = new Bindings( - new Binding("test-name-1", Paths.get("src/test/resources/test-name-1"), - new FluentMap().withEntry("kind", "test-kind-1").withEntry("provider", "test-provider-1"), - Collections.emptyMap()), - new Binding("test-name-2", Paths.get("src/test/resources/test-name-2"), - new FluentMap().withEntry("kind", "test-kind-2").withEntry("provider", "test-provider-2"), - Collections.emptyMap()) - ); - - @Test - @DisplayName("returns content") - void getBindings() { - assertThat(bindings.getBindings()).hasSize(2); - } - - @Test - @DisplayName("filters bindings by kind") - void filterBindingsByKind() { - assertThat(bindings.filterBindings("test-kind-1", null)).hasSize(1); - } - - @Test - @DisplayName("filters bindings by provider") - void filterBindingsByProvider() { - assertThat(bindings.filterBindings(null, "test-provider-1")).hasSize(1); - } - - } -} diff --git a/src/test/java/org/springframework/cloud/bindings/boot/BindingFlattenedEnvironmentPostProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/BindingFlattenedEnvironmentPostProcessorTest.java index 50f4bf3..a08c3c1 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/BindingFlattenedEnvironmentPostProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/BindingFlattenedEnvironmentPostProcessorTest.java @@ -43,7 +43,8 @@ final class BindingFlattenedEnvironmentPostProcessorTest { new BindingFlattenedEnvironmentPostProcessor( new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.emptyMap(), Collections.emptyMap()) + Collections.emptyMap() + ) ) ).postProcessEnvironment(new MockEnvironment(), application); @@ -65,14 +66,13 @@ final class BindingFlattenedEnvironmentPostProcessorTest { new BindingFlattenedEnvironmentPostProcessor( new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("test-metadata-key", "test-metadata-value"), - Collections.singletonMap("test-secret-key", "test-secret-value")) + Collections.singletonMap("test-secret-key", "test-secret-value") + ) ) ).postProcessEnvironment(environment, application); assertThat(environment.getPropertySources()).hasSize(2); - assertThat(environment.getProperty("cnb.bindings.test-name.metadata.test-metadata-key")).isEqualTo("test-metadata-value"); - assertThat(environment.getProperty("cnb.bindings.test-name.secret.test-secret-key")).isEqualTo("test-secret-value"); + assertThat(environment.getProperty("cnb.bindings.test-name.test-secret-key")).isEqualTo("test-secret-value"); } @Test diff --git a/src/test/java/org/springframework/cloud/bindings/boot/BindingSpecificEnvironmentPostProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/BindingSpecificEnvironmentPostProcessorTest.java index cc04d7b..4c54bee 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/BindingSpecificEnvironmentPostProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/BindingSpecificEnvironmentPostProcessorTest.java @@ -43,7 +43,8 @@ final class BindingSpecificEnvironmentPostProcessorTest { new BindingSpecificEnvironmentPostProcessor( new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.emptyMap(), Collections.emptyMap()) + Collections.emptyMap() + ) ), (environment, bindings, properties) -> properties.put("test-key", "test-value") ).postProcessEnvironment(new MockEnvironment(), application); @@ -66,7 +67,8 @@ final class BindingSpecificEnvironmentPostProcessorTest { new BindingSpecificEnvironmentPostProcessor( new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.emptyMap(), Collections.emptyMap()) + Collections.emptyMap() + ) ) ).postProcessEnvironment(environment, application); @@ -79,7 +81,8 @@ final class BindingSpecificEnvironmentPostProcessorTest { new BindingSpecificEnvironmentPostProcessor( new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.emptyMap(), Collections.emptyMap()) + Collections.emptyMap() + ) ), (environment, bindings, properties) -> properties.put("test-key", "test-value") ).postProcessEnvironment(environment, application); diff --git a/src/test/java/org/springframework/cloud/bindings/boot/CassandraBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/CassandraBindingsPropertiesProcessorTest.java index 6056039..e6624df 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/CassandraBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/CassandraBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.CassandraBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.CassandraBindingsPropertiesProcessor.TYPE; @DisplayName("Cassandra BindingsPropertiesProcessor") final class CassandraBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("cluster-name", "test-cluster-name") .withEntry("compression", "test-compression") .withEntry("contact-points", "test-contact-points") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/ConfigServerBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/ConfigServerBindingsPropertiesProcessorTest.java index 75f7be5..96b6c81 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/ConfigServerBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/ConfigServerBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.ConfigServerBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.ConfigServerBindingsPropertiesProcessor.TYPE; @DisplayName("Config Server BindingsPropertiesProcessor") final class ConfigServerBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("uri", "test-uri") .withEntry("client-id", "test-client-id") .withEntry("client-secret", "test-client-secret") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/CouchbaseBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/CouchbaseBindingsPropertiesProcessorTest.java index c7ac600..4e55d9b 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/CouchbaseBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/CouchbaseBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.CouchbaseBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.CouchbaseBindingsPropertiesProcessor.TYPE; @DisplayName("Couchbase BindingsPropertiesProcessor") final class CouchbaseBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("bootstrap-hosts", "test-bootstrap-hosts") .withEntry("bucket.name", "test-bucket-name") .withEntry("bucket.password", "test-bucket-password") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/Db2BindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/Db2BindingsPropertiesProcessorTest.java index 3bfa8df..43d0314 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/Db2BindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/Db2BindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.Db2BindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.Db2BindingsPropertiesProcessor.TYPE; @DisplayName("DB2 BindingsPropertiesProcessor") final class Db2BindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("database", "test-database") .withEntry("host", "test-host") .withEntry("password", "test-password") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/ElasticsearchBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/ElasticsearchBindingsPropertiesProcessorTest.java index 57b0c2b..f7ae1cc 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/ElasticsearchBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/ElasticsearchBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.ElasticsearchBindingsPropertiesProcessor.TYPE; @DisplayName("Elasticsearch BindingsPropertiesProcessor") final class ElasticsearchBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("endpoints", "test-endpoints") .withEntry("password", "test-password") .withEntry("use-ssl", "test-use-ssl") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/EurekaBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/EurekaBindingsPropertiesProcessorTest.java index dc784f1..a56663f 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/EurekaBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/EurekaBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.EurekaBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.EurekaBindingsPropertiesProcessor.TYPE; @DisplayName("Eureka BindingsPropertiesProcessor") final class EurekaBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("uri", "test-uri") .withEntry("client-id", "test-client-id") .withEntry("client-secret", "test-client-secret") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/GuardsTest.java b/src/test/java/org/springframework/cloud/bindings/boot/GuardsTest.java index b8df380..f246481 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/GuardsTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/GuardsTest.java @@ -23,7 +23,7 @@ import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.cloud.bindings.boot.Guards.isGlobalEnabled; -import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled; +import static org.springframework.cloud.bindings.boot.Guards.isTypeEnabled; @DisplayName("Guards") final class GuardsTest { @@ -57,29 +57,29 @@ final class GuardsTest { } @Nested - @DisplayName("Kind Guard") - final class KindGuard { + @DisplayName("Type Guard") + final class TypeGuard { private final MockEnvironment environment = new MockEnvironment(); @Test @DisplayName("returns true if unset") void unset() { - assertThat(isKindEnabled(environment, "Test")).isTrue(); + assertThat(isTypeEnabled(environment, "Test")).isTrue(); } @Test @DisplayName("returns the set value of true") void setTrue() { environment.setProperty("org.springframework.cloud.bindings.boot.test.enable", "true"); - assertThat(isKindEnabled(environment, "Test")).isTrue(); + assertThat(isTypeEnabled(environment, "Test")).isTrue(); } @Test @DisplayName("returns the set value of false") void setFalse() { environment.setProperty("org.springframework.cloud.bindings.boot.test.enable", "false"); - assertThat(isKindEnabled(environment, "Test")).isFalse(); + assertThat(isTypeEnabled(environment, "Test")).isFalse(); } } diff --git a/src/test/java/org/springframework/cloud/bindings/boot/KafkaBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/KafkaBindingsPropertiesProcessorTest.java index 6d62cd0..fd55178 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/KafkaBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/KafkaBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.KafkaBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.KafkaBindingsPropertiesProcessor.TYPE; @DisplayName("Kafka BindingsPropertiesProcessor") final class KafkaBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("bootstrap-servers", "test-bootstrap-servers") .withEntry("consumer.bootstrap-servers", "test-consumer-bootstrap-servers") .withEntry("producer.bootstrap-servers", "test-producer-bootstrap-servers") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/LDAPBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/LDAPBindingsPropertiesProcessorTest.java index 28872f0..c4afe7e 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/LDAPBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/LDAPBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.LDAPBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.LDAPBindingsPropertiesProcessor.TYPE; @DisplayName("LDAP BindingsPropertiesProcessor") final class LDAPBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("urls", "test-urls") .withEntry("password", "test-password") .withEntry("username", "test-username") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/MongoDbBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/MongoDbBindingsPropertiesProcessorTest.java index 2351b5f..b744adb 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/MongoDbBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/MongoDbBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.MongoDbBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.MongoDbBindingsPropertiesProcessor.TYPE; @DisplayName("MongoDB BindingsPropertiesProcessor") final class MongoDbBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("authentication-database", "test-authentication-database") .withEntry("database", "test-database") .withEntry("grid-fs-database", "test-grid-fs-database") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/MySqlBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/MySqlBindingsPropertiesProcessorTest.java index 3eadb69..2fd05d1 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/MySqlBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/MySqlBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.MySqlBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.MySqlBindingsPropertiesProcessor.TYPE; @DisplayName("MySQL BindingsPropertiesProcessor") final class MySqlBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("database", "test-database") .withEntry("host", "test-host") .withEntry("password", "test-password") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/Neo4JBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/Neo4JBindingsPropertiesProcessorTest.java index e1cc542..85d351b 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/Neo4JBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/Neo4JBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.Neo4JBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.Neo4JBindingsPropertiesProcessor.TYPE; @DisplayName("Neo4J BindingsPropertiesProcessor") final class Neo4JBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("password", "test-password") .withEntry("uri", "test-uri") .withEntry("username", "test-username") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/OracleBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/OracleBindingsPropertiesProcessorTest.java index adb3829..7640e66 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/OracleBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/OracleBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.OracleBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.OracleBindingsPropertiesProcessor.TYPE; @DisplayName("Oracle BindingsPropertiesProcessor") final class OracleBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("database", "test-database") .withEntry("host", "test-host") .withEntry("password", "test-password") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/PostgreSqlBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/PostgreSqlBindingsPropertiesProcessorTest.java index 87f7ae6..76bf5de 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/PostgreSqlBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/PostgreSqlBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.PostgreSqlBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.PostgreSqlBindingsPropertiesProcessor.TYPE; @DisplayName("PostgreSQL BindingsPropertiesProcessor") final class PostgreSqlBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("database", "test-database") .withEntry("host", "test-host") .withEntry("password", "test-password") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/RabbitMqBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/RabbitMqBindingsPropertiesProcessorTest.java index 0dc180e..6fb1398 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/RabbitMqBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/RabbitMqBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.RabbitMqBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.RabbitMqBindingsPropertiesProcessor.TYPE; @DisplayName("RabbitMQ BindingsPropertiesProcessor") final class RabbitMqBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("addresses", "test-addresses") .withEntry("host", "test-host") .withEntry("password", "test-password") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessorTest.java index db0258d..83de7fa 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/RedisBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.RedisBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.RedisBindingsPropertiesProcessor.TYPE; @DisplayName("Redis BindingsPropertiesProcessor") final class RedisBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("client-name", "test-client-name") .withEntry("cluster.max-redirects", "test-cluster-max-redirects") .withEntry("cluster.nodes", "test-cluster-nodes") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/SpringSecurityOAuth2BindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/SpringSecurityOAuth2BindingsPropertiesProcessorTest.java index 2a2589d..8ec31bc 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/SpringSecurityOAuth2BindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/SpringSecurityOAuth2BindingsPropertiesProcessorTest.java @@ -27,7 +27,7 @@ import java.nio.file.Paths; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.SpringSecurityOAuth2BindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.SpringSecurityOAuth2BindingsPropertiesProcessor.TYPE; @DisplayName("Spring Security OAuth2 BindingsPropertiesProcessor") final class SpringSecurityOAuth2BindingsPropertiesProcessorTest { @@ -35,26 +35,23 @@ final class SpringSecurityOAuth2BindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name-1", Paths.get("test-path"), new FluentMap() - .withEntry("kind", KIND) - .withEntry("provider", "github"), - new FluentMap() + .withEntry(Binding.TYPE, TYPE) + .withEntry("provider", "github") .withEntry("client-id", "github-client-id") .withEntry("client-secret", "github-client-secret") ), new Binding("test-name-2", Paths.get("test-path"), new FluentMap() - .withEntry("kind", KIND) - .withEntry("provider", "okta"), - new FluentMap() + .withEntry(Binding.TYPE, TYPE) + .withEntry("provider", "okta") .withEntry("client-id", "okta-client-id") .withEntry("client-secret", "okta-client-secret") .withEntry("issuer-uri", "okta-issuer-uri") ), new Binding("test-name-3", Paths.get("test-path"), new FluentMap() - .withEntry("kind", KIND) - .withEntry("provider", "my-provider"), - new FluentMap() + .withEntry(Binding.TYPE, TYPE) + .withEntry("provider", "my-provider") .withEntry("client-id", "my-provider-client-id") .withEntry("client-secret", "my-provider-client-secret") .withEntry("authorization-uri", "my-provider-authorization-uri") @@ -67,8 +64,7 @@ final class SpringSecurityOAuth2BindingsPropertiesProcessorTest { // Don't crash when provider is missing new Binding("test-missing-provider", Paths.get("test-path"), new FluentMap() - .withEntry("kind", KIND), - new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("client-id", "my-provider-client-id") ) ); diff --git a/src/test/java/org/springframework/cloud/bindings/boot/SqlServerBindingsPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/SqlServerBindingsPropertiesProcessorTest.java index 73ca1ee..b1b1536 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/SqlServerBindingsPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/SqlServerBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.SqlServerBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.SqlServerBindingsPropertiesProcessor.TYPE; @DisplayName("SQLServer BindingsPropertiesProcessor") final class SqlServerBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("database", "test-database") .withEntry("host", "test-host") .withEntry("password", "test-password") diff --git a/src/test/java/org/springframework/cloud/bindings/boot/VaultPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/VaultBindingsPropertiesProcessorTest.java similarity index 56% rename from src/test/java/org/springframework/cloud/bindings/boot/VaultPropertiesProcessorTest.java rename to src/test/java/org/springframework/cloud/bindings/boot/VaultBindingsPropertiesProcessorTest.java index f5c9de3..59a435d 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/VaultPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/VaultBindingsPropertiesProcessorTest.java @@ -27,122 +27,10 @@ import java.nio.file.Paths; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.VaultBindingsPropertiesProcessor.TYPE; @DisplayName("Vault BindingsPropertiesProcessor") -final class VaultPropertiesProcessorTest { - - private FluentMap baseSecret() { - return new FluentMap() - .withEntry("namespace", "test-namespace") - .withEntry("uri", "test-uri"); - } - - private FluentMap metadata() { - return new FluentMap() - .withEntry("kind", KIND); - } - - private final Binding tokenBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "token") - .withEntry("token", "test-token") - ); - - private final Binding appRoleBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("app-role-path", "test-app-role-path") - .withEntry("authentication-method", "approle") - .withEntry("role", "test-role") - .withEntry("role-id", "test-role-id") - .withEntry("secret-id", "test-secret-id") - ); - - private final Binding cubbyholeBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "cubbyhole") - .withEntry("token", "test-token") - ); - - private final Binding certBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "cert") - .withEntry("cert-auth-path", "test-cert-auth-path") - .withEntry("key-store-password", "test-key-store-password") - .withEntry("keystore.jks", "key store contents!") - ); - - private final Binding awsEc2Binding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "aws_ec2") - .withEntry("aws-ec2-instance-identity-document", "test-identity-document") - .withEntry("nonce", "test-nonce") - .withEntry("aws-ec2-path", "test-aws-ec2-path") - .withEntry("role", "test-role") - ); - - private final Binding awsIamBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "aws_iam") - .withEntry("aws-iam-server-id", "test-server-id") - .withEntry("aws-path", "test-aws-path") - .withEntry("aws-sts-endpoint-uri", "test-endpoint-uri") - .withEntry("role", "test-role") - ); - - private final Binding azureMsiBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "azure_msi") - .withEntry("azure-path", "test-azure-path") - .withEntry("role", "test-role") - ); - - private final Binding gcpGceBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "gcp_gce") - .withEntry("gcp-path", "test-gcp-path") - .withEntry("gcp-service-account", "test-service-account") - .withEntry("role", "test-role") - ); - - private final Binding gcpIamBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "gcp_iam") - .withEntry("credentials.json", "credentials JSON contents!") - .withEntry("encoded-key", "test-encoded-key") - .withEntry("gcp-path", "test-gcp-path") - .withEntry("gcp-project-id", "test-project-id") - .withEntry("gcp-service-account", "test-service-account") - .withEntry("jwt-validity", "test-jwt-validity") - .withEntry("role", "test-role") - ); - - private final Binding k8sBinding = new Binding( - "test-name", Paths.get("test-path"), - metadata(), - baseSecret() - .withEntry("authentication-method", "kubernetes") - .withEntry("role", "test-role") - .withEntry("kubernetes-path", "test-kubernetes-path") - ); +final class VaultBindingsPropertiesProcessorTest { private final MockEnvironment environment = new MockEnvironment(); @@ -151,7 +39,15 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports token authentication") void testTokenAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(tokenBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "token") + .withEntry("token", "test-token") + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") @@ -162,7 +58,18 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports AppRole authentication") void testAppRoleAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(appRoleBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("app-role-path", "test-app-role-path") + .withEntry("authentication-method", "approle") + .withEntry("role", "test-role") + .withEntry("role-id", "test-role-id") + .withEntry("secret-id", "test-secret-id") + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") @@ -176,7 +83,15 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports cubbyhole authentication") void testCubbyholeAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(cubbyholeBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "cubbyhole") + .withEntry("token", "test-token") + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") @@ -187,12 +102,22 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports TLS certificate authentication") void testCertAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(certBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "cert") + .withEntry("cert-auth-path", "test-cert-auth-path") + .withEntry("key-store-password", "test-key-store-password") + .withEntry("keystore.jks", "key store contents!") + ) + ); + + new VaultBindingsPropertiesProcessor().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/secret/keystore.jks") + .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"); } @@ -200,7 +125,18 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports AWS EC2 authentication") void testAwsEc2Authentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(awsEc2Binding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "aws_ec2") + .withEntry("aws-ec2-instance-identity-document", "test-identity-document") + .withEntry("nonce", "test-nonce") + .withEntry("aws-ec2-path", "test-aws-ec2-path") + .withEntry("role", "test-role") + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") @@ -214,7 +150,18 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports AWS IAM authentication") void testAwsIamAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(awsIamBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "aws_iam") + .withEntry("aws-iam-server-id", "test-server-id") + .withEntry("aws-path", "test-aws-path") + .withEntry("aws-sts-endpoint-uri", "test-endpoint-uri") + .withEntry("role", "test-role") + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") @@ -228,7 +175,16 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports Azure MSI authentication") void testAzureMsiAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(azureMsiBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "azure_msi") + .withEntry("azure-path", "test-azure-path") + .withEntry("role", "test-role") + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") @@ -240,7 +196,17 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports GCP GCE authentication") void testGcpGceAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(gcpGceBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "gcp_gce") + .withEntry("gcp-path", "test-gcp-path") + .withEntry("gcp-service-account", "test-service-account") + .withEntry("role", "test-role") + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") @@ -253,13 +219,27 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports GCP IAM authentication") void testGcpIamAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(gcpIamBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "gcp_iam") + .withEntry("credentials.json", "credentials JSON contents!") + .withEntry("encoded-key", "test-encoded-key") + .withEntry("gcp-path", "test-gcp-path") + .withEntry("gcp-project-id", "test-project-id") + .withEntry("gcp-service-account", "test-service-account") + .withEntry("jwt-validity", "test-jwt-validity") + .withEntry("role", "test-role") + ) + ); + + new VaultBindingsPropertiesProcessor().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/secret/credentials.json") + .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") @@ -270,7 +250,16 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Supports Kubernetes authentication") void testK8sAuthentication() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(k8sBinding), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "kubernetes") + .withEntry("role", "test-role") + .withEntry("kubernetes-path", "test-kubernetes-path") + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") @@ -282,33 +271,62 @@ final class VaultPropertiesProcessorTest { @Test @DisplayName("Doesn't fail when method is missing") void testMissingProvider() { - new VaultBindingsPropertiesProcessor().process(environment, new Bindings(new Binding( - "test-name", - Paths.get("test-path"), - metadata(), - baseSecret() - )), properties); + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + ) + ); + + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties) .containsEntry("spring.cloud.vault.uri", "test-uri") .containsEntry("spring.cloud.vault.namespace", "test-namespace") .doesNotContainKey("spring.cloud.vault.authentication"); } - //Vault agent authentication can be configured using a sidecar and should not require a binding - @Test @DisplayName("can be disabled") void disabled() { + Bindings bindings = new Bindings( + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "token") + .withEntry("token", "test-token") + ), + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("app-role-path", "test-app-role-path") + .withEntry("authentication-method", "approle") + .withEntry("role", "test-role") + .withEntry("role-id", "test-role-id") + .withEntry("secret-id", "test-secret-id") + ), + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "cubbyhole") + .withEntry("token", "test-token") + ), + new Binding("test-name", Paths.get("test-path"), + baseSecret() + .withEntry("authentication-method", "cert") + .withEntry("cert-auth-path", "test-cert-auth-path") + .withEntry("key-store-password", "test-key-store-password") + .withEntry("keystore.jks", "key store contents!") + ) + ); + environment.setProperty("org.springframework.cloud.bindings.boot.vault.enable", "false"); - new VaultBindingsPropertiesProcessor().process(environment, new Bindings( - tokenBinding, - appRoleBinding, - cubbyholeBinding, - certBinding - ), properties); + new VaultBindingsPropertiesProcessor().process(environment, bindings, properties); assertThat(properties).isEmpty(); } + private FluentMap baseSecret() { + return new FluentMap() + .withEntry(Binding.TYPE, TYPE) + .withEntry("namespace", "test-namespace") + .withEntry("uri", "test-uri"); + } + } diff --git a/src/test/java/org/springframework/cloud/bindings/boot/WavefrontPropertiesProcessorTest.java b/src/test/java/org/springframework/cloud/bindings/boot/WavefrontBindingsPropertiesProcessorTest.java similarity index 93% rename from src/test/java/org/springframework/cloud/bindings/boot/WavefrontPropertiesProcessorTest.java rename to src/test/java/org/springframework/cloud/bindings/boot/WavefrontBindingsPropertiesProcessorTest.java index 090bfe1..eb4f513 100644 --- a/src/test/java/org/springframework/cloud/bindings/boot/WavefrontPropertiesProcessorTest.java +++ b/src/test/java/org/springframework/cloud/bindings/boot/WavefrontBindingsPropertiesProcessorTest.java @@ -24,19 +24,18 @@ import org.springframework.cloud.bindings.FluentMap; import org.springframework.mock.env.MockEnvironment; import java.nio.file.Paths; -import java.util.Collections; import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.cloud.bindings.boot.WavefrontBindingsPropertiesProcessor.KIND; +import static org.springframework.cloud.bindings.boot.WavefrontBindingsPropertiesProcessor.TYPE; @DisplayName("Wavefront BindingsPropertiesProcessor") -final class WavefrontPropertiesProcessorTest { +final class WavefrontBindingsPropertiesProcessorTest { private final Bindings bindings = new Bindings( new Binding("test-name", Paths.get("test-path"), - Collections.singletonMap("kind", KIND), new FluentMap() + .withEntry(Binding.TYPE, TYPE) .withEntry("api-token", "test-api-token") .withEntry("uri", "test-uri") ) diff --git a/src/test/resources/test-k8s/metadata/.hidden-data b/src/test/resources/cnb/test-k8s/metadata/.hidden-data similarity index 100% rename from src/test/resources/test-k8s/metadata/.hidden-data rename to src/test/resources/cnb/test-k8s/metadata/.hidden-data diff --git a/src/test/resources/test-k8s/metadata/.hidden-data-1/kind b/src/test/resources/cnb/test-k8s/metadata/.hidden-data-1/kind similarity index 100% rename from src/test/resources/test-k8s/metadata/.hidden-data-1/kind rename to src/test/resources/cnb/test-k8s/metadata/.hidden-data-1/kind diff --git a/src/test/resources/test-k8s/metadata/.hidden-data-1/provider b/src/test/resources/cnb/test-k8s/metadata/.hidden-data-1/provider similarity index 100% rename from src/test/resources/test-k8s/metadata/.hidden-data-1/provider rename to src/test/resources/cnb/test-k8s/metadata/.hidden-data-1/provider diff --git a/src/test/resources/cnb/test-k8s/metadata/.hidden-data-1/test-metadata-key b/src/test/resources/cnb/test-k8s/metadata/.hidden-data-1/test-metadata-key new file mode 100644 index 0000000..9f4070b --- /dev/null +++ b/src/test/resources/cnb/test-k8s/metadata/.hidden-data-1/test-metadata-key @@ -0,0 +1 @@ +test-metadata-value diff --git a/src/test/resources/test-k8s/metadata/kind b/src/test/resources/cnb/test-k8s/metadata/kind similarity index 100% rename from src/test/resources/test-k8s/metadata/kind rename to src/test/resources/cnb/test-k8s/metadata/kind diff --git a/src/test/resources/test-k8s/metadata/provider b/src/test/resources/cnb/test-k8s/metadata/provider similarity index 100% rename from src/test/resources/test-k8s/metadata/provider rename to src/test/resources/cnb/test-k8s/metadata/provider diff --git a/src/test/resources/cnb/test-k8s/metadata/test-metadata-key b/src/test/resources/cnb/test-k8s/metadata/test-metadata-key new file mode 120000 index 0000000..443a743 --- /dev/null +++ b/src/test/resources/cnb/test-k8s/metadata/test-metadata-key @@ -0,0 +1 @@ +.hidden-data/test-metadata-key \ No newline at end of file diff --git a/src/test/resources/test-k8s/secret/.hidden-data b/src/test/resources/cnb/test-k8s/secret/.hidden-data similarity index 100% rename from src/test/resources/test-k8s/secret/.hidden-data rename to src/test/resources/cnb/test-k8s/secret/.hidden-data diff --git a/src/test/resources/cnb/test-k8s/secret/.hidden-data-1/test-secret-key b/src/test/resources/cnb/test-k8s/secret/.hidden-data-1/test-secret-key new file mode 100644 index 0000000..fffe74e --- /dev/null +++ b/src/test/resources/cnb/test-k8s/secret/.hidden-data-1/test-secret-key @@ -0,0 +1 @@ +test-secret-value diff --git a/src/test/resources/cnb/test-k8s/secret/test-secret-key b/src/test/resources/cnb/test-k8s/secret/test-secret-key new file mode 120000 index 0000000..9b4711a --- /dev/null +++ b/src/test/resources/cnb/test-k8s/secret/test-secret-key @@ -0,0 +1 @@ +.hidden-data/test-secret-key \ No newline at end of file diff --git a/src/test/resources/test-name-1/metadata/kind b/src/test/resources/cnb/test-name-1/metadata/kind similarity index 100% rename from src/test/resources/test-name-1/metadata/kind rename to src/test/resources/cnb/test-name-1/metadata/kind diff --git a/src/test/resources/test-name-1/metadata/provider b/src/test/resources/cnb/test-name-1/metadata/provider similarity index 100% rename from src/test/resources/test-name-1/metadata/provider rename to src/test/resources/cnb/test-name-1/metadata/provider diff --git a/src/test/resources/cnb/test-name-1/metadata/test-metadata-key b/src/test/resources/cnb/test-name-1/metadata/test-metadata-key new file mode 100644 index 0000000..9f4070b --- /dev/null +++ b/src/test/resources/cnb/test-name-1/metadata/test-metadata-key @@ -0,0 +1 @@ +test-metadata-value diff --git a/src/test/resources/cnb/test-name-1/secret/test-secret-key b/src/test/resources/cnb/test-name-1/secret/test-secret-key new file mode 100644 index 0000000..fffe74e --- /dev/null +++ b/src/test/resources/cnb/test-name-1/secret/test-secret-key @@ -0,0 +1 @@ +test-secret-value diff --git a/src/test/resources/test-name-2/metadata/kind b/src/test/resources/cnb/test-name-2/metadata/kind similarity index 100% rename from src/test/resources/test-name-2/metadata/kind rename to src/test/resources/cnb/test-name-2/metadata/kind diff --git a/src/test/resources/test-name-2/metadata/provider b/src/test/resources/cnb/test-name-2/metadata/provider similarity index 100% rename from src/test/resources/test-name-2/metadata/provider rename to src/test/resources/cnb/test-name-2/metadata/provider diff --git a/src/test/resources/cnb/test-name-2/metadata/test-metadata-key b/src/test/resources/cnb/test-name-2/metadata/test-metadata-key new file mode 100644 index 0000000..9f4070b --- /dev/null +++ b/src/test/resources/cnb/test-name-2/metadata/test-metadata-key @@ -0,0 +1 @@ +test-metadata-value diff --git a/src/test/resources/cnb/test-name-2/secret/test-secret-key b/src/test/resources/cnb/test-name-2/secret/test-secret-key new file mode 100644 index 0000000..fffe74e --- /dev/null +++ b/src/test/resources/cnb/test-name-2/secret/test-secret-key @@ -0,0 +1 @@ +test-secret-value diff --git a/src/test/resources/k8s/test-k8s/.hidden-data b/src/test/resources/k8s/test-k8s/.hidden-data new file mode 120000 index 0000000..b4901b5 --- /dev/null +++ b/src/test/resources/k8s/test-k8s/.hidden-data @@ -0,0 +1 @@ +.hidden-data-1 \ No newline at end of file diff --git a/src/test/resources/k8s/test-k8s/.hidden-data-1/provider b/src/test/resources/k8s/test-k8s/.hidden-data-1/provider new file mode 100644 index 0000000..0036389 --- /dev/null +++ b/src/test/resources/k8s/test-k8s/.hidden-data-1/provider @@ -0,0 +1 @@ +test-provider-1 diff --git a/src/test/resources/k8s/test-k8s/.hidden-data-1/test-secret-key b/src/test/resources/k8s/test-k8s/.hidden-data-1/test-secret-key new file mode 100644 index 0000000..fffe74e --- /dev/null +++ b/src/test/resources/k8s/test-k8s/.hidden-data-1/test-secret-key @@ -0,0 +1 @@ +test-secret-value diff --git a/src/test/resources/k8s/test-k8s/.hidden-data-1/type b/src/test/resources/k8s/test-k8s/.hidden-data-1/type new file mode 100644 index 0000000..b3f16a9 --- /dev/null +++ b/src/test/resources/k8s/test-k8s/.hidden-data-1/type @@ -0,0 +1 @@ +test-type-1 diff --git a/src/test/resources/k8s/test-k8s/provider b/src/test/resources/k8s/test-k8s/provider new file mode 120000 index 0000000..7ba8004 --- /dev/null +++ b/src/test/resources/k8s/test-k8s/provider @@ -0,0 +1 @@ +.hidden-data/provider \ No newline at end of file diff --git a/src/test/resources/k8s/test-k8s/test-secret-key b/src/test/resources/k8s/test-k8s/test-secret-key new file mode 120000 index 0000000..9b4711a --- /dev/null +++ b/src/test/resources/k8s/test-k8s/test-secret-key @@ -0,0 +1 @@ +.hidden-data/test-secret-key \ No newline at end of file diff --git a/src/test/resources/k8s/test-k8s/type b/src/test/resources/k8s/test-k8s/type new file mode 120000 index 0000000..342d0e8 --- /dev/null +++ b/src/test/resources/k8s/test-k8s/type @@ -0,0 +1 @@ +.hidden-data/type \ No newline at end of file diff --git a/src/test/resources/k8s/test-name-1/provider b/src/test/resources/k8s/test-name-1/provider new file mode 100644 index 0000000..0036389 --- /dev/null +++ b/src/test/resources/k8s/test-name-1/provider @@ -0,0 +1 @@ +test-provider-1 diff --git a/src/test/resources/k8s/test-name-1/test-secret-key b/src/test/resources/k8s/test-name-1/test-secret-key new file mode 100644 index 0000000..fffe74e --- /dev/null +++ b/src/test/resources/k8s/test-name-1/test-secret-key @@ -0,0 +1 @@ +test-secret-value diff --git a/src/test/resources/k8s/test-name-1/type b/src/test/resources/k8s/test-name-1/type new file mode 100644 index 0000000..b3f16a9 --- /dev/null +++ b/src/test/resources/k8s/test-name-1/type @@ -0,0 +1 @@ +test-type-1 diff --git a/src/test/resources/k8s/test-name-2/provider b/src/test/resources/k8s/test-name-2/provider new file mode 100644 index 0000000..a4f5045 --- /dev/null +++ b/src/test/resources/k8s/test-name-2/provider @@ -0,0 +1 @@ +test-provider-2 diff --git a/src/test/resources/k8s/test-name-2/test-secret-key b/src/test/resources/k8s/test-name-2/test-secret-key new file mode 100644 index 0000000..fffe74e --- /dev/null +++ b/src/test/resources/k8s/test-name-2/test-secret-key @@ -0,0 +1 @@ +test-secret-value diff --git a/src/test/resources/k8s/test-name-2/type b/src/test/resources/k8s/test-name-2/type new file mode 100644 index 0000000..b0c27fb --- /dev/null +++ b/src/test/resources/k8s/test-name-2/type @@ -0,0 +1 @@ +test-type-2 diff --git a/src/test/resources/test-k8s/metadata/.hidden-data-1/.gitkeep b/src/test/resources/test-k8s/metadata/.hidden-data-1/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/resources/test-k8s/secret/.hidden-data-1/.gitkeep b/src/test/resources/test-k8s/secret/.hidden-data-1/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/resources/test-k8s/secret/.hidden-data-1/test-key b/src/test/resources/test-k8s/secret/.hidden-data-1/test-key deleted file mode 100644 index 2278763..0000000 --- a/src/test/resources/test-k8s/secret/.hidden-data-1/test-key +++ /dev/null @@ -1 +0,0 @@ -test-value diff --git a/src/test/resources/test-k8s/secret/test-key b/src/test/resources/test-k8s/secret/test-key deleted file mode 120000 index c8d4599..0000000 --- a/src/test/resources/test-k8s/secret/test-key +++ /dev/null @@ -1 +0,0 @@ -.hidden-data/test-key \ No newline at end of file diff --git a/src/test/resources/test-name-1/secret/test-key b/src/test/resources/test-name-1/secret/test-key deleted file mode 100644 index 2278763..0000000 --- a/src/test/resources/test-name-1/secret/test-key +++ /dev/null @@ -1 +0,0 @@ -test-value diff --git a/src/test/resources/test-name-2/secret/test-key b/src/test/resources/test-name-2/secret/test-key deleted file mode 100644 index 2278763..0000000 --- a/src/test/resources/test-name-2/secret/test-key +++ /dev/null @@ -1 +0,0 @@ -test-value