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/09/15 18:10:43 UTC
[camel] 01/02: CAMEL-18511 - Camel-Azure-Key-Vault: Create a task looking for secrets update in Eventhubs
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.git
commit b0f15e5a2af559f8f3cda880c32a4ddb87e6c1db
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Sep 15 19:07:41 2022 +0200
CAMEL-18511 - Camel-Azure-Key-Vault: Create a task looking for secrets update in Eventhubs
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../main/camel-main-configuration-metadata.json | 7 +
.../camel-azure/camel-azure-key-vault/pom.xml | 8 +
.../camel/periodic-task/azure-secret-refresh | 2 +
.../key/vault/EventhubsReloadTriggerTask.java | 239 +++++++++++++++++++++
.../key/vault/KeyVaultPropertiesFunction.java | 22 ++
.../camel/vault/AzureVaultConfiguration.java | 91 ++++++++
...zureVaultConfigurationPropertiesConfigurer.java | 42 ++++
.../vault/AzureVaultConfigurationConfigurer.java | 42 ++++
.../camel-main-configuration-metadata.json | 7 +
core/camel-main/src/main/docs/main.adoc | 9 +-
.../main/AzureVaultConfigurationProperties.java | 58 ++++-
.../org/apache/camel/main/BaseMainSupport.java | 19 ++
12 files changed, 544 insertions(+), 2 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
index 326888ac898..efd1b33060a 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
@@ -214,8 +214,15 @@
{ "name": "camel.vault.aws.region", "description": "The AWS region", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.aws.secretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.aws.secrets", "description": "Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma.", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.blobAccessKey", "description": "The Eventhubs Blob Access Key for CheckpointStore purpose", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.blobAccountName", "description": "The Eventhubs Blob Account Name for CheckpointStore purpose", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.blobContainerName", "description": "The Eventhubs Blob Container Name for CheckpointStore purpose", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.azure.clientId", "description": "The client Id for accessing Azure Key Vault", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.azure.clientSecret", "description": "The client Secret for accessing Azure Key Vault", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.eventhubConnectionString", "description": "The Eventhubs connection String for Key Vault Secret events notifications", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.refreshEnabled", "description": "Whether to automatically reload Camel upon secrets being updated in Azure.", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
+ { "name": "camel.vault.azure.refreshPeriod", "description": "The period (millis) between checking Azure for updated secrets.", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "integer", "javaType": "long", "defaultValue": 30000 },
+ { "name": "camel.vault.azure.secrets", "description": "Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma.", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.azure.tenantId", "description": "The Tenant Id for accessing Azure Key Vault", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.azure.vaultName", "description": "The vault Name in Azure Key Vault", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.gcp.projectId", "description": "The GCP Project ID", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
diff --git a/components/camel-azure/camel-azure-key-vault/pom.xml b/components/camel-azure/camel-azure-key-vault/pom.xml
index be9f1bc573e..5f02311ad27 100644
--- a/components/camel-azure/camel-azure-key-vault/pom.xml
+++ b/components/camel-azure/camel-azure-key-vault/pom.xml
@@ -46,6 +46,14 @@
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-secrets</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.azure</groupId>
+ <artifactId>azure-messaging-eventhubs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.azure</groupId>
+ <artifactId>azure-messaging-eventhubs-checkpointstore-blob</artifactId>
+ </dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
diff --git a/components/camel-azure/camel-azure-key-vault/src/generated/resources/META-INF/services/org/apache/camel/periodic-task/azure-secret-refresh b/components/camel-azure/camel-azure-key-vault/src/generated/resources/META-INF/services/org/apache/camel/periodic-task/azure-secret-refresh
new file mode 100644
index 00000000000..494db245971
--- /dev/null
+++ b/components/camel-azure/camel-azure-key-vault/src/generated/resources/META-INF/services/org/apache/camel/periodic-task/azure-secret-refresh
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.azure.key.vault.EventhubsReloadTriggerTask
diff --git a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/EventhubsReloadTriggerTask.java b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/EventhubsReloadTriggerTask.java
new file mode 100644
index 00000000000..b9fc9218dcc
--- /dev/null
+++ b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/EventhubsReloadTriggerTask.java
@@ -0,0 +1,239 @@
+/*
+ * 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.component.azure.key.vault;
+
+import java.time.Instant;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.ContextReloadStrategy;
+import org.apache.camel.spi.PropertiesComponent;
+import org.apache.camel.spi.PropertiesFunction;
+import org.apache.camel.spi.annotations.PeriodicTask;
+import org.apache.camel.support.PatternHelper;
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.vault.AzureVaultConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.azure.core.amqp.AmqpTransportType;
+import com.azure.messaging.eventhubs.EventProcessorClient;
+import com.azure.messaging.eventhubs.EventProcessorClientBuilder;
+import com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore;
+import com.azure.messaging.eventhubs.models.ErrorContext;
+import com.azure.messaging.eventhubs.models.EventContext;
+import com.azure.storage.blob.BlobContainerAsyncClient;
+import com.azure.storage.blob.BlobContainerClientBuilder;
+import com.azure.storage.common.StorageSharedKeyCredential;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Period task which checks if Azure Key Vaults secrets has been updated and can trigger Camel to be reloaded.
+ */
+@PeriodicTask("azure-secret-refresh")
+public class EventhubsReloadTriggerTask extends ServiceSupport implements CamelContextAware, Runnable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EventhubsReloadTriggerTask.class);
+
+ private static final String BLOB_SERVICE_URI_SEGMENT = ".blob.core.windows.net";
+ private CamelContext camelContext;
+ private boolean reloadEnabled = true;
+ private String secrets;
+ private EventProcessorClient eventProcessorClient;
+ private KeyVaultPropertiesFunction propertiesFunction;
+ private final Map<String, Instant> updates = new HashMap<>();
+
+ public EventhubsReloadTriggerTask() {
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ public boolean isReloadEnabled() {
+ return reloadEnabled;
+ }
+
+ /**
+ * Whether Camel should be reloaded on Azure secret updated
+ */
+ public void setReloadEnabled(boolean reloadEnabled) {
+ this.reloadEnabled = reloadEnabled;
+ }
+
+ /**
+ * A map of the updated secrets with the latest updated time.
+ */
+ public Map<String, Instant> getUpdates() {
+ return Collections.unmodifiableMap(updates);
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ // auto-detect secrets in-use
+ PropertiesComponent pc = camelContext.getPropertiesComponent();
+ PropertiesFunction pf = pc.getPropertiesFunction("azure");
+ if (pf instanceof KeyVaultPropertiesFunction) {
+ propertiesFunction = (KeyVaultPropertiesFunction) pf;
+ LOG.debug("Auto-detecting secrets from properties-function: {}", pf.getName());
+ }
+ // specific secrets
+ secrets = camelContext.getVaultConfiguration().azure().getSecrets();
+ if (ObjectHelper.isEmpty(secrets) && propertiesFunction == null) {
+ throw new IllegalArgumentException("Secrets must be configured on Azure vault configuration");
+ }
+
+ String eventhubConnectionString = null;
+ String blobAccessKey = null;
+ String blobAccountName = null;
+ String blobContainerName = null;
+ AzureVaultConfiguration azureVaultConfiguration = getCamelContext().getVaultConfiguration().azure();
+ if (ObjectHelper.isNotEmpty(azureVaultConfiguration)) {
+ eventhubConnectionString = azureVaultConfiguration.getEventhubConnectionString();
+ blobAccessKey = azureVaultConfiguration.getBlobAccessKey();
+ blobAccountName = azureVaultConfiguration.getBlobAccountName();
+ blobContainerName = azureVaultConfiguration.getBlobContainerName();
+ }
+ if (ObjectHelper.isNotEmpty(eventhubConnectionString) && ObjectHelper.isNotEmpty(blobAccessKey)
+ && ObjectHelper.isNotEmpty(blobAccountName) && ObjectHelper.isNotEmpty(blobContainerName)) {
+ BlobContainerAsyncClient c = new BlobContainerClientBuilder()
+ .endpoint(String.format(Locale.ROOT, "https://%s" + BLOB_SERVICE_URI_SEGMENT, blobAccountName))
+ .containerName(blobContainerName)
+ .credential(new StorageSharedKeyCredential(blobAccountName, blobAccessKey))
+ .buildAsyncClient();
+
+
+ EventProcessorClientBuilder eventProcessorClientBuilder = new EventProcessorClientBuilder()
+ .checkpointStore(new BlobCheckpointStore(c))
+ .consumerGroup("$Default")
+ .connectionString(eventhubConnectionString)
+ .processEvent(this::onEventListener)
+ .processError(this::onErrorListener)
+ .transportType(AmqpTransportType.AMQP);
+
+ eventProcessorClient = eventProcessorClientBuilder.buildEventProcessorClient();
+ eventProcessorClient.start();
+ } else {
+ throw new RuntimeCamelException(
+ "Using the Azure Key Vault Secret refresh task requires setting eventhubs connection String, Blob Account Name, Blob Access Key and Blob Container Name as application properties ");
+ }
+ }
+
+ @Override
+ protected void doShutdown() throws Exception {
+ super.doShutdown();
+
+ if (eventProcessorClient != null) {
+ try {
+ eventProcessorClient.stop();
+ } catch (Exception e) {
+ // ignore
+ }
+ eventProcessorClient = null;
+ }
+
+ updates.clear();
+ }
+
+ @Override
+ public void run() {
+ }
+
+ protected boolean matchSecret(String name) {
+ Set<String> set = new HashSet<>();
+ if (secrets != null) {
+ Collections.addAll(set, secrets.split(","));
+ }
+ if (propertiesFunction != null) {
+ set.addAll(propertiesFunction.getSecrets());
+ }
+
+ for (String part : set) {
+ boolean result = name.contains(part) || PatternHelper.matchPattern(name, part);
+ LOG.trace("Matching secret id: {}={} -> {}", name, part, result);
+ if (result) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "Azure Secrets Refresh Task";
+ }
+
+ protected void onEventListener(final EventContext eventContext) {
+ final String SECRET_VERSION_ADD = "Microsoft.KeyVault.SecretNewVersionCreated";
+ boolean triggerReloading = false;
+
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode actualObj = null;
+ try {
+ actualObj = mapper.readTree(eventContext.getEventData().getBodyAsString());
+ } catch (JsonMappingException e) {
+ e.printStackTrace();
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+ for (int i = 0; i < actualObj.size(); i++) {
+ String secret = actualObj.get(i).get("subject").textValue();
+ String eventType = actualObj.get(i).get("eventType").textValue();
+ if (ObjectHelper.isNotEmpty(secret) && ObjectHelper.isNotEmpty(eventType)) {
+ if (eventType.equalsIgnoreCase(SECRET_VERSION_ADD)) {
+ if (matchSecret(secret)) {
+ if (isReloadEnabled()) {
+ LOG.info("Update for Azure secret: {} detected, triggering CamelContext reload", secret);
+ triggerReloading = true;
+ }
+ }
+ }
+ }
+ }
+ if (triggerReloading) {
+ ContextReloadStrategy reload = camelContext.hasService(ContextReloadStrategy.class);
+ if (reload != null) {
+ // trigger reload
+ reload.onReload(this);
+ }
+ }
+ }
+
+ public void onErrorListener(final ErrorContext errorContext) {
+ //NOOP
+ }
+}
diff --git a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultPropertiesFunction.java b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultPropertiesFunction.java
index 8c3b91c89e9..80cea5ab033 100644
--- a/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultPropertiesFunction.java
+++ b/components/camel-azure/camel-azure-key-vault/src/main/java/org/apache/camel/component/azure/key/vault/KeyVaultPropertiesFunction.java
@@ -25,6 +25,10 @@ import com.azure.security.keyvault.secrets.models.KeyVaultSecret;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.HashSet;
+import java.util.Set;
+
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.RuntimeCamelException;
@@ -77,6 +81,7 @@ public class KeyVaultPropertiesFunction extends ServiceSupport implements Proper
private static final String CAMEL_VAULT_AZURE_TENANT_ID = "CAMEL_VAULT_AZURE_TENANT_ID";
private CamelContext camelContext;
private SecretClient client;
+ private final Set<String> secrets = new HashSet<>();
@Override
protected void doStart() throws Exception {
@@ -116,6 +121,12 @@ public class KeyVaultPropertiesFunction extends ServiceSupport implements Proper
"Using the Azure Key Vault Properties Function requires setting Azure credentials as application properties or environment variables");
}
}
+
+ @Override
+ protected void doStop() throws Exception {
+ secrets.clear();
+ super.doStop();
+ }
@Override
public String getName() {
@@ -175,6 +186,10 @@ public class KeyVaultPropertiesFunction extends ServiceSupport implements Proper
String key, String subkey, String defaultValue, String version)
throws JsonProcessingException {
String returnValue;
+
+ // capture name of secret
+ secrets.add(key);
+
try {
KeyVaultSecret secret = client.getSecret(key, ObjectHelper.isNotEmpty(version) ? version : "");
returnValue = secret.getValue();
@@ -210,4 +225,11 @@ public class KeyVaultPropertiesFunction extends ServiceSupport implements Proper
public CamelContext getCamelContext() {
return camelContext;
}
+
+ /**
+ * Ids of the secrets in use
+ */
+ public Set<String> getSecrets() {
+ return secrets;
+ }
}
diff --git a/core/camel-api/src/main/java/org/apache/camel/vault/AzureVaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/AzureVaultConfiguration.java
index 33ed8ab8164..91e82bcbb2a 100644
--- a/core/camel-api/src/main/java/org/apache/camel/vault/AzureVaultConfiguration.java
+++ b/core/camel-api/src/main/java/org/apache/camel/vault/AzureVaultConfiguration.java
@@ -31,6 +31,20 @@ public class AzureVaultConfiguration extends VaultConfiguration {
private String clientSecret;
@Metadata(secret = true)
private String tenantId;
+ @Metadata
+ private boolean refreshEnabled;
+ @Metadata(defaultValue = "30000")
+ private long refreshPeriod = 30000;
+ @Metadata
+ private String secrets;
+ @Metadata(secret = true)
+ private String eventhubConnectionString;
+ @Metadata(secret = true)
+ private String blobAccessKey;
+ @Metadata
+ private String blobAccountName;
+ @Metadata
+ private String blobContainerName;
public String getVaultName() {
return vaultName;
@@ -75,4 +89,81 @@ public class AzureVaultConfiguration extends VaultConfiguration {
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
+
+ public boolean isRefreshEnabled() {
+ return refreshEnabled;
+ }
+
+ /**
+ * Whether to automatically reload Camel upon secrets being updated in Azure.
+ */
+ public void setRefreshEnabled(boolean refreshEnabled) {
+ this.refreshEnabled = refreshEnabled;
+ }
+
+ public long getRefreshPeriod() {
+ return refreshPeriod;
+ }
+
+ /**
+ * The period (millis) between checking Azure for updated secrets.
+ */
+ public void setRefreshPeriod(long refreshPeriod) {
+ this.refreshPeriod = refreshPeriod;
+ }
+
+ public String getSecrets() {
+ return secrets;
+ }
+
+ /**
+ * Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma.
+ */
+ public void setSecrets(String secrets) {
+ this.secrets = secrets;
+ }
+
+ public String getEventhubConnectionString() {
+ return eventhubConnectionString;
+ }
+
+ /**
+ * The Eventhubs connection String for Key Vault Secret events notifications
+ */
+ public void setEventhubConnectionString(String eventhubConnectionString) {
+ this.eventhubConnectionString = eventhubConnectionString;
+ }
+
+ public String getBlobAccessKey() {
+ return blobAccessKey;
+ }
+
+ /**
+ * The Eventhubs Blob Access Key for CheckpointStore purpose
+ */
+ public void setBlobAccessKey(String blobAccessKey) {
+ this.blobAccessKey = blobAccessKey;
+ }
+
+ public String getBlobAccountName() {
+ return blobAccountName;
+ }
+
+ /**
+ * The Eventhubs Blob Account Name for CheckpointStore purpose
+ */
+ public void setBlobAccountName(String blobAccountName) {
+ this.blobAccountName = blobAccountName;
+ }
+
+ public String getBlobContainerName() {
+ return blobContainerName;
+ }
+
+ /**
+ * The Eventhubs Blob Container Name for CheckpointStore purpose
+ */
+ public void setBlobContainerName(String blobContainerName) {
+ this.blobContainerName = blobContainerName;
+ }
}
diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/AzureVaultConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/AzureVaultConfigurationPropertiesConfigurer.java
index 976b171168e..cafee650316 100644
--- a/core/camel-main/src/generated/java/org/apache/camel/main/AzureVaultConfigurationPropertiesConfigurer.java
+++ b/core/camel-main/src/generated/java/org/apache/camel/main/AzureVaultConfigurationPropertiesConfigurer.java
@@ -25,14 +25,28 @@ public class AzureVaultConfigurationPropertiesConfigurer extends org.apache.came
case "AwsVaultConfiguration": target.setAwsVaultConfiguration(property(camelContext, org.apache.camel.vault.AwsVaultConfiguration.class, value)); return true;
case "azurevaultconfiguration":
case "AzureVaultConfiguration": target.setAzureVaultConfiguration(property(camelContext, org.apache.camel.vault.AzureVaultConfiguration.class, value)); return true;
+ case "blobaccesskey":
+ case "BlobAccessKey": target.setBlobAccessKey(property(camelContext, java.lang.String.class, value)); return true;
+ case "blobaccountname":
+ case "BlobAccountName": target.setBlobAccountName(property(camelContext, java.lang.String.class, value)); return true;
+ case "blobcontainername":
+ case "BlobContainerName": target.setBlobContainerName(property(camelContext, java.lang.String.class, value)); return true;
case "clientid":
case "ClientId": target.setClientId(property(camelContext, java.lang.String.class, value)); return true;
case "clientsecret":
case "ClientSecret": target.setClientSecret(property(camelContext, java.lang.String.class, value)); return true;
+ case "eventhubconnectionstring":
+ case "EventhubConnectionString": target.setEventhubConnectionString(property(camelContext, java.lang.String.class, value)); return true;
case "gcpvaultconfiguration":
case "GcpVaultConfiguration": target.setGcpVaultConfiguration(property(camelContext, org.apache.camel.vault.GcpVaultConfiguration.class, value)); return true;
case "hashicorpvaultconfiguration":
case "HashicorpVaultConfiguration": target.setHashicorpVaultConfiguration(property(camelContext, org.apache.camel.vault.HashicorpVaultConfiguration.class, value)); return true;
+ case "refreshenabled":
+ case "RefreshEnabled": target.setRefreshEnabled(property(camelContext, boolean.class, value)); return true;
+ case "refreshperiod":
+ case "RefreshPeriod": target.setRefreshPeriod(property(camelContext, long.class, value)); return true;
+ case "secrets":
+ case "Secrets": target.setSecrets(property(camelContext, java.lang.String.class, value)); return true;
case "tenantid":
case "TenantId": target.setTenantId(property(camelContext, java.lang.String.class, value)); return true;
case "vaultname":
@@ -48,14 +62,28 @@ public class AzureVaultConfigurationPropertiesConfigurer extends org.apache.came
case "AwsVaultConfiguration": return org.apache.camel.vault.AwsVaultConfiguration.class;
case "azurevaultconfiguration":
case "AzureVaultConfiguration": return org.apache.camel.vault.AzureVaultConfiguration.class;
+ case "blobaccesskey":
+ case "BlobAccessKey": return java.lang.String.class;
+ case "blobaccountname":
+ case "BlobAccountName": return java.lang.String.class;
+ case "blobcontainername":
+ case "BlobContainerName": return java.lang.String.class;
case "clientid":
case "ClientId": return java.lang.String.class;
case "clientsecret":
case "ClientSecret": return java.lang.String.class;
+ case "eventhubconnectionstring":
+ case "EventhubConnectionString": return java.lang.String.class;
case "gcpvaultconfiguration":
case "GcpVaultConfiguration": return org.apache.camel.vault.GcpVaultConfiguration.class;
case "hashicorpvaultconfiguration":
case "HashicorpVaultConfiguration": return org.apache.camel.vault.HashicorpVaultConfiguration.class;
+ case "refreshenabled":
+ case "RefreshEnabled": return boolean.class;
+ case "refreshperiod":
+ case "RefreshPeriod": return long.class;
+ case "secrets":
+ case "Secrets": return java.lang.String.class;
case "tenantid":
case "TenantId": return java.lang.String.class;
case "vaultname":
@@ -72,14 +100,28 @@ public class AzureVaultConfigurationPropertiesConfigurer extends org.apache.came
case "AwsVaultConfiguration": return target.getAwsVaultConfiguration();
case "azurevaultconfiguration":
case "AzureVaultConfiguration": return target.getAzureVaultConfiguration();
+ case "blobaccesskey":
+ case "BlobAccessKey": return target.getBlobAccessKey();
+ case "blobaccountname":
+ case "BlobAccountName": return target.getBlobAccountName();
+ case "blobcontainername":
+ case "BlobContainerName": return target.getBlobContainerName();
case "clientid":
case "ClientId": return target.getClientId();
case "clientsecret":
case "ClientSecret": return target.getClientSecret();
+ case "eventhubconnectionstring":
+ case "EventhubConnectionString": return target.getEventhubConnectionString();
case "gcpvaultconfiguration":
case "GcpVaultConfiguration": return target.getGcpVaultConfiguration();
case "hashicorpvaultconfiguration":
case "HashicorpVaultConfiguration": return target.getHashicorpVaultConfiguration();
+ case "refreshenabled":
+ case "RefreshEnabled": return target.isRefreshEnabled();
+ case "refreshperiod":
+ case "RefreshPeriod": return target.getRefreshPeriod();
+ case "secrets":
+ case "Secrets": return target.getSecrets();
case "tenantid":
case "TenantId": return target.getTenantId();
case "vaultname":
diff --git a/core/camel-main/src/generated/java/org/apache/camel/vault/AzureVaultConfigurationConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/vault/AzureVaultConfigurationConfigurer.java
index 9d59a46c478..de815ca031d 100644
--- a/core/camel-main/src/generated/java/org/apache/camel/vault/AzureVaultConfigurationConfigurer.java
+++ b/core/camel-main/src/generated/java/org/apache/camel/vault/AzureVaultConfigurationConfigurer.java
@@ -25,14 +25,28 @@ public class AzureVaultConfigurationConfigurer extends org.apache.camel.support.
case "AwsVaultConfiguration": target.setAwsVaultConfiguration(property(camelContext, org.apache.camel.vault.AwsVaultConfiguration.class, value)); return true;
case "azurevaultconfiguration":
case "AzureVaultConfiguration": target.setAzureVaultConfiguration(property(camelContext, org.apache.camel.vault.AzureVaultConfiguration.class, value)); return true;
+ case "blobaccesskey":
+ case "BlobAccessKey": target.setBlobAccessKey(property(camelContext, java.lang.String.class, value)); return true;
+ case "blobaccountname":
+ case "BlobAccountName": target.setBlobAccountName(property(camelContext, java.lang.String.class, value)); return true;
+ case "blobcontainername":
+ case "BlobContainerName": target.setBlobContainerName(property(camelContext, java.lang.String.class, value)); return true;
case "clientid":
case "ClientId": target.setClientId(property(camelContext, java.lang.String.class, value)); return true;
case "clientsecret":
case "ClientSecret": target.setClientSecret(property(camelContext, java.lang.String.class, value)); return true;
+ case "eventhubconnectionstring":
+ case "EventhubConnectionString": target.setEventhubConnectionString(property(camelContext, java.lang.String.class, value)); return true;
case "gcpvaultconfiguration":
case "GcpVaultConfiguration": target.setGcpVaultConfiguration(property(camelContext, org.apache.camel.vault.GcpVaultConfiguration.class, value)); return true;
case "hashicorpvaultconfiguration":
case "HashicorpVaultConfiguration": target.setHashicorpVaultConfiguration(property(camelContext, org.apache.camel.vault.HashicorpVaultConfiguration.class, value)); return true;
+ case "refreshenabled":
+ case "RefreshEnabled": target.setRefreshEnabled(property(camelContext, boolean.class, value)); return true;
+ case "refreshperiod":
+ case "RefreshPeriod": target.setRefreshPeriod(property(camelContext, long.class, value)); return true;
+ case "secrets":
+ case "Secrets": target.setSecrets(property(camelContext, java.lang.String.class, value)); return true;
case "tenantid":
case "TenantId": target.setTenantId(property(camelContext, java.lang.String.class, value)); return true;
case "vaultname":
@@ -48,14 +62,28 @@ public class AzureVaultConfigurationConfigurer extends org.apache.camel.support.
case "AwsVaultConfiguration": return org.apache.camel.vault.AwsVaultConfiguration.class;
case "azurevaultconfiguration":
case "AzureVaultConfiguration": return org.apache.camel.vault.AzureVaultConfiguration.class;
+ case "blobaccesskey":
+ case "BlobAccessKey": return java.lang.String.class;
+ case "blobaccountname":
+ case "BlobAccountName": return java.lang.String.class;
+ case "blobcontainername":
+ case "BlobContainerName": return java.lang.String.class;
case "clientid":
case "ClientId": return java.lang.String.class;
case "clientsecret":
case "ClientSecret": return java.lang.String.class;
+ case "eventhubconnectionstring":
+ case "EventhubConnectionString": return java.lang.String.class;
case "gcpvaultconfiguration":
case "GcpVaultConfiguration": return org.apache.camel.vault.GcpVaultConfiguration.class;
case "hashicorpvaultconfiguration":
case "HashicorpVaultConfiguration": return org.apache.camel.vault.HashicorpVaultConfiguration.class;
+ case "refreshenabled":
+ case "RefreshEnabled": return boolean.class;
+ case "refreshperiod":
+ case "RefreshPeriod": return long.class;
+ case "secrets":
+ case "Secrets": return java.lang.String.class;
case "tenantid":
case "TenantId": return java.lang.String.class;
case "vaultname":
@@ -72,14 +100,28 @@ public class AzureVaultConfigurationConfigurer extends org.apache.camel.support.
case "AwsVaultConfiguration": return target.getAwsVaultConfiguration();
case "azurevaultconfiguration":
case "AzureVaultConfiguration": return target.getAzureVaultConfiguration();
+ case "blobaccesskey":
+ case "BlobAccessKey": return target.getBlobAccessKey();
+ case "blobaccountname":
+ case "BlobAccountName": return target.getBlobAccountName();
+ case "blobcontainername":
+ case "BlobContainerName": return target.getBlobContainerName();
case "clientid":
case "ClientId": return target.getClientId();
case "clientsecret":
case "ClientSecret": return target.getClientSecret();
+ case "eventhubconnectionstring":
+ case "EventhubConnectionString": return target.getEventhubConnectionString();
case "gcpvaultconfiguration":
case "GcpVaultConfiguration": return target.getGcpVaultConfiguration();
case "hashicorpvaultconfiguration":
case "HashicorpVaultConfiguration": return target.getHashicorpVaultConfiguration();
+ case "refreshenabled":
+ case "RefreshEnabled": return target.isRefreshEnabled();
+ case "refreshperiod":
+ case "RefreshPeriod": return target.getRefreshPeriod();
+ case "secrets":
+ case "Secrets": return target.getSecrets();
case "tenantid":
case "TenantId": return target.getTenantId();
case "vaultname":
diff --git a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 326888ac898..efd1b33060a 100644
--- a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -214,8 +214,15 @@
{ "name": "camel.vault.aws.region", "description": "The AWS region", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.aws.secretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.aws.secrets", "description": "Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma.", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.blobAccessKey", "description": "The Eventhubs Blob Access Key for CheckpointStore purpose", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.blobAccountName", "description": "The Eventhubs Blob Account Name for CheckpointStore purpose", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.blobContainerName", "description": "The Eventhubs Blob Container Name for CheckpointStore purpose", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.azure.clientId", "description": "The client Id for accessing Azure Key Vault", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.azure.clientSecret", "description": "The client Secret for accessing Azure Key Vault", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.eventhubConnectionString", "description": "The Eventhubs connection String for Key Vault Secret events notifications", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.azure.refreshEnabled", "description": "Whether to automatically reload Camel upon secrets being updated in Azure.", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
+ { "name": "camel.vault.azure.refreshPeriod", "description": "The period (millis) between checking Azure for updated secrets.", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "integer", "javaType": "long", "defaultValue": 30000 },
+ { "name": "camel.vault.azure.secrets", "description": "Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma.", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.azure.tenantId", "description": "The Tenant Id for accessing Azure Key Vault", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.azure.vaultName", "description": "The vault Name in Azure Key Vault", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.gcp.projectId", "description": "The GCP Project ID", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc
index 73171822dff..7bc34ab33c3 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -238,13 +238,20 @@ The camel.vault.gcp supports 7 options, which are listed below.
|===
=== Camel Azure Key Vault configurations
-The camel.vault.azure supports 4 options, which are listed below.
+The camel.vault.azure supports 11 options, which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
+| *camel.vault.azure.blobAccess{zwsp}Key* | The Eventhubs Blob Access Key for CheckpointStore purpose | | String
+| *camel.vault.azure.blobAccount{zwsp}Name* | The Eventhubs Blob Account Name for CheckpointStore purpose | | String
+| *camel.vault.azure.blob{zwsp}ContainerName* | The Eventhubs Blob Container Name for CheckpointStore purpose | | String
| *camel.vault.azure.clientId* | The client Id for accessing Azure Key Vault | | String
| *camel.vault.azure.clientSecret* | The client Secret for accessing Azure Key Vault | | String
+| *camel.vault.azure.eventhub{zwsp}ConnectionString* | The Eventhubs connection String for Key Vault Secret events notifications | | String
+| *camel.vault.azure.refresh{zwsp}Enabled* | Whether to automatically reload Camel upon secrets being updated in Azure. | false | boolean
+| *camel.vault.azure.refresh{zwsp}Period* | The period (millis) between checking Azure for updated secrets. | 30000 | long
+| *camel.vault.azure.secrets* | Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma. | | String
| *camel.vault.azure.tenantId* | The Tenant Id for accessing Azure Key Vault | | String
| *camel.vault.azure.vaultName* | The vault Name in Azure Key Vault | | String
|===
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/AzureVaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/AzureVaultConfigurationProperties.java
index 23d4c0ba4bd..1eebc2df0d2 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/AzureVaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/AzureVaultConfigurationProperties.java
@@ -72,7 +72,7 @@ public class AzureVaultConfigurationProperties extends AzureVaultConfiguration i
setClientSecret(clientSecret);
return this;
}
-
+
/**
* The Azure Key Vault Tenant Id
*/
@@ -81,4 +81,60 @@ public class AzureVaultConfigurationProperties extends AzureVaultConfiguration i
return this;
}
+ /**
+ * Whether to automatically reload Camel upon secrets being updated in Azure.
+ */
+ public AzureVaultConfigurationProperties withRefreshEnabled(boolean refreshEnabled) {
+ setRefreshEnabled(refreshEnabled);
+ return this;
+ }
+
+ /**
+ * The period (millis) between checking Azure for updated secrets.
+ */
+ public AzureVaultConfigurationProperties withRefreshPeriod(long refreshPeriod) {
+ setRefreshPeriod(refreshPeriod);
+ return this;
+ }
+
+ /**
+ * Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma.
+ */
+ public AzureVaultConfigurationProperties withSecrets(String secrets) {
+ setSecrets(secrets);
+ return this;
+ }
+
+ /**
+ * The Azure Eventhub connection String for Key Vault Event notification
+ */
+ public AzureVaultConfigurationProperties withEventhubConnectionString(String connectionString) {
+ setEventhubConnectionString(connectionString);
+ return this;
+ }
+
+ /**
+ * The Azure Eventhub Blob Access Key for Checkpoint Store purpose
+ */
+ public AzureVaultConfigurationProperties withBlobAccessKey(String accessKey) {
+ setBlobAccessKey(accessKey);
+ return this;
+ }
+
+ /**
+ * The Azure Eventhub Blob Account Name for Checkpoint Store purpose
+ */
+ public AzureVaultConfigurationProperties withBlobAccountName(String accountName) {
+ setBlobAccountName(accountName);
+ return this;
+ }
+
+
+ /**
+ * The Azure Eventhub Blob Container Name for Checkpoint Store purpose
+ */
+ public AzureVaultConfigurationProperties withBlobContainerName(String containerName) {
+ setBlobContainerName(containerName);
+ return this;
+ }
}
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 7a6fc43a4f6..a20a37d4723 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -433,6 +433,25 @@ public abstract class BaseMainSupport extends BaseService {
scheduler.schedulePeriodTask(r, period);
}
}
+
+ if (vc.azure().isRefreshEnabled()) {
+ Optional<Runnable> task = camelContext.adapt(ExtendedCamelContext.class)
+ .getPeriodTaskResolver().newInstance("azure-secret-refresh", Runnable.class);
+ if (task.isPresent()) {
+ long period = vc.azure().getRefreshPeriod();
+ Runnable r = task.get();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Scheduling: {} (period: {})", r, TimeUtils.printDuration(period, false));
+ }
+ if (camelContext.hasService(ContextReloadStrategy.class) == null) {
+ // refresh is enabled then we need to automatically enable context-reload as well
+ ContextReloadStrategy reloader = new DefaultContextReloadStrategy();
+ camelContext.addService(reloader);
+ }
+ PeriodTaskScheduler scheduler = getCamelContext().adapt(ExtendedCamelContext.class).getPeriodTaskScheduler();
+ scheduler.schedulePeriodTask(r, period);
+ }
+ }
}
protected void autoconfigure(CamelContext camelContext) throws Exception {