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/13 12:07:57 UTC
[camel] branch main updated (b0339a00640 -> 6726c4e0a3e)
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from b0339a00640 Polished
new caad006641d CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
new dc043fe9e0f CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
new 6b6bd28e08c CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
new 6726c4e0a3e CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../main/camel-main-configuration-metadata.json | 4 +
.../camel-google-secret-manager/pom.xml | 17 ++
.../apache/camel/periodic-task/gcp-secret-refresh | 2 +
.../GoogleSecretManagerPropertiesFunction.java | 15 ++
.../manager/vault/PubsubReloadTriggerTask.java | 231 +++++++++++++++++++++
.../apache/camel/vault/GcpVaultConfiguration.java | 51 +++++
.../GcpVaultConfigurationPropertiesConfigurer.java | 24 +++
.../vault/GcpVaultConfigurationConfigurer.java | 24 +++
.../camel-main-configuration-metadata.json | 4 +
core/camel-main/src/main/docs/main.adoc | 6 +-
.../org/apache/camel/main/BaseMainSupport.java | 19 ++
.../main/GcpVaultConfigurationProperties.java | 32 +++
12 files changed, 428 insertions(+), 1 deletion(-)
create mode 100644 components/camel-google/camel-google-secret-manager/src/generated/resources/META-INF/services/org/apache/camel/periodic-task/gcp-secret-refresh
create mode 100644 components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
[camel] 01/04: CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
Posted by ac...@apache.org.
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 caad006641d855c89e71e810186a77620ddb5c7d
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Sep 13 08:45:13 2022 +0200
CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
---
.../camel-google-secret-manager/pom.xml | 17 ++
.../GoogleSecretManagerPropertiesFunction.java | 15 ++
.../manager/vault/PubsubReloadTriggerTask.java | 232 +++++++++++++++++++++
.../apache/camel/vault/GcpVaultConfiguration.java | 52 +++++
.../org/apache/camel/main/BaseMainSupport.java | 19 ++
.../main/GcpVaultConfigurationProperties.java | 32 +++
6 files changed, 367 insertions(+)
diff --git a/components/camel-google/camel-google-secret-manager/pom.xml b/components/camel-google/camel-google-secret-manager/pom.xml
index 6c0d0eebaa8..ea378bec96b 100644
--- a/components/camel-google/camel-google-secret-manager/pom.xml
+++ b/components/camel-google/camel-google-secret-manager/pom.xml
@@ -52,6 +52,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>com.google.cloud</groupId>
+ <artifactId>libraries-bom</artifactId>
+ <version>${google-cloud-bom-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -82,6 +89,16 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>com.google.cloud</groupId>
+ <artifactId>google-cloud-pubsub</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
diff --git a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
index 06f79815fdb..7576aad827e 100644
--- a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
+++ b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
@@ -17,6 +17,8 @@
package org.apache.camel.component.google.secret.manager;
import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
@@ -79,6 +81,7 @@ public class GoogleSecretManagerPropertiesFunction extends ServiceSupport implem
private CamelContext camelContext;
private SecretManagerServiceClient client;
private String projectId;
+ private final Set<String> secrets = new HashSet<>();
@Override
protected void doStart() throws Exception {
@@ -116,6 +119,7 @@ public class GoogleSecretManagerPropertiesFunction extends ServiceSupport implem
if (client != null) {
client.close();
}
+ secrets.clear();
super.doStop();
}
@@ -176,6 +180,10 @@ public class GoogleSecretManagerPropertiesFunction extends ServiceSupport implem
private String getSecretFromSource(
String key, String subkey, String defaultValue, String version)
throws JsonProcessingException {
+
+ // capture name of secret
+ secrets.add(key);
+
String returnValue = null;
try {
SecretVersionName secretVersionName
@@ -216,4 +224,11 @@ public class GoogleSecretManagerPropertiesFunction extends ServiceSupport implem
public CamelContext getCamelContext() {
return camelContext;
}
+
+ /**
+ * Ids of the secrets in use
+ */
+ public Set<String> getSecrets() {
+ return secrets;
+ }
}
diff --git a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
new file mode 100644
index 00000000000..7088f6284b0
--- /dev/null
+++ b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
@@ -0,0 +1,232 @@
+/*
+ * 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.google.secret.manager.vault;
+
+import java.io.InputStream;
+import java.time.Instant;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+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.component.google.secret.manager.GoogleSecretManagerPropertiesFunction;
+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.ResourceHelper;
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.vault.GcpVaultConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.api.gax.core.FixedCredentialsProvider;
+import com.google.auth.Credentials;
+import com.google.auth.oauth2.GoogleCredentials;
+import com.google.auth.oauth2.ServiceAccountCredentials;
+import com.google.cloud.pubsub.v1.AckReplyConsumer;
+import com.google.cloud.pubsub.v1.MessageReceiver;
+import com.google.cloud.pubsub.v1.Subscriber;
+import com.google.pubsub.v1.ProjectSubscriptionName;
+import com.google.pubsub.v1.PubsubMessage;
+
+/**
+ * Period task which checks if Google secrets has been updated and can trigger Camel to be reloaded.
+ */
+@PeriodicTask("gcp-secret-refresh")
+public class PubsubReloadTriggerTask extends ServiceSupport implements CamelContextAware, Runnable {
+
+ private static final String CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY";
+ private static final String CAMEL_VAULT_GCP_PROJECT_ID = "CAMEL_VAULT_GCP_PROJECT_ID";
+ private static final String CAMEL_VAULT_GCP_USE_DEFAULT_INSTANCE = "CAMEL_VAULT_GCP_USE_DEFAULT_INSTANCE";
+
+ private static final Logger LOG = LoggerFactory.getLogger(PubsubReloadTriggerTask.class);
+
+ private CamelContext camelContext;
+ private boolean reloadEnabled = true;
+ private String secrets;
+ private Subscriber subscriber;
+ private GoogleSecretManagerPropertiesFunction propertiesFunction;
+ private final Map<String, Instant> updates = new HashMap<>();
+
+ public PubsubReloadTriggerTask() {
+ }
+
+ @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 AWS 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("gcp");
+ if (pf instanceof GoogleSecretManagerPropertiesFunction) {
+ propertiesFunction = (GoogleSecretManagerPropertiesFunction) pf;
+ LOG.debug("Auto-detecting secrets from properties-function: {}", pf.getName());
+ }
+ // specific secrets
+ secrets = camelContext.getVaultConfiguration().aws().getSecrets();
+ if (ObjectHelper.isEmpty(secrets) && propertiesFunction == null) {
+ throw new IllegalArgumentException("Secrets must be configured on GCP vault configuration");
+ }
+
+ String serviceAccountKey = System.getenv(CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY);
+ boolean useDefaultInstance = Boolean.parseBoolean(System.getenv(CAMEL_VAULT_GCP_USE_DEFAULT_INSTANCE));
+ String projectId = System.getenv(CAMEL_VAULT_GCP_PROJECT_ID);
+ String subscription = null;
+ if (ObjectHelper.isEmpty(serviceAccountKey) && ObjectHelper.isEmpty(projectId)) {
+ GcpVaultConfiguration gcpVaultConfiguration = getCamelContext().getVaultConfiguration().gcp();
+ if (ObjectHelper.isNotEmpty(gcpVaultConfiguration)) {
+ serviceAccountKey = gcpVaultConfiguration.getServiceAccountKey();
+ projectId = gcpVaultConfiguration.getProjectId();
+ useDefaultInstance = gcpVaultConfiguration.isUseDefaultInstance();
+ }
+ }
+ if (ObjectHelper.isNotEmpty(serviceAccountKey) && ObjectHelper.isNotEmpty(projectId)) {
+ InputStream resolveMandatoryResourceAsInputStream
+ = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), serviceAccountKey);
+ Credentials myCredentials = ServiceAccountCredentials
+ .fromStream(resolveMandatoryResourceAsInputStream);
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscription);
+ Subscriber.Builder builder = Subscriber.newBuilder(subscriptionName, new FilteringEventMessageReceiver());
+ builder.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials));
+ subscriber = builder.build();
+ } else if (useDefaultInstance && ObjectHelper.isNotEmpty(projectId)) {
+ ProjectSubscriptionName subscriptionName =
+ ProjectSubscriptionName.of(projectId, subscription);
+ Subscriber.Builder builder = Subscriber.newBuilder(subscriptionName, new FilteringEventMessageReceiver());
+ builder.setCredentialsProvider(FixedCredentialsProvider.create(GoogleCredentials.getApplicationDefault()));
+ subscriber = builder.build();
+ } else {
+ throw new RuntimeCamelException(
+ "Using the GCP Secret Manager Properties Function requires setting GCP service account key and project Id as application properties or environment variables");
+ }
+ }
+
+ @Override
+ protected void doShutdown() throws Exception {
+ super.doShutdown();
+
+ if (subscriber != null) {
+ try {
+ subscriber.stopAsync();
+ } catch (Exception e) {
+ // ignore
+ }
+ subscriber = null;
+ }
+
+ updates.clear();
+ }
+
+ @Override
+ public void run() {
+ subscriber.startAsync().awaitRunning();
+ subscriber.awaitTerminated();
+ }
+
+ 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 "Google Secrets Refresh Task";
+ }
+
+ public class FilteringEventMessageReceiver implements MessageReceiver {
+
+ private static String SECRET_UPDATE = "SECRET_UPDATE";
+ private static String SECRET_VERSION_ADD = "SECRET_VERSION_ADD";
+
+ private boolean triggerReloading;
+
+ @Override
+ public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
+ String secretId = message.getAttributesMap().get("secretId");
+ String eventType = message.getAttributesMap().get("eventType");
+ if (eventType.equalsIgnoreCase(SECRET_UPDATE) || eventType.equalsIgnoreCase(SECRET_VERSION_ADD)) {
+ if (matchSecret(secretId)) {
+ if (isReloadEnabled()) {
+ LOG.info("Update for AWS secret: {} detected, triggering CamelContext reload", secretId);
+ triggerReloading = true;
+ }
+ }
+ }
+ if (triggerReloading) {
+ ContextReloadStrategy reload = camelContext.hasService(ContextReloadStrategy.class);
+ if (reload != null) {
+ // trigger reload
+ reload.onReload(this);
+ }
+ }
+ consumer.ack();
+
+ }
+
+ }
+}
diff --git a/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
index bc50bcf6538..15793eab1fb 100644
--- a/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
+++ b/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
@@ -29,6 +29,14 @@ public class GcpVaultConfiguration extends VaultConfiguration {
private String projectId;
@Metadata
private boolean useDefaultInstance;
+ @Metadata
+ private String subscriptionName;
+ @Metadata
+ private boolean refreshEnabled;
+ @Metadata(defaultValue = "30000")
+ private long refreshPeriod = 30000;
+ @Metadata
+ private String secrets;
public String getServiceAccountKey() {
return serviceAccountKey;
@@ -63,4 +71,48 @@ public class GcpVaultConfiguration extends VaultConfiguration {
this.useDefaultInstance = useDefaultInstance;
}
+ public String getSubscriptionName() {
+ return subscriptionName;
+ }
+
+ /**
+ * Define the Google Pubsub subscription Name to be used when checking for updates
+ */
+ public void setSubscriptionName(String subscriptionName) {
+ this.subscriptionName = subscriptionName;
+ }
+
+
+ public boolean isRefreshEnabled() {
+ return refreshEnabled;
+ }
+
+ /**
+ * Whether to automatically reload Camel upon secrets being updated in AWS.
+ */
+ public void setRefreshEnabled(boolean refreshEnabled) {
+ this.refreshEnabled = refreshEnabled;
+ }
+
+ public long getRefreshPeriod() {
+ return refreshPeriod;
+ }
+
+ /**
+ * The period (millis) between checking Google 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;
+ }
}
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 a388a797e96..def6eee6a5c 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
@@ -414,6 +414,25 @@ public abstract class BaseMainSupport extends BaseService {
scheduler.schedulePeriodTask(r, period);
}
}
+
+ if (vc.gcp().isRefreshEnabled()) {
+ Optional<Runnable> task = camelContext.adapt(ExtendedCamelContext.class)
+ .getPeriodTaskResolver().newInstance("gcp-secret-refresh", Runnable.class);
+ if (task.isPresent()) {
+ long period = vc.aws().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 {
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
index f4412918e21..c91d796d89d 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
@@ -72,5 +72,37 @@ public class GcpVaultConfigurationProperties extends GcpVaultConfiguration imple
setUseDefaultInstance(useDefaultInstance);
return this;
}
+
+ /**
+ * The Pubsub subscriptionName name
+ */
+ public GcpVaultConfigurationProperties withSubscriptionName(String subscriptionName) {
+ setSubscriptionName(subscriptionName);
+ return this;
+ }
+
+ /**
+ * Whether to automatically reload Camel upon secrets being updated in Google.
+ */
+ public GcpVaultConfigurationProperties withRefreshEnabled(boolean refreshEnabled) {
+ setRefreshEnabled(refreshEnabled);
+ return this;
+ }
+
+ /**
+ * The period (millis) between checking Google for updated secrets.
+ */
+ public GcpVaultConfigurationProperties 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 GcpVaultConfigurationProperties withSecrets(String secrets) {
+ setSecrets(secrets);
+ return this;
+ }
}
[camel] 02/04: CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
Posted by ac...@apache.org.
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 dc043fe9e0f80de8bbc179b02163a5c586688558
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Sep 13 12:00:12 2022 +0200
CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../main/camel-main-configuration-metadata.json | 4 ++++
.../apache/camel/periodic-task/gcp-secret-refresh | 2 ++
.../manager/vault/PubsubReloadTriggerTask.java | 17 +++++++--------
.../GcpVaultConfigurationPropertiesConfigurer.java | 24 ++++++++++++++++++++++
.../vault/GcpVaultConfigurationConfigurer.java | 24 ++++++++++++++++++++++
.../camel-main-configuration-metadata.json | 4 ++++
core/camel-main/src/main/docs/main.adoc | 6 +++++-
7 files changed, 72 insertions(+), 9 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 895849bf2e0..244dd57d7c9 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
@@ -218,7 +218,11 @@
{ "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" },
+ { "name": "camel.vault.gcp.refreshEnabled", "description": "Whether to automatically reload Camel upon secrets being updated in AWS.", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
+ { "name": "camel.vault.gcp.refreshPeriod", "description": "The period (millis) between checking Google for updated secrets.", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "integer", "javaType": "long", "defaultValue": 30000 },
+ { "name": "camel.vault.gcp.secrets", "description": "Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma.", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.gcp.serviceAccountKey", "description": "The Service Account Key location", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.gcp.subscriptionName", "description": "Define the Google Pubsub subscription Name to be used when checking for updates", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.gcp.useDefaultInstance", "description": "Define if we want to use the GCP Client Default Instance or not", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }
]
}
diff --git a/components/camel-google/camel-google-secret-manager/src/generated/resources/META-INF/services/org/apache/camel/periodic-task/gcp-secret-refresh b/components/camel-google/camel-google-secret-manager/src/generated/resources/META-INF/services/org/apache/camel/periodic-task/gcp-secret-refresh
new file mode 100644
index 00000000000..97807c0935d
--- /dev/null
+++ b/components/camel-google/camel-google-secret-manager/src/generated/resources/META-INF/services/org/apache/camel/periodic-task/gcp-secret-refresh
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.google.secret.manager.vault.PubsubReloadTriggerTask
diff --git a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
index 7088f6284b0..e4a2afd0d13 100644
--- a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
+++ b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
@@ -59,6 +59,7 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
private static final String CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY";
private static final String CAMEL_VAULT_GCP_PROJECT_ID = "CAMEL_VAULT_GCP_PROJECT_ID";
private static final String CAMEL_VAULT_GCP_USE_DEFAULT_INSTANCE = "CAMEL_VAULT_GCP_USE_DEFAULT_INSTANCE";
+ private static final String CAMEL_VAULT_GCP_SUBSCRIPTION_NAME = "CAMEL_VAULT_GCP_SUBSCRIPTION_NAME";
private static final Logger LOG = LoggerFactory.getLogger(PubsubReloadTriggerTask.class);
@@ -120,16 +121,17 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
String serviceAccountKey = System.getenv(CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY);
boolean useDefaultInstance = Boolean.parseBoolean(System.getenv(CAMEL_VAULT_GCP_USE_DEFAULT_INSTANCE));
String projectId = System.getenv(CAMEL_VAULT_GCP_PROJECT_ID);
- String subscription = null;
- if (ObjectHelper.isEmpty(serviceAccountKey) && ObjectHelper.isEmpty(projectId)) {
+ String subscription = System.getenv(CAMEL_VAULT_GCP_SUBSCRIPTION_NAME);
+ if (ObjectHelper.isEmpty(serviceAccountKey) && ObjectHelper.isEmpty(projectId) && ObjectHelper.isEmpty(subscription)) {
GcpVaultConfiguration gcpVaultConfiguration = getCamelContext().getVaultConfiguration().gcp();
if (ObjectHelper.isNotEmpty(gcpVaultConfiguration)) {
serviceAccountKey = gcpVaultConfiguration.getServiceAccountKey();
projectId = gcpVaultConfiguration.getProjectId();
useDefaultInstance = gcpVaultConfiguration.isUseDefaultInstance();
+ subscription = gcpVaultConfiguration.getSubscriptionName();
}
}
- if (ObjectHelper.isNotEmpty(serviceAccountKey) && ObjectHelper.isNotEmpty(projectId)) {
+ if (ObjectHelper.isNotEmpty(serviceAccountKey) && ObjectHelper.isNotEmpty(projectId) && ObjectHelper.isNotEmpty(subscription)) {
InputStream resolveMandatoryResourceAsInputStream
= ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), serviceAccountKey);
Credentials myCredentials = ServiceAccountCredentials
@@ -139,7 +141,7 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
Subscriber.Builder builder = Subscriber.newBuilder(subscriptionName, new FilteringEventMessageReceiver());
builder.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials));
subscriber = builder.build();
- } else if (useDefaultInstance && ObjectHelper.isNotEmpty(projectId)) {
+ } else if (useDefaultInstance && ObjectHelper.isNotEmpty(projectId) && ObjectHelper.isNotEmpty(subscription)) {
ProjectSubscriptionName subscriptionName =
ProjectSubscriptionName.of(projectId, subscription);
Subscriber.Builder builder = Subscriber.newBuilder(subscriptionName, new FilteringEventMessageReceiver());
@@ -147,7 +149,7 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
subscriber = builder.build();
} else {
throw new RuntimeCamelException(
- "Using the GCP Secret Manager Properties Function requires setting GCP service account key and project Id as application properties or environment variables");
+ "Using the GCP Secret refresh task requires setting GCP service account key, project Id and Google Pubsub subscription name as application properties or environment variables");
}
}
@@ -170,7 +172,6 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
@Override
public void run() {
subscriber.startAsync().awaitRunning();
- subscriber.awaitTerminated();
}
protected boolean matchSecret(String name) {
@@ -200,8 +201,8 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
public class FilteringEventMessageReceiver implements MessageReceiver {
- private static String SECRET_UPDATE = "SECRET_UPDATE";
- private static String SECRET_VERSION_ADD = "SECRET_VERSION_ADD";
+ private String SECRET_UPDATE = "SECRET_UPDATE";
+ private String SECRET_VERSION_ADD = "SECRET_VERSION_ADD";
private boolean triggerReloading;
diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/GcpVaultConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/GcpVaultConfigurationPropertiesConfigurer.java
index c8b2deda7e5..c8943f566ca 100644
--- a/core/camel-main/src/generated/java/org/apache/camel/main/GcpVaultConfigurationPropertiesConfigurer.java
+++ b/core/camel-main/src/generated/java/org/apache/camel/main/GcpVaultConfigurationPropertiesConfigurer.java
@@ -31,8 +31,16 @@ public class GcpVaultConfigurationPropertiesConfigurer extends org.apache.camel.
case "HashicorpVaultConfiguration": target.setHashicorpVaultConfiguration(property(camelContext, org.apache.camel.vault.HashicorpVaultConfiguration.class, value)); return true;
case "projectid":
case "ProjectId": target.setProjectId(property(camelContext, java.lang.String.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 "serviceaccountkey":
case "ServiceAccountKey": target.setServiceAccountKey(property(camelContext, java.lang.String.class, value)); return true;
+ case "subscriptionname":
+ case "SubscriptionName": target.setSubscriptionName(property(camelContext, java.lang.String.class, value)); return true;
case "usedefaultinstance":
case "UseDefaultInstance": target.setUseDefaultInstance(property(camelContext, boolean.class, value)); return true;
default: return false;
@@ -52,8 +60,16 @@ public class GcpVaultConfigurationPropertiesConfigurer extends org.apache.camel.
case "HashicorpVaultConfiguration": return org.apache.camel.vault.HashicorpVaultConfiguration.class;
case "projectid":
case "ProjectId": return java.lang.String.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 "serviceaccountkey":
case "ServiceAccountKey": return java.lang.String.class;
+ case "subscriptionname":
+ case "SubscriptionName": return java.lang.String.class;
case "usedefaultinstance":
case "UseDefaultInstance": return boolean.class;
default: return null;
@@ -74,8 +90,16 @@ public class GcpVaultConfigurationPropertiesConfigurer extends org.apache.camel.
case "HashicorpVaultConfiguration": return target.getHashicorpVaultConfiguration();
case "projectid":
case "ProjectId": return target.getProjectId();
+ case "refreshenabled":
+ case "RefreshEnabled": return target.isRefreshEnabled();
+ case "refreshperiod":
+ case "RefreshPeriod": return target.getRefreshPeriod();
+ case "secrets":
+ case "Secrets": return target.getSecrets();
case "serviceaccountkey":
case "ServiceAccountKey": return target.getServiceAccountKey();
+ case "subscriptionname":
+ case "SubscriptionName": return target.getSubscriptionName();
case "usedefaultinstance":
case "UseDefaultInstance": return target.isUseDefaultInstance();
default: return null;
diff --git a/core/camel-main/src/generated/java/org/apache/camel/vault/GcpVaultConfigurationConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/vault/GcpVaultConfigurationConfigurer.java
index 89b1c732cd1..e7e11775ec1 100644
--- a/core/camel-main/src/generated/java/org/apache/camel/vault/GcpVaultConfigurationConfigurer.java
+++ b/core/camel-main/src/generated/java/org/apache/camel/vault/GcpVaultConfigurationConfigurer.java
@@ -31,8 +31,16 @@ public class GcpVaultConfigurationConfigurer extends org.apache.camel.support.co
case "HashicorpVaultConfiguration": target.setHashicorpVaultConfiguration(property(camelContext, org.apache.camel.vault.HashicorpVaultConfiguration.class, value)); return true;
case "projectid":
case "ProjectId": target.setProjectId(property(camelContext, java.lang.String.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 "serviceaccountkey":
case "ServiceAccountKey": target.setServiceAccountKey(property(camelContext, java.lang.String.class, value)); return true;
+ case "subscriptionname":
+ case "SubscriptionName": target.setSubscriptionName(property(camelContext, java.lang.String.class, value)); return true;
case "usedefaultinstance":
case "UseDefaultInstance": target.setUseDefaultInstance(property(camelContext, boolean.class, value)); return true;
default: return false;
@@ -52,8 +60,16 @@ public class GcpVaultConfigurationConfigurer extends org.apache.camel.support.co
case "HashicorpVaultConfiguration": return org.apache.camel.vault.HashicorpVaultConfiguration.class;
case "projectid":
case "ProjectId": return java.lang.String.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 "serviceaccountkey":
case "ServiceAccountKey": return java.lang.String.class;
+ case "subscriptionname":
+ case "SubscriptionName": return java.lang.String.class;
case "usedefaultinstance":
case "UseDefaultInstance": return boolean.class;
default: return null;
@@ -74,8 +90,16 @@ public class GcpVaultConfigurationConfigurer extends org.apache.camel.support.co
case "HashicorpVaultConfiguration": return target.getHashicorpVaultConfiguration();
case "projectid":
case "ProjectId": return target.getProjectId();
+ case "refreshenabled":
+ case "RefreshEnabled": return target.isRefreshEnabled();
+ case "refreshperiod":
+ case "RefreshPeriod": return target.getRefreshPeriod();
+ case "secrets":
+ case "Secrets": return target.getSecrets();
case "serviceaccountkey":
case "ServiceAccountKey": return target.getServiceAccountKey();
+ case "subscriptionname":
+ case "SubscriptionName": return target.getSubscriptionName();
case "usedefaultinstance":
case "UseDefaultInstance": return target.isUseDefaultInstance();
default: return null;
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 895849bf2e0..244dd57d7c9 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
@@ -218,7 +218,11 @@
{ "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" },
+ { "name": "camel.vault.gcp.refreshEnabled", "description": "Whether to automatically reload Camel upon secrets being updated in AWS.", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
+ { "name": "camel.vault.gcp.refreshPeriod", "description": "The period (millis) between checking Google for updated secrets.", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "integer", "javaType": "long", "defaultValue": 30000 },
+ { "name": "camel.vault.gcp.secrets", "description": "Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma.", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.gcp.serviceAccountKey", "description": "The Service Account Key location", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+ { "name": "camel.vault.gcp.subscriptionName", "description": "Define the Google Pubsub subscription Name to be used when checking for updates", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.vault.gcp.useDefaultInstance", "description": "Define if we want to use the GCP Client Default Instance or not", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }
]
}
diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc
index ece27ae2d5a..f946ead8202 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -223,13 +223,17 @@ The camel.vault.aws supports 7 options, which are listed below.
|===
=== Camel GCP Vault configurations
-The camel.vault.gcp supports 3 options, which are listed below.
+The camel.vault.gcp supports 7 options, which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *camel.vault.gcp.projectId* | The GCP Project ID | | String
+| *camel.vault.gcp.refreshEnabled* | Whether to automatically reload Camel upon secrets being updated in AWS. | false | boolean
+| *camel.vault.gcp.refreshPeriod* | The period (millis) between checking Google for updated secrets. | 30000 | long
+| *camel.vault.gcp.secrets* | Specify the secret names (or pattern) to check for updates. Multiple secrets can be separated by comma. | | String
| *camel.vault.gcp.serviceAccount{zwsp}Key* | The Service Account Key location | | String
+| *camel.vault.gcp.subscription{zwsp}Name* | Define the Google Pubsub subscription Name to be used when checking for updates | | String
| *camel.vault.gcp.useDefault{zwsp}Instance* | Define if we want to use the GCP Client Default Instance or not | false | boolean
|===
[camel] 03/04: CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
Posted by ac...@apache.org.
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 6b6bd28e08c297e37c27b79cd1f4db4e4b31532e
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Sep 13 12:05:25 2022 +0200
CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../component/google/secret/manager/vault/PubsubReloadTriggerTask.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
index e4a2afd0d13..c75ad4e8675 100644
--- a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
+++ b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
@@ -213,7 +213,7 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
if (eventType.equalsIgnoreCase(SECRET_UPDATE) || eventType.equalsIgnoreCase(SECRET_VERSION_ADD)) {
if (matchSecret(secretId)) {
if (isReloadEnabled()) {
- LOG.info("Update for AWS secret: {} detected, triggering CamelContext reload", secretId);
+ LOG.info("Update for GCP secret: {} detected, triggering CamelContext reload", secretId.toString());
triggerReloading = true;
}
}
[camel] 04/04: CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
Posted by ac...@apache.org.
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 6726c4e0a3e9500f9f32c932454904ea8b61b108
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Sep 13 14:07:14 2022 +0200
CAMEL-18501 - Camel-Google-Secret-Manager: Create a task looking for secrets update in PubSub
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../GoogleSecretManagerPropertiesFunction.java | 6 +--
.../manager/vault/PubsubReloadTriggerTask.java | 56 +++++++++++-----------
.../apache/camel/vault/GcpVaultConfiguration.java | 13 +++--
.../org/apache/camel/main/BaseMainSupport.java | 2 +-
.../main/GcpVaultConfigurationProperties.java | 4 +-
5 files changed, 39 insertions(+), 42 deletions(-)
diff --git a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
index 7576aad827e..dcb9ca73b36 100644
--- a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
+++ b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
@@ -180,10 +180,10 @@ public class GoogleSecretManagerPropertiesFunction extends ServiceSupport implem
private String getSecretFromSource(
String key, String subkey, String defaultValue, String version)
throws JsonProcessingException {
-
+
// capture name of secret
secrets.add(key);
-
+
String returnValue = null;
try {
SecretVersionName secretVersionName
@@ -224,7 +224,7 @@ public class GoogleSecretManagerPropertiesFunction extends ServiceSupport implem
public CamelContext getCamelContext() {
return camelContext;
}
-
+
/**
* Ids of the secrets in use
*/
diff --git a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
index c75ad4e8675..866b57a361f 100644
--- a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
+++ b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/vault/PubsubReloadTriggerTask.java
@@ -24,6 +24,15 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import com.google.api.gax.core.FixedCredentialsProvider;
+import com.google.auth.Credentials;
+import com.google.auth.oauth2.GoogleCredentials;
+import com.google.auth.oauth2.ServiceAccountCredentials;
+import com.google.cloud.pubsub.v1.AckReplyConsumer;
+import com.google.cloud.pubsub.v1.MessageReceiver;
+import com.google.cloud.pubsub.v1.Subscriber;
+import com.google.pubsub.v1.ProjectSubscriptionName;
+import com.google.pubsub.v1.PubsubMessage;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.RuntimeCamelException;
@@ -40,16 +49,6 @@ import org.apache.camel.vault.GcpVaultConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.api.gax.core.FixedCredentialsProvider;
-import com.google.auth.Credentials;
-import com.google.auth.oauth2.GoogleCredentials;
-import com.google.auth.oauth2.ServiceAccountCredentials;
-import com.google.cloud.pubsub.v1.AckReplyConsumer;
-import com.google.cloud.pubsub.v1.MessageReceiver;
-import com.google.cloud.pubsub.v1.Subscriber;
-import com.google.pubsub.v1.ProjectSubscriptionName;
-import com.google.pubsub.v1.PubsubMessage;
-
/**
* Period task which checks if Google secrets has been updated and can trigger Camel to be reloaded.
*/
@@ -131,19 +130,18 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
subscription = gcpVaultConfiguration.getSubscriptionName();
}
}
- if (ObjectHelper.isNotEmpty(serviceAccountKey) && ObjectHelper.isNotEmpty(projectId) && ObjectHelper.isNotEmpty(subscription)) {
+ if (ObjectHelper.isNotEmpty(serviceAccountKey) && ObjectHelper.isNotEmpty(projectId)
+ && ObjectHelper.isNotEmpty(subscription)) {
InputStream resolveMandatoryResourceAsInputStream
= ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), serviceAccountKey);
Credentials myCredentials = ServiceAccountCredentials
.fromStream(resolveMandatoryResourceAsInputStream);
- ProjectSubscriptionName subscriptionName =
- ProjectSubscriptionName.of(projectId, subscription);
+ ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscription);
Subscriber.Builder builder = Subscriber.newBuilder(subscriptionName, new FilteringEventMessageReceiver());
builder.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials));
subscriber = builder.build();
} else if (useDefaultInstance && ObjectHelper.isNotEmpty(projectId) && ObjectHelper.isNotEmpty(subscription)) {
- ProjectSubscriptionName subscriptionName =
- ProjectSubscriptionName.of(projectId, subscription);
+ ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscription);
Subscriber.Builder builder = Subscriber.newBuilder(subscriptionName, new FilteringEventMessageReceiver());
builder.setCredentialsProvider(FixedCredentialsProvider.create(GoogleCredentials.getApplicationDefault()));
subscriber = builder.build();
@@ -171,7 +169,7 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
@Override
public void run() {
- subscriber.startAsync().awaitRunning();
+ subscriber.startAsync().awaitRunning();
}
protected boolean matchSecret(String name) {
@@ -198,25 +196,25 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
public String toString() {
return "Google Secrets Refresh Task";
}
-
+
public class FilteringEventMessageReceiver implements MessageReceiver {
- private String SECRET_UPDATE = "SECRET_UPDATE";
- private String SECRET_VERSION_ADD = "SECRET_VERSION_ADD";
-
- private boolean triggerReloading;
-
- @Override
- public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
+ private String SECRET_UPDATE = "SECRET_UPDATE";
+ private String SECRET_VERSION_ADD = "SECRET_VERSION_ADD";
+
+ private boolean triggerReloading;
+
+ @Override
+ public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
String secretId = message.getAttributesMap().get("secretId");
String eventType = message.getAttributesMap().get("eventType");
if (eventType.equalsIgnoreCase(SECRET_UPDATE) || eventType.equalsIgnoreCase(SECRET_VERSION_ADD)) {
- if (matchSecret(secretId)) {
+ if (matchSecret(secretId)) {
if (isReloadEnabled()) {
LOG.info("Update for GCP secret: {} detected, triggering CamelContext reload", secretId.toString());
triggerReloading = true;
}
- }
+ }
}
if (triggerReloading) {
ContextReloadStrategy reload = camelContext.hasService(ContextReloadStrategy.class);
@@ -226,8 +224,8 @@ public class PubsubReloadTriggerTask extends ServiceSupport implements CamelCont
}
}
consumer.ack();
-
- }
-
+
+ }
+
}
}
diff --git a/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
index 15793eab1fb..2cdebd2150c 100644
--- a/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
+++ b/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
@@ -71,17 +71,16 @@ public class GcpVaultConfiguration extends VaultConfiguration {
this.useDefaultInstance = useDefaultInstance;
}
- public String getSubscriptionName() {
- return subscriptionName;
- }
+ public String getSubscriptionName() {
+ return subscriptionName;
+ }
/**
* Define the Google Pubsub subscription Name to be used when checking for updates
*/
- public void setSubscriptionName(String subscriptionName) {
- this.subscriptionName = subscriptionName;
- }
-
+ public void setSubscriptionName(String subscriptionName) {
+ this.subscriptionName = subscriptionName;
+ }
public boolean isRefreshEnabled() {
return refreshEnabled;
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 def6eee6a5c..d7ab13d1f7c 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
@@ -414,7 +414,7 @@ public abstract class BaseMainSupport extends BaseService {
scheduler.schedulePeriodTask(r, period);
}
}
-
+
if (vc.gcp().isRefreshEnabled()) {
Optional<Runnable> task = camelContext.adapt(ExtendedCamelContext.class)
.getPeriodTaskResolver().newInstance("gcp-secret-refresh", Runnable.class);
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
index c91d796d89d..5091de6ed88 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
@@ -72,7 +72,7 @@ public class GcpVaultConfigurationProperties extends GcpVaultConfiguration imple
setUseDefaultInstance(useDefaultInstance);
return this;
}
-
+
/**
* The Pubsub subscriptionName name
*/
@@ -80,7 +80,7 @@ public class GcpVaultConfigurationProperties extends GcpVaultConfiguration imple
setSubscriptionName(subscriptionName);
return this;
}
-
+
/**
* Whether to automatically reload Camel upon secrets being updated in Google.
*/