Skip to content

Commit

Permalink
CAMEL-21167 - Camel-Spring-Boot: Kubernetes Secrets Trigger context r… (
Browse files Browse the repository at this point in the history
#1209)

* CAMEL-21167 - Camel-Spring-Boot: Kubernetes Secrets Trigger context reloading on update support

Signed-off-by: Andrea Cosentino <[email protected]>

* CAMEL-21167 - Camel-Spring-Boot: Kubernetes Secrets Trigger context reloading on update support

Signed-off-by: Andrea Cosentino <[email protected]>

---------

Signed-off-by: Andrea Cosentino <[email protected]>
  • Loading branch information
oscerd authored Sep 4, 2024
1 parent 1cdc74f commit 010b126
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/camel-spring-boot/src/main/docs/spring-boot.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 010b126

Please sign in to comment.