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 033debd580785c5a4c20dea8dc1012944c1f1940 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Jul 5 11:21:13 2022 +0200 CAMEL-18256 - Camel-Hashicorp-vault: Support Versioning of secret while reading --- .../apache/camel/component/hashicorp/vault/hashicorp-vault.json | 3 ++- .../camel/component/hashicorp/vault/HashicorpVaultConstants.java | 5 +++++ .../camel/component/hashicorp/vault/HashicorpVaultProducer.java | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/components/camel-hashicorp-vault/src/generated/resources/org/apache/camel/component/hashicorp/vault/hashicorp-vault.json b/components/camel-hashicorp-vault/src/generated/resources/org/apache/camel/component/hashicorp/vault/hashicorp-vault.json index 2515a09ee78..11dbe253dbe 100644 --- a/components/camel-hashicorp-vault/src/generated/resources/org/apache/camel/component/hashicorp/vault/hashicorp-vault.json +++ b/components/camel-hashicorp-vault/src/generated/resources/org/apache/camel/component/hashicorp/vault/hashicorp-vault.json @@ -27,7 +27,8 @@ }, "headers": { "CamelHashicorpVaultProducerOperation": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Overrides the desired operation to be used in the producer.", "constantName": "org.apache.camel.component.hashicorp.vault.HashicorpVaultConstants#OPERATION" }, - "CamelHashicorpVaultSecretPath": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Set the desired secret path as header.", "constantName": "org.apache.camel.component.hashicorp.vault.HashicorpVaultConstants#SECRET_PATH" } + "CamelHashicorpVaultSecretPath": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Set the desired secret path as header.", "constantName": "org.apache.camel.component.hashicorp.vault.HashicorpVaultConstants#SECRET_PATH" }, + "CamelHashicorpVaultSecretVersion": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Set the desired secret version as header.", "constantName": "org.apache.camel.component.hashicorp.vault.HashicorpVaultConstants#SECRET_VERSION" } }, "properties": { "secretsEngine": { "kind": "path", "displayName": "Secrets Engine", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.hashicorp.vault.HashicorpVaultConfiguration", "configurationField": "configuration", "description": "Vault Name to be used" }, diff --git a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultConstants.java b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultConstants.java index 941e5224f59..f8711477d3c 100644 --- a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultConstants.java +++ b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultConstants.java @@ -31,6 +31,11 @@ public final class HashicorpVaultConstants { javaType = "String") public static final String SECRET_PATH = HEADER_PREFIX + "SecretPath"; + // headers set by the producer only + @Metadata(label = "producer", description = "Set the desired secret version as header.", + javaType = "String") + public static final String SECRET_VERSION = HEADER_PREFIX + "SecretVersion"; + private HashicorpVaultConstants() { } } diff --git a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java index f4743bd7dc7..3ead39c6269 100644 --- a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java +++ b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultProducer.java @@ -72,12 +72,19 @@ public class HashicorpVaultProducer extends DefaultProducer { private void getSecret(Exchange exchange) { String secretPath; + String secretVersion = null; if (ObjectHelper.isNotEmpty(exchange.getMessage().getHeader(HashicorpVaultConstants.SECRET_PATH))) { secretPath = exchange.getMessage().getHeader(HashicorpVaultConstants.SECRET_PATH, String.class); } else { throw new IllegalArgumentException("Secret Path must be specified"); } + if (ObjectHelper.isNotEmpty(exchange.getMessage().getHeader(HashicorpVaultConstants.SECRET_VERSION))) { + secretVersion = exchange.getMessage().getHeader(HashicorpVaultConstants.SECRET_VERSION, String.class); + } String completePath = getEndpoint().getConfiguration().getSecretsEngine() + "/" + "data" + "/" + secretPath; + if (ObjectHelper.isNotEmpty(secretVersion)) { + completePath = completePath + "?" + secretVersion; + } VaultResponse rawSecret = getEndpoint().getVaultTemplate().read(completePath); exchange.getMessage().setBody(rawSecret.getData()); }