From 5226f3e4500948294fc50e59232831566de87690 Mon Sep 17 00:00:00 2001 From: Andrea Cosentino Date: Wed, 4 Sep 2024 09:01:54 +0200 Subject: [PATCH 1/2] CAMEL-21167 - Camel-Spring-Boot: Kubernetes Secrets Trigger context reloading on update support Signed-off-by: Andrea Cosentino --- .../src/main/docs/spring-boot.json | 18 +++++++ .../KubernetesVaultAutoConfiguration.java | 41 +++++++++++++++ ...ubernetesVaultConfigurationProperties.java | 51 +++++++++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../KubernetesVaultConfigurationTest.java | 43 ++++++++++++++++ .../camel-spring-boot-dependencies/pom.xml | 5 -- 6 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/KubernetesVaultAutoConfiguration.java create mode 100644 core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/KubernetesVaultConfigurationProperties.java create mode 100644 core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/KubernetesVaultConfigurationTest.java 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 49d5fa990f1..9a87ba22734 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.json +++ b/core/camel-spring-boot/src/main/docs/spring-boot.json @@ -156,6 +156,11 @@ "type": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties", "sourceType": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties" }, + { + "name": "camel.vault.kubernetes", + "type": "org.apache.camel.spring.boot.vault.KubernetesVaultConfigurationProperties", + "sourceType": "org.apache.camel.spring.boot.vault.KubernetesVaultConfigurationProperties" + }, { "name": "management.endpoint.camel", "type": "org.apache.camel.spring.boot.actuate.console.CamelDevConsoleEndpoint", @@ -1841,6 +1846,19 @@ "description": "The Hashicorp Vault Token for accessing the service", "sourceType": "org.apache.camel.spring.boot.vault.HashicorpVaultConfigurationProperties" }, + { + "name": "camel.vault.kubernetes.refresh-enabled", + "type": "java.lang.Boolean", + "description": "Define if we want to refresh the secrets on update", + "sourceType": "org.apache.camel.spring.boot.vault.KubernetesVaultConfigurationProperties", + "defaultValue": false + }, + { + "name": "camel.vault.kubernetes.secrets", + "type": "java.lang.String", + "description": "Define the secrets to look at", + "sourceType": "org.apache.camel.spring.boot.vault.KubernetesVaultConfigurationProperties" + }, { "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/KubernetesVaultAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/KubernetesVaultAutoConfiguration.java new file mode 100644 index 00000000000..ed56c48e739 --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/KubernetesVaultAutoConfiguration.java @@ -0,0 +1,41 @@ +/* + * 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.KubernetesVaultConfiguration; +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(KubernetesVaultConfigurationProperties.class) +@AutoConfigureAfter(CamelAutoConfiguration.class) +public class KubernetesVaultAutoConfiguration { + + @Bean + public KubernetesVaultConfiguration kubernetesVaultConfiguration(KubernetesVaultConfigurationProperties config) { + KubernetesVaultConfiguration answer = new KubernetesVaultConfiguration(); + answer.setRefreshEnabled(config.isRefreshEnabled()); + answer.setSecrets(config.getSecrets()); + return answer; + } + +} diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/KubernetesVaultConfigurationProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/KubernetesVaultConfigurationProperties.java new file mode 100644 index 00000000000..19173c8504f --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/vault/KubernetesVaultConfigurationProperties.java @@ -0,0 +1,51 @@ +/* + * 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.kubernetes") +public class KubernetesVaultConfigurationProperties { + + /** + * Define if we want to refresh the secrets on update + */ + private boolean refreshEnabled; + + /** + * Define the secrets to look at + */ + private String secrets; + + + + public boolean isRefreshEnabled() { + return refreshEnabled; + } + + public void setRefreshEnabled(boolean refreshEnabled) { + this.refreshEnabled = refreshEnabled; + } + + public String getSecrets() { + return secrets; + } + + public void setSecrets(String secrets) { + this.secrets = secrets; + } +} diff --git a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 30f28a88919..2fb21e7f846 100644 --- a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -39,3 +39,4 @@ org.apache.camel.spring.boot.vault.AwsVaultAutoConfiguration org.apache.camel.spring.boot.vault.GcpVaultAutoConfiguration org.apache.camel.spring.boot.vault.AzureVaultAutoConfiguration org.apache.camel.spring.boot.vault.HashicorpVaultAutoConfiguration +org.apache.camel.spring.boot.vault.KubernetesVaultAutoConfiguration diff --git a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/KubernetesVaultConfigurationTest.java b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/KubernetesVaultConfigurationTest.java new file mode 100644 index 00000000000..2afe3ffdd96 --- /dev/null +++ b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/vault/KubernetesVaultConfigurationTest.java @@ -0,0 +1,43 @@ +/* + * 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 = { KubernetesVaultConfigurationTest.class }, properties = { + "camel.vault.kubernetes.refreshEnabled=true", "camel.vault.kubernetes.secrets=supersecret" }) +public class KubernetesVaultConfigurationTest { + + @Autowired + private CamelContext camelContext; + + @Test + public void testKubernetesVault() throws Exception { + Assertions.assertEquals(true, camelContext.getVaultConfiguration().kubernetes().isRefreshEnabled()); + Assertions.assertEquals("supersecret", camelContext.getVaultConfiguration().kubernetes().getSecrets()); + } +} diff --git a/tooling/camel-spring-boot-dependencies/pom.xml b/tooling/camel-spring-boot-dependencies/pom.xml index 1ee54989164..3ded4ff1d52 100644 --- a/tooling/camel-spring-boot-dependencies/pom.xml +++ b/tooling/camel-spring-boot-dependencies/pom.xml @@ -3419,11 +3419,6 @@ camel-langchain4j-tokenizer 4.8.0-SNAPSHOT - - org.apache.camel - camel-langchain4j-tools - 4.8.0-SNAPSHOT - org.apache.camel camel-langchain4j-web-search From 27e3d134646655457017421bfc62de74e714224c Mon Sep 17 00:00:00 2001 From: Andrea Cosentino Date: Wed, 4 Sep 2024 10:24:02 +0200 Subject: [PATCH 2/2] CAMEL-21167 - Camel-Spring-Boot: Kubernetes Secrets Trigger context reloading on update support Signed-off-by: Andrea Cosentino --- tooling/camel-spring-boot-dependencies/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tooling/camel-spring-boot-dependencies/pom.xml b/tooling/camel-spring-boot-dependencies/pom.xml index 3ded4ff1d52..1ee54989164 100644 --- a/tooling/camel-spring-boot-dependencies/pom.xml +++ b/tooling/camel-spring-boot-dependencies/pom.xml @@ -3419,6 +3419,11 @@ camel-langchain4j-tokenizer 4.8.0-SNAPSHOT + + org.apache.camel + camel-langchain4j-tools + 4.8.0-SNAPSHOT + org.apache.camel camel-langchain4j-web-search