You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2022/07/14 12:56:47 UTC
[camel-spring-boot] 02/02: CAMEL-17688 - Support ability to load properties from Vault/Secrets cloud services - Hashicorp Vault
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit 186b4f2710063468ede55a70d2d404f0e9ec1181
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Jul 14 14:42:51 2022 +0200
CAMEL-17688 - Support ability to load properties from Vault/Secrets cloud services - Hashicorp Vault
---
.../src/main/docs/spring-boot.json | 35 +++++++++
.../vault/HashicorpVaultAutoConfiguration.java | 44 +++++++++++
.../HashicorpVaultConfigurationProperties.java | 88 ++++++++++++++++++++++
.../vault/HashicorpVaultConfigurationTest.java | 55 ++++++++++++++
4 files changed, 222 insertions(+)
diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.json b/core/camel-spring-boot/src/main/docs/spring-boot.json
index 828a160791a..a6d7dd8d232 100644
--- a/core/camel-spring-boot/src/main/docs/spring-boot.json
+++ b/core/camel-spring-boot/src/main/docs/spring-boot.json
@@ -129,6 +129,11 @@
"type": "org.apache.camel.spring.boot.vault.GcpVaultConfigurationProperties",
"sourceType": "org.apache.camel.spring.boot.vault.GcpVaultConfigurationProperties"
},
+ {
+ "name": "camel.vault.hashicorp",
+ "type": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties",
+ "sourceType": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties"
+ },
{
"name": "management.endpoint.camel",
"type": "org.apache.camel.spring.boot.actuate.console.CamelDevConsoleEndpoint",
@@ -1410,6 +1415,36 @@
"sourceType": "org.apache.camel.spring.boot.vault.GcpVaultConfigurationProperties",
"defaultValue": false
},
+ {
+ "name": "camel.vault.hashicorp.engine",
+ "type": "java.lang.String",
+ "description": "The Hashicorp Vault Engine for accessing secrets",
+ "sourceType": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties"
+ },
+ {
+ "name": "camel.vault.hashicorp.host",
+ "type": "java.lang.String",
+ "description": "The Hashicorp Vault Host for accessing the service",
+ "sourceType": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties"
+ },
+ {
+ "name": "camel.vault.hashicorp.port",
+ "type": "java.lang.String",
+ "description": "The Hashicorp Vault port for accessing the service",
+ "sourceType": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties"
+ },
+ {
+ "name": "camel.vault.hashicorp.scheme",
+ "type": "java.lang.String",
+ "description": "The Hashicorp Vault Scheme for accessing the service",
+ "sourceType": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties"
+ },
+ {
+ "name": "camel.vault.hashicorp.token",
+ "type": "java.lang.String",
+ "description": "The Hashicorp Vault Token for accessing the service",
+ "sourceType": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties"
+ },
{
"name": "management.endpoint.camel.cache.time-to-live",
"type": "java.time.Duration",
diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/HashicorpVaultAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/HashicorpVaultAutoConfiguration.java
new file mode 100644
index 00000000000..a5f50df3191
--- /dev/null
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/HashicorpVaultAutoConfiguration.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.spring.boot.vault;
+
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.vault.HashicorpVaultConfiguration;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnBean(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(HashicorpVaultConfigurationProperties.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+public class HashicorpVaultAutoConfiguration {
+
+ @Bean
+ public HashicorpVaultConfiguration hashicorpVaultConfiguration(HashicorpVaultConfigurationProperties config) {
+ HashicorpVaultConfiguration answer = new HashicorpVaultConfiguration();
+ answer.setToken(config.getToken());
+ answer.setEngine(config.getEngine());
+ answer.setHost(config.getHost());
+ answer.setPort(config.getPort());
+ answer.setScheme(config.getScheme());
+ return answer;
+ }
+
+}
diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/HashicorpVaultConfigurationProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/HashicorpVaultConfigurationProperties.java
new file mode 100644
index 00000000000..08e61edfc67
--- /dev/null
+++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/HashicorpVaultConfigurationProperties.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.spring.boot.vault;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.vault.hashicorp")
+public class HashicorpVaultConfigurationProperties {
+
+ /**
+ * The Hashicorp Vault Token for accessing the service
+ */
+ private String token;
+
+ /**
+ * The Hashicorp Vault Engine for accessing secrets
+ */
+ private String engine;
+
+ /**
+ * The Hashicorp Vault Host for accessing the service
+ */
+ private String host;
+
+ /**
+ * The Hashicorp Vault port for accessing the service
+ */
+ private String port;
+
+ /**
+ * The Hashicorp Vault Scheme for accessing the service
+ */
+ private String scheme;
+
+ public String getToken() {
+ return token;
+ }
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+
+ public String getEngine() {
+ return engine;
+ }
+
+ public void setEngine(String engine) {
+ this.engine = engine;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getPort() {
+ return port;
+ }
+
+ public void setPort(String port) {
+ this.port = port;
+ }
+
+ public String getScheme() {
+ return scheme;
+ }
+
+ public void setScheme(String scheme) {
+ this.scheme = scheme;
+ }
+}
diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/HashicorpVaultConfigurationTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/HashicorpVaultConfigurationTest.java
new file mode 100644
index 00000000000..df91ce61130
--- /dev/null
+++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/HashicorpVaultConfigurationTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.spring.boot.vault;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+
+@DirtiesContext
+@CamelSpringBootTest
+@EnableAutoConfiguration
+@SpringBootTest(
+ classes = {
+ HashicorpVaultConfigurationTest.class},
+ properties = {
+ "camel.vault.hashicorp.token=myToken",
+ "camel.vault.hashicorp.engine=myEngine",
+ "camel.vault.hashicorp.host=myHost",
+ "camel.vault.hashicorp.port=myPort",
+ "camel.vault.hashicorp.scheme=myScheme"
+ }
+)
+public class HashicorpVaultConfigurationTest {
+
+ @Autowired
+ private CamelContext camelContext;
+
+ @Test
+ public void testAwsVault() throws Exception {
+ Assertions.assertEquals("myToken", camelContext.getVaultConfiguration().hashicorp().getToken());
+ Assertions.assertEquals("myEngine", camelContext.getVaultConfiguration().hashicorp().getEngine());
+ Assertions.assertEquals("myHost", camelContext.getVaultConfiguration().hashicorp().getHost());
+ Assertions.assertEquals("myPort", camelContext.getVaultConfiguration().hashicorp().getPort());
+ Assertions.assertEquals("myScheme", camelContext.getVaultConfiguration().hashicorp().getScheme());
+ }
+}