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 8ae0c2d620d522536df2b5abcb915e184392029a Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Feb 19 10:34:47 2022 +0100 CAMEL-17644: camel-core - Add VaultConfiguration SPI --- .../main/java/org/apache/camel/CamelContext.java | 4 +- .../AwsVaultConfiguration.java} | 38 +++++++------- .../camel/{spi => vault}/VaultConfiguration.java | 46 ++++------------ .../camel/impl/engine/AbstractCamelContext.java | 2 +- .../camel/impl/ExtendedCamelContextConfigurer.java | 4 +- .../camel/impl/lw/LightweightCamelContext.java | 2 +- .../impl/lw/LightweightRuntimeCamelContext.java | 2 +- .../AwsVaultConfigurationPropertiesConfigurer.java | 61 ++++++++++++++++++++++ .../VaultConfigurationPropertiesConfigurer.java | 61 ---------------------- .../camel-main-configuration-metadata.json | 8 +-- ...ache.camel.main.AwsVaultConfigurationProperties | 2 + core/camel-main/src/main/docs/main.adoc | 10 ++-- ...s.java => AwsVaultConfigurationProperties.java} | 20 +++---- .../org/apache/camel/main/BaseMainSupport.java | 33 ++++++++++-- .../camel/main/MainConfigurationProperties.java | 4 +- .../camel/main/VaultConfigurationProperties.java | 55 ++++--------------- .../java/org/apache/camel/main/MainVaultTest.java | 32 ++++++------ .../maven/packaging/PrepareCamelMainMojo.java | 14 +++-- 18 files changed, 185 insertions(+), 213 deletions(-) diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java index 669b56c..d4ddd58 100644 --- a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java +++ b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java @@ -52,8 +52,8 @@ import org.apache.camel.spi.TypeConverterRegistry; import org.apache.camel.spi.UuidGenerator; import org.apache.camel.spi.Validator; import org.apache.camel.spi.ValidatorRegistry; -import org.apache.camel.spi.VaultConfiguration; import org.apache.camel.support.jsse.SSLContextParameters; +import org.apache.camel.vault.VaultConfiguration; /** * Interface used to represent the CamelContext used to configure routes and the policies to use during message @@ -674,7 +674,7 @@ public interface CamelContext extends CamelContextLifecycle, RuntimeConfiguratio RestConfiguration getRestConfiguration(); /** - * Sets a custom {@link org.apache.camel.spi.VaultConfiguration} + * Sets a custom {@link VaultConfiguration} * * @param vaultConfiguration the vault configuration */ diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java similarity index 60% copy from core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java copy to core/camel-api/src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java index b50ee0c..4b2bb00 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java +++ b/core/camel-api/src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java @@ -14,51 +14,53 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.spi; +package org.apache.camel.vault; + +import org.apache.camel.spi.Metadata; /** - * Configuration for access to Vaults. + * Configuration for access to AWS Secret. */ -public class VaultConfiguration { +public class AwsVaultConfiguration extends VaultConfiguration { @Metadata(secret = true) - private String awsAccessKey; + private String accessKey; @Metadata(secret = true) - private String awsSecretKey; + private String secretKey; @Metadata - private String awsRegion; + private String region; - public String getAwsAccessKey() { - return awsAccessKey; + public String getAccessKey() { + return accessKey; } /** * The AWS access key */ - public void setAwsAccessKey(String awsAccessKey) { - this.awsAccessKey = awsAccessKey; + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; } - public String getAwsSecretKey() { - return awsSecretKey; + public String getSecretKey() { + return secretKey; } /** * The AWS secret key */ - public void setAwsSecretKey(String awsSecretKey) { - this.awsSecretKey = awsSecretKey; + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; } - public String getAwsRegion() { - return awsRegion; + public String getRegion() { + return region; } /** * The AWS region */ - public void setAwsRegion(String awsRegion) { - this.awsRegion = awsRegion; + public void setRegion(String region) { + this.region = region; } } diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java similarity index 50% rename from core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java rename to core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java index b50ee0c..bcbcdb8 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java +++ b/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java @@ -14,51 +14,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.spi; +package org.apache.camel.vault; /** - * Configuration for access to Vaults. + * Base configuration for access to Vaults. */ public class VaultConfiguration { - @Metadata(secret = true) - private String awsAccessKey; - @Metadata(secret = true) - private String awsSecretKey; - @Metadata - private String awsRegion; - - public String getAwsAccessKey() { - return awsAccessKey; - } - - /** - * The AWS access key - */ - public void setAwsAccessKey(String awsAccessKey) { - this.awsAccessKey = awsAccessKey; - } - - public String getAwsSecretKey() { - return awsSecretKey; - } - - /** - * The AWS secret key - */ - public void setAwsSecretKey(String awsSecretKey) { - this.awsSecretKey = awsSecretKey; - } - - public String getAwsRegion() { - return awsRegion; - } + private AwsVaultConfiguration aws; /** - * The AWS region + * AWS Vault Configuration */ - public void setAwsRegion(String awsRegion) { - this.awsRegion = awsRegion; + public AwsVaultConfiguration aws() { + if (aws == null) { + aws = new AwsVaultConfiguration(); + } + return aws; } } diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java index 9ebd16c..dd55c69 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java @@ -169,7 +169,6 @@ import org.apache.camel.spi.UriFactoryResolver; import org.apache.camel.spi.UuidGenerator; import org.apache.camel.spi.Validator; import org.apache.camel.spi.ValidatorRegistry; -import org.apache.camel.spi.VaultConfiguration; import org.apache.camel.spi.XMLRoutesDefinitionLoader; import org.apache.camel.support.CamelContextHelper; import org.apache.camel.support.EndpointHelper; @@ -189,6 +188,7 @@ import org.apache.camel.util.StopWatch; import org.apache.camel.util.StringHelper; import org.apache.camel.util.TimeUtils; import org.apache.camel.util.URISupport; +import org.apache.camel.vault.VaultConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; diff --git a/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java b/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java index 8eeef0d..8a2bf2a 100644 --- a/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java +++ b/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java @@ -212,7 +212,7 @@ public class ExtendedCamelContextConfigurer extends org.apache.camel.support.com case "uuidgenerator": case "UuidGenerator": target.setUuidGenerator(property(camelContext, org.apache.camel.spi.UuidGenerator.class, value)); return true; case "vaultconfiguration": - case "VaultConfiguration": target.setVaultConfiguration(property(camelContext, org.apache.camel.spi.VaultConfiguration.class, value)); return true; + case "VaultConfiguration": target.setVaultConfiguration(property(camelContext, org.apache.camel.vault.VaultConfiguration.class, value)); return true; case "xmlroutesdefinitionloader": case "XMLRoutesDefinitionLoader": target.setXMLRoutesDefinitionLoader(property(camelContext, org.apache.camel.spi.XMLRoutesDefinitionLoader.class, value)); return true; default: return false; @@ -413,7 +413,7 @@ public class ExtendedCamelContextConfigurer extends org.apache.camel.support.com case "uuidgenerator": case "UuidGenerator": return org.apache.camel.spi.UuidGenerator.class; case "vaultconfiguration": - case "VaultConfiguration": return org.apache.camel.spi.VaultConfiguration.class; + case "VaultConfiguration": return org.apache.camel.vault.VaultConfiguration.class; case "xmlroutesdefinitionloader": case "XMLRoutesDefinitionLoader": return org.apache.camel.spi.XMLRoutesDefinitionLoader.class; default: return null; diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java index b5c5dff..531584e 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java @@ -149,10 +149,10 @@ import org.apache.camel.spi.UriFactoryResolver; import org.apache.camel.spi.UuidGenerator; import org.apache.camel.spi.Validator; import org.apache.camel.spi.ValidatorRegistry; -import org.apache.camel.spi.VaultConfiguration; import org.apache.camel.spi.XMLRoutesDefinitionLoader; import org.apache.camel.support.DefaultRegistry; import org.apache.camel.support.jsse.SSLContextParameters; +import org.apache.camel.vault.VaultConfiguration; @Experimental public class LightweightCamelContext implements ExtendedCamelContext, CatalogCamelContext, ModelCamelContext { diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java index e344bc5..1bc5b25 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java @@ -144,7 +144,6 @@ import org.apache.camel.spi.UriFactoryResolver; import org.apache.camel.spi.UuidGenerator; import org.apache.camel.spi.Validator; import org.apache.camel.spi.ValidatorRegistry; -import org.apache.camel.spi.VaultConfiguration; import org.apache.camel.spi.XMLRoutesDefinitionLoader; import org.apache.camel.support.CamelContextHelper; import org.apache.camel.support.NormalizedUri; @@ -154,6 +153,7 @@ import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.StringHelper; import org.apache.camel.util.TimeUtils; import org.apache.camel.util.URISupport; +import org.apache.camel.vault.VaultConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java new file mode 100644 index 0000000..8ef2142 --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java @@ -0,0 +1,61 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.main.AwsVaultConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class AwsVaultConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.AwsVaultConfigurationProperties target = (org.apache.camel.main.AwsVaultConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "AccessKey": target.setAccessKey(property(camelContext, java.lang.String.class, value)); return true; + case "region": + case "Region": target.setRegion(property(camelContext, java.lang.String.class, value)); return true; + case "secretkey": + case "SecretKey": target.setSecretKey(property(camelContext, java.lang.String.class, value)); return true; + default: return false; + } + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "AccessKey": return java.lang.String.class; + case "region": + case "Region": return java.lang.String.class; + case "secretkey": + case "SecretKey": return java.lang.String.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + org.apache.camel.main.AwsVaultConfigurationProperties target = (org.apache.camel.main.AwsVaultConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "AccessKey": return target.getAccessKey(); + case "region": + case "Region": return target.getRegion(); + case "secretkey": + case "SecretKey": return target.getSecretKey(); + default: return null; + } + } +} + diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java deleted file mode 100644 index ba2c389..0000000 --- a/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* Generated by camel build tools - do NOT edit this file! */ -package org.apache.camel.main; - -import java.util.Map; - -import org.apache.camel.CamelContext; -import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; -import org.apache.camel.spi.PropertyConfigurerGetter; -import org.apache.camel.spi.ConfigurerStrategy; -import org.apache.camel.spi.GeneratedPropertyConfigurer; -import org.apache.camel.util.CaseInsensitiveMap; -import org.apache.camel.main.VaultConfigurationProperties; - -/** - * Generated by camel build tools - do NOT edit this file! - */ -@SuppressWarnings("unchecked") -public class VaultConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { - - @Override - public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { - org.apache.camel.main.VaultConfigurationProperties target = (org.apache.camel.main.VaultConfigurationProperties) obj; - switch (ignoreCase ? name.toLowerCase() : name) { - case "awsaccesskey": - case "AwsAccessKey": target.setAwsAccessKey(property(camelContext, java.lang.String.class, value)); return true; - case "awsregion": - case "AwsRegion": target.setAwsRegion(property(camelContext, java.lang.String.class, value)); return true; - case "awssecretkey": - case "AwsSecretKey": target.setAwsSecretKey(property(camelContext, java.lang.String.class, value)); return true; - default: return false; - } - } - - @Override - public Class<?> getOptionType(String name, boolean ignoreCase) { - switch (ignoreCase ? name.toLowerCase() : name) { - case "awsaccesskey": - case "AwsAccessKey": return java.lang.String.class; - case "awsregion": - case "AwsRegion": return java.lang.String.class; - case "awssecretkey": - case "AwsSecretKey": return java.lang.String.class; - default: return null; - } - } - - @Override - public Object getOptionValue(Object obj, String name, boolean ignoreCase) { - org.apache.camel.main.VaultConfigurationProperties target = (org.apache.camel.main.VaultConfigurationProperties) obj; - switch (ignoreCase ? name.toLowerCase() : name) { - case "awsaccesskey": - case "AwsAccessKey": return target.getAwsAccessKey(); - case "awsregion": - case "AwsRegion": return target.getAwsRegion(); - case "awssecretkey": - case "AwsSecretKey": return target.getAwsSecretKey(); - 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 5404d48..c5bd162 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 @@ -4,7 +4,7 @@ { "name": "camel.threadpool", "description": "Camel Thread Pool configurations", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties" }, { "name": "camel.health", "description": "Camel Health Check configurations", "sourceType": "org.apache.camel.main.HealthConfigurationProperties" }, { "name": "camel.rest", "description": "Camel Rest-DSL configurations", "sourceType": "org.apache.camel.spi.RestConfiguration" }, - { "name": "camel.vault", "description": "Camel Vault configurations", "sourceType": "org.apache.camel.spi.VaultConfiguration" }, + { "name": "camel.vault.aws", "description": "Camel AWS Vault configurations", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration" }, { "name": "camel.faulttolerance", "description": "Fault Tolerance EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.FaultToleranceConfigurationProperties" }, { "name": "camel.resilience4j", "description": "Resilience4j EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.Resilience4jConfigurationProperties" }, { "name": "camel.hystrix", "description": "Hystrix (deprecated) EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.HystrixConfigurationProperties" }, @@ -229,8 +229,8 @@ { "name": "camel.threadpool.poolSize", "description": "Sets the default core pool size (threads to keep minimum in pool)", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "integer", "javaType": "java.lang.Integer" }, { "name": "camel.threadpool.rejectedPolicy", "description": "Sets the default handler for tasks which cannot be executed by the thread pool.", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy", "enum": [ "Abort", "CallerRuns", "DiscardOldest", "Discard" ] }, { "name": "camel.threadpool.timeUnit", "description": "Sets the default time unit used for keep alive time", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "java.util.concurrent.TimeUnit" }, - { "name": "camel.vault.awsAccessKey", "description": "The AWS access key", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" }, - { "name": "camel.vault.awsRegion", "description": "The AWS region", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" }, - { "name": "camel.vault.awsSecretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" } + { "name": "camel.vault.aws.accessKey", "description": "The AWS access key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" }, + { "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" } ] } diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.AwsVaultConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.AwsVaultConfigurationProperties new file mode 100644 index 0000000..9334aae --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.AwsVaultConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.AwsVaultConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc index 8621ec1..2553118 100644 --- a/core/camel-main/src/main/docs/main.adoc +++ b/core/camel-main/src/main/docs/main.adoc @@ -200,15 +200,15 @@ The camel.rest supports 28 options, which are listed below. | *camel.rest.xmlDataFormat* | Sets a custom xml data format to be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. | | String |=== -=== Camel Vault configurations -The camel.vault supports 3 options, which are listed below. +=== Camel AWS Vault configurations +The camel.vault.aws supports 3 options, which are listed below. [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type -| *camel.vault.awsAccessKey* | The AWS access key | | String -| *camel.vault.awsRegion* | The AWS region | | String -| *camel.vault.awsSecretKey* | The AWS secret key | | String +| *camel.vault.aws.accessKey* | The AWS access key | | String +| *camel.vault.aws.region* | The AWS region | | String +| *camel.vault.aws.secretKey* | The AWS secret key | | String |=== === Fault Tolerance EIP Circuit Breaker configurations diff --git a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/AwsVaultConfigurationProperties.java similarity index 72% copy from core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java copy to core/camel-main/src/main/java/org/apache/camel/main/AwsVaultConfigurationProperties.java index 7901a29..5bd4b1d 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/AwsVaultConfigurationProperties.java @@ -18,17 +18,17 @@ package org.apache.camel.main; import org.apache.camel.spi.BootstrapCloseable; import org.apache.camel.spi.Configurer; -import org.apache.camel.spi.VaultConfiguration; +import org.apache.camel.vault.AwsVaultConfiguration; /** - * Global configuration for accessing secrets in vaults. + * Configuration for access to AWS Secret. */ @Configurer(bootstrap = true) -public class VaultConfigurationProperties extends VaultConfiguration implements BootstrapCloseable { +public class AwsVaultConfigurationProperties extends AwsVaultConfiguration implements BootstrapCloseable { private MainConfigurationProperties parent; - public VaultConfigurationProperties(MainConfigurationProperties parent) { + public AwsVaultConfigurationProperties(MainConfigurationProperties parent) { this.parent = parent; } @@ -52,24 +52,24 @@ public class VaultConfigurationProperties extends VaultConfiguration implements /** * The AWS access key */ - public VaultConfigurationProperties withAwsAccessKey(String awsAccessKey) { - setAwsAccessKey(awsAccessKey); + public AwsVaultConfigurationProperties withAccessKey(String accessKey) { + setAccessKey(accessKey); return this; } /** * The AWS secret key */ - public VaultConfigurationProperties withAwsSecretKey(String awsSecretKey) { - setAwsSecretKey(awsSecretKey); + public AwsVaultConfigurationProperties withSecretKey(String secretKey) { + setSecretKey(secretKey); return this; } /** * The AWS region */ - public VaultConfigurationProperties withAwsRegion(String awsRegion) { - setAwsRegion(awsRegion); + public AwsVaultConfigurationProperties withRegion(String region) { + setRegion(region); 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 8639020..af84a12 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 @@ -67,6 +67,7 @@ import org.apache.camel.util.OrderedProperties; import org.apache.camel.util.PropertiesHelper; import org.apache.camel.util.SensitiveUtils; import org.apache.camel.util.StringHelper; +import org.apache.camel.vault.VaultConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -876,11 +877,9 @@ public abstract class BaseMainSupport extends BaseService { } if (!vaultProperties.isEmpty() || mainConfigurationProperties.hasVaultConfiguration()) { - VaultConfigurationProperties vault = mainConfigurationProperties.vault(); LOG.debug("Auto-configuring Vault from loaded properties: {}", vaultProperties.size()); - setPropertiesOnTarget(camelContext, vault, vaultProperties, "camel.vault.", - mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties); - camelContext.setVaultConfiguration(vault); + setVaultProperties(camelContext, vaultProperties, mainConfigurationProperties.isAutoConfigurationFailFast(), + autoConfiguredProperties); } if (!threadPoolProperties.isEmpty() || mainConfigurationProperties.hasThreadPoolConfiguration()) { @@ -1104,6 +1103,32 @@ public abstract class BaseMainSupport extends BaseService { } } + private void setVaultProperties( + CamelContext camelContext, Map<String, Object> properties, + boolean failIfNotSet, Map<String, String> autoConfiguredProperties) + throws Exception { + + if (mainConfigurationProperties.hasVaultConfiguration()) { + camelContext.setVaultConfiguration(mainConfigurationProperties.vault()); + } + VaultConfiguration target = camelContext.getVaultConfiguration(); + + // make defensive copy as we mutate the map + Set<String> keys = new LinkedHashSet<>(properties.keySet()); + // set properties per different vault component + for (String key : keys) { + String name = StringHelper.before(key, "."); + if ("aws".equalsIgnoreCase(name)) { + // TODO: add more vault providers here + target = target.aws(); + } + // configure all the properties on the vault at once (to ensure they are configured in right order) + Map<String, Object> config = PropertiesHelper.extractProperties(properties, name + "."); + setPropertiesOnTarget(camelContext, target, config, "camel.vault." + name + ".", failIfNotSet, true, + autoConfiguredProperties); + } + } + private void bindBeansToRegistry( CamelContext camelContext, Map<String, Object> properties, String optionPrefix, boolean failIfNotSet, boolean logSummary, boolean ignoreCase, diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java index b4aefb2..59b1cd4 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java @@ -226,7 +226,7 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< } /** - * To configure access to vaults + * To configure access to AWS vaults */ public VaultConfigurationProperties vault() { if (vaultConfigurationProperties == null) { @@ -236,7 +236,7 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< } /** - * Whether there has been any rest configuration specified + * Whether there has been any vault configuration specified */ public boolean hasVaultConfiguration() { return vaultConfigurationProperties != null; diff --git a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java index 7901a29..2bb2693 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java @@ -1,32 +1,12 @@ -/* - * 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.main; import org.apache.camel.spi.BootstrapCloseable; -import org.apache.camel.spi.Configurer; -import org.apache.camel.spi.VaultConfiguration; +import org.apache.camel.vault.VaultConfiguration; -/** - * Global configuration for accessing secrets in vaults. - */ -@Configurer(bootstrap = true) public class VaultConfigurationProperties extends VaultConfiguration implements BootstrapCloseable { private MainConfigurationProperties parent; + private AwsVaultConfigurationProperties aws; public VaultConfigurationProperties(MainConfigurationProperties parent) { this.parent = parent; @@ -39,6 +19,9 @@ public class VaultConfigurationProperties extends VaultConfiguration implements @Override public void close() { parent = null; + if (aws != null) { + aws.close(); + } } // getter and setters @@ -49,28 +32,12 @@ public class VaultConfigurationProperties extends VaultConfiguration implements // fluent builders // -------------------------------------------------------------- - /** - * The AWS access key - */ - public VaultConfigurationProperties withAwsAccessKey(String awsAccessKey) { - setAwsAccessKey(awsAccessKey); - return this; - } - - /** - * The AWS secret key - */ - public VaultConfigurationProperties withAwsSecretKey(String awsSecretKey) { - setAwsSecretKey(awsSecretKey); - return this; - } - - /** - * The AWS region - */ - public VaultConfigurationProperties withAwsRegion(String awsRegion) { - setAwsRegion(awsRegion); - return this; + @Override + public AwsVaultConfigurationProperties aws() { + if (aws == null) { + aws = new AwsVaultConfigurationProperties(parent); + } + return aws; } } diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java index ac7b43e..3b2b44d 100644 --- a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java +++ b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java @@ -17,7 +17,7 @@ package org.apache.camel.main; import org.apache.camel.CamelContext; -import org.apache.camel.spi.VaultConfiguration; +import org.apache.camel.vault.AwsVaultConfiguration; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -29,21 +29,21 @@ public class MainVaultTest { public void testMain() throws Exception { Main main = new Main(); - main.addInitialProperty("camel.vault.awsAccessKey", "myKey"); - main.addInitialProperty("camel.vault.awsSecretKey", "mySecret"); - main.addInitialProperty("camel.vault.awsRegion", "myRegion"); + main.addInitialProperty("camel.vault.aws.accessKey", "myKey"); + main.addInitialProperty("camel.vault.aws.secretKey", "mySecret"); + main.addInitialProperty("camel.vault.aws.region", "myRegion"); main.start(); CamelContext context = main.getCamelContext(); assertNotNull(context); - VaultConfiguration cfg = context.getVaultConfiguration(); + AwsVaultConfiguration cfg = context.getVaultConfiguration().aws(); assertNotNull(cfg); - Assertions.assertEquals("myKey", cfg.getAwsAccessKey()); - Assertions.assertEquals("mySecret", cfg.getAwsSecretKey()); - Assertions.assertEquals("myRegion", cfg.getAwsRegion()); + Assertions.assertEquals("myKey", cfg.getAccessKey()); + Assertions.assertEquals("mySecret", cfg.getSecretKey()); + Assertions.assertEquals("myRegion", cfg.getRegion()); main.stop(); } @@ -51,10 +51,10 @@ public class MainVaultTest { @Test public void testMainFluent() throws Exception { Main main = new Main(); - main.configure().vault() - .withAwsAccessKey("myKey") - .withAwsSecretKey("mySecret") - .withAwsRegion("myRegion") + main.configure().vault().aws() + .withAccessKey("myKey") + .withSecretKey("mySecret") + .withRegion("myRegion") .end(); main.start(); @@ -62,12 +62,12 @@ public class MainVaultTest { CamelContext context = main.getCamelContext(); assertNotNull(context); - VaultConfiguration cfg = context.getVaultConfiguration(); + AwsVaultConfiguration cfg = context.getVaultConfiguration().aws(); assertNotNull(cfg); - Assertions.assertEquals("myKey", cfg.getAwsAccessKey()); - Assertions.assertEquals("mySecret", cfg.getAwsSecretKey()); - Assertions.assertEquals("myRegion", cfg.getAwsRegion()); + Assertions.assertEquals("myKey", cfg.getAccessKey()); + Assertions.assertEquals("mySecret", cfg.getSecretKey()); + Assertions.assertEquals("myRegion", cfg.getRegion()); main.stop(); } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java index a405f4f..843fd6e 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java @@ -195,8 +195,9 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo { prefix = "camel.faulttolerance."; } else if (file.getName().contains("Rest")) { prefix = "camel.rest."; - } else if (file.getName().contains("Vault")) { - prefix = "camel.vault."; + } else if (file.getName().contains("AwsVault")) { + prefix = "camel.vault.aws."; + // TODO: add more vault providers here } else if (file.getName().contains("Health")) { prefix = "camel.health."; } else if (file.getName().contains("Lra")) { @@ -228,10 +229,11 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo { throw new MojoFailureException("Error parsing file " + restConfig + " due " + e.getMessage(), e); } // include additional vault configuration from camel-api - File vaultConfig = new File(camelApiDir, "src/main/java/org/apache/camel/spi/VaultConfiguration.java"); + // TODO: add more vault providers here + File vaultConfig = new File(camelApiDir, "src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java"); try { List<MainModel.MainOptionModel> model = parseConfigurationSource(vaultConfig); - model.forEach(m -> m.setName("camel.vault." + m.getName())); + model.forEach(m -> m.setName("camel.vault.aws." + m.getName())); data.addAll(model); } catch (Exception e) { throw new MojoFailureException("Error parsing file " + restConfig + " due " + e.getMessage(), e); @@ -265,7 +267,9 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo { "camel.rest", "Camel Rest-DSL configurations", "org.apache.camel.spi.RestConfiguration")); model.getGroups().add( new MainGroupModel( - "camel.vault", "Camel Vault configurations", "org.apache.camel.spi.VaultConfiguration")); + "camel.vault.aws", "Camel AWS Vault configurations", + "org.apache.camel.vault.AwsVaultConfiguration")); + // TODO: add more vault providers here model.getGroups() .add(new MainGroupModel( "camel.faulttolerance", "Fault Tolerance EIP Circuit Breaker configurations",