You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "Croway (via GitHub)" <gi...@apache.org> on 2024/10/09 09:53:44 UTC

[PR] Hashicorp vault early properties parser [camel-spring-boot]

Croway opened a new pull request, #1249:
URL: https://github.com/apache/camel-spring-boot/pull/1249

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Hashicorp vault early properties parser [camel-spring-boot]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #1249:
URL: https://github.com/apache/camel-spring-boot/pull/1249#discussion_r1793237135


##########
components-starter/camel-hashicorp-vault-starter/src/main/java/org/apache/camel/component/hashicorp/vault/springboot/SpringBootHashicorpVaultPropertiesParser.java:
##########
@@ -0,0 +1,80 @@
+package org.apache.camel.component.hashicorp.vault.springboot;
+
+import org.apache.camel.component.hashicorp.vault.HashicorpVaultPropertiesFunction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
+import org.springframework.boot.origin.OriginTrackedValue;
+import org.springframework.context.ApplicationListener;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MapPropertySource;
+import org.springframework.core.env.PropertiesPropertySource;
+import org.springframework.core.env.PropertySource;
+import org.springframework.vault.authentication.TokenAuthentication;
+import org.springframework.vault.client.VaultEndpoint;
+import org.springframework.vault.core.VaultTemplate;
+
+import java.util.Objects;
+import java.util.Properties;
+
+public class SpringBootHashicorpVaultPropertiesParser implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
+    private static final Logger LOG = LoggerFactory.getLogger(SpringBootHashicorpVaultPropertiesParser.class);
+
+    @Override
+    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
+        ConfigurableEnvironment environment = event.getEnvironment();
+        if (Boolean.parseBoolean(environment.getProperty("camel.component.hashicorp-vault.early-resolve-properties"))) {
+            Objects.requireNonNull(environment.getProperty("camel.vault.hashicorp.token"), "Hashicorp Vault token is required");
+            Objects.requireNonNull(environment.getProperty("camel.vault.hashicorp.host"), "Hashicorp Vault host is required");
+            Objects.requireNonNull(environment.getProperty("camel.vault.hashicorp.port"), "Hashicorp Vault port is required");
+            Objects.requireNonNull(environment.getProperty("camel.vault.hashicorp.scheme"), "Hashicorp Vault scheme is required");
+
+            String token = environment.getProperty("camel.vault.hashicorp.token");
+            String host = environment.getProperty("camel.vault.hashicorp.host");
+
+            int port = Integer.parseInt(environment.getProperty("camel.vault.hashicorp.port"));
+            String scheme = environment.getProperty("camel.vault.hashicorp.scheme");
+
+            VaultEndpoint vaultEndpoint = new VaultEndpoint();
+            vaultEndpoint.setHost(host);
+            vaultEndpoint.setPort(port);
+            vaultEndpoint.setScheme(scheme);
+
+            VaultTemplate client = new VaultTemplate(
+                    vaultEndpoint,
+                    new TokenAuthentication(token));
+            HashicorpVaultPropertiesFunction hashicorpVaultPropertiesFunction = new HashicorpVaultPropertiesFunction(client);
+
+            final Properties props = new Properties();
+            for (PropertySource mutablePropertySources : event.getEnvironment().getPropertySources()) {
+                if (mutablePropertySources instanceof MapPropertySource mapPropertySource) {
+                    mapPropertySource.getSource().forEach((key, value) -> {
+                        String stringValue = null;
+                        if ((value instanceof OriginTrackedValue originTrackedValue &&
+                                originTrackedValue.getValue() instanceof String v)) {
+                            stringValue = v;
+                        } else if (value instanceof String v) {
+                            stringValue = v;
+                        }
+
+                        if (stringValue != null &&
+                                stringValue.startsWith("{{hashicorp:") &&
+                                stringValue.endsWith("}}")) {
+                            LOG.debug("decrypting and overriding property {}", key);
+                            try {
+                                props.put(key, hashicorpVaultPropertiesFunction.apply(stringValue
+                                        .replace("{{hashicorp:", "")
+                                        .replace("}}", "")));
+                            } catch (Exception e) {
+                                // Log and do nothing
+                                LOG.debug("failed to parse property {}", key, e);

Review Comment:
   Add ". This exception is ignored".



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Hashicorp vault early properties parser [camel-spring-boot]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway merged PR #1249:
URL: https://github.com/apache/camel-spring-boot/pull/1249


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Hashicorp vault early properties parser [camel-spring-boot]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on PR #1249:
URL: https://github.com/apache/camel-spring-boot/pull/1249#issuecomment-2401877947

   The pipeline failure is expected due to https://github.com/apache/camel/pull/15896#pullrequestreview-2356622895


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org