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 4c8b60a276403f66cfe589cb60abaa920e0edfb5 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Sat Feb 19 14:07:11 2022 +0100 CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws secrets manager --- .../SecretsManagerPropertiesFunction.java | 22 +++-------- .../SecretsManagerNoEnvPropertiesSourceTestIT.java | 44 ++++++++++------------ 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerPropertiesFunction.java b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerPropertiesFunction.java index 6c14068..a195fb5 100644 --- a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerPropertiesFunction.java +++ b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerPropertiesFunction.java @@ -26,11 +26,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; import org.apache.camel.RuntimeCamelException; -import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.spi.PropertiesFunction; import org.apache.camel.support.service.ServiceSupport; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.StringHelper; +import org.apache.camel.vault.AwsVaultConfiguration; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; import software.amazon.awssdk.regions.Region; @@ -61,9 +61,6 @@ public class SecretsManagerPropertiesFunction extends ServiceSupport implements private static final String CAMEL_AWS_VAULT_ACCESS_KEY_ENV = "CAMEL_VAULT_AWS_ACCESS_KEY"; private static final String CAMEL_AWS_VAULT_SECRET_KEY_ENV = "CAMEL_VAULT_AWS_SECRET_KEY"; private static final String CAMEL_AWS_VAULT_REGION_ENV = "CAMEL_VAULT_AWS_REGION"; - private static final String CAMEL_AWS_VAULT_ACCESS_KEY_PROP = "camel.aws.vault.access.key"; - private static final String CAMEL_AWS_VAULT_SECRET_KEY_PROP = "camel.aws.vault.secret.key"; - private static final String CAMEL_AWS_VAULT_REGION_PROP = "camel.aws.vault.region"; private CamelContext camelContext; private SecretsManagerClient client; @@ -74,18 +71,11 @@ public class SecretsManagerPropertiesFunction extends ServiceSupport implements String secretKey = System.getenv(CAMEL_AWS_VAULT_SECRET_KEY_ENV); String region = System.getenv(CAMEL_AWS_VAULT_REGION_ENV); if (ObjectHelper.isEmpty(accessKey) && ObjectHelper.isEmpty(secretKey) && ObjectHelper.isEmpty(region)) { - PropertiesComponent pc = getCamelContext().getPropertiesComponent(); - Optional<String> tmpAccessKey = pc.resolveProperty(CAMEL_AWS_VAULT_ACCESS_KEY_PROP); - if (tmpAccessKey.isPresent()) { - accessKey = tmpAccessKey.get(); - } - Optional<String> tmpSecretKey = pc.resolveProperty(CAMEL_AWS_VAULT_SECRET_KEY_PROP); - if (tmpSecretKey.isPresent()) { - secretKey = tmpSecretKey.get(); - } - Optional<String> tmpRegion = pc.resolveProperty(CAMEL_AWS_VAULT_REGION_PROP); - if (tmpRegion.isPresent()) { - region = tmpRegion.get(); + AwsVaultConfiguration awsVaultConfiguration = getCamelContext().getVaultConfiguration().aws(); + if (ObjectHelper.isNotEmpty(awsVaultConfiguration)) { + accessKey = awsVaultConfiguration.getAccessKey(); + secretKey = awsVaultConfiguration.getSecretKey(); + region = awsVaultConfiguration.getRegion(); } } SecretsManagerClientBuilder clientBuilder = SecretsManagerClient.builder(); diff --git a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java index 83251f2..3633b6b 100644 --- a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java +++ b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java @@ -23,25 +23,23 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperties; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; -import static org.apache.camel.util.CollectionHelper.propertiesOf; import static org.junit.jupiter.api.Assertions.assertThrows; -// Must be manually tested. Provide your own accessKey and secretKey using -Dcamel.aws.vault.access.key, -Dcamel.aws.vault.secret.key and -Dcamel.aws.vault.region +// Must be manually tested. Provide your own accessKey and secretKey using -Dcamel.vault.aws.accessKey, -Dcamel.vault.aws.secretKey and -Dcamel.vault.aws.region @EnabledIfSystemProperties({ - @EnabledIfSystemProperty(named = "camel.aws.vault.access.key", matches = ".*", + @EnabledIfSystemProperty(named = "camel.vault.aws.accessKey", matches = ".*", disabledReason = "Access key not provided"), - @EnabledIfSystemProperty(named = "camel.aws.vault.secret.key", matches = ".*", + @EnabledIfSystemProperty(named = "camel.vault.aws.secretKey", matches = ".*", disabledReason = "Secret key not provided"), - @EnabledIfSystemProperty(named = "camel.aws.vault.region", matches = ".*", disabledReason = "Region not provided"), + @EnabledIfSystemProperty(named = "camel.vault.aws.region", matches = ".*", disabledReason = "Region not provided"), }) public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport { @Test public void testFunction() throws Exception { - context.getPropertiesComponent().setOverrideProperties( - propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"), - "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"), - "camel.aws.vault.region", System.getProperty("camel.aws.vault.region"))); + context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey")); + context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey")); + context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region")); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { @@ -59,10 +57,9 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport @Test public void testComplexPropertiesFunction() throws Exception { - context.getPropertiesComponent().setOverrideProperties( - propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"), - "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"), - "camel.aws.vault.region", System.getProperty("camel.aws.vault.region"))); + context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey")); + context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey")); + context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region")); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { @@ -81,10 +78,9 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport @Test public void testComplexCustomPropertiesFunction() throws Exception { - context.getPropertiesComponent().setOverrideProperties( - propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"), - "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"), - "camel.aws.vault.region", System.getProperty("camel.aws.vault.region"))); + context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey")); + context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey")); + context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region")); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { @@ -103,10 +99,9 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport @Test public void testSecretNotFoundFunction() throws Exception { - context.getPropertiesComponent().setOverrideProperties( - propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"), - "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"), - "camel.aws.vault.region", System.getProperty("camel.aws.vault.region"))); + context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey")); + context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey")); + context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region")); Exception exception = assertThrows(FailedToCreateRouteException.class, () -> { context.addRoutes(new RouteBuilder() { @Override @@ -126,10 +121,9 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport @Test public void testComplexNoSubkeyPropertiesFunction() throws Exception { - context.getPropertiesComponent().setOverrideProperties( - propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"), - "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"), - "camel.aws.vault.region", System.getProperty("camel.aws.vault.region"))); + context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey")); + context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey")); + context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region")); Exception exception = assertThrows(FailedToCreateRouteException.class, () -> { context.addRoutes(new RouteBuilder() { @Override