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 2020/04/06 13:48:22 UTC

[camel] 01/02: CAMEL-14850 - Camel-AWS2-*: Improve the verifiers to check if a particular service works on a specified region, DynamoDB

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7b88469d4a74a30b86a6c78f44435f48bff5f595
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Apr 6 15:45:07 2020 +0200

    CAMEL-14850 - Camel-AWS2-*: Improve the verifiers to check if a particular service works on a specified region, DynamoDB
---
 .../aws2/ddb/Ddb2ComponentVerifierExtension.java          |  4 ++++
 .../aws2/ddb/DdbComponentVerifierExtensionTest.java       | 15 +++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2ComponentVerifierExtension.java b/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2ComponentVerifierExtension.java
index 2db09f4..375c725 100644
--- a/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2ComponentVerifierExtension.java
+++ b/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2ComponentVerifierExtension.java
@@ -79,6 +79,10 @@ public class Ddb2ComponentVerifierExtension extends DefaultComponentVerifierExte
 
         try {
             Ddb2Configuration configuration = setProperties(new Ddb2Configuration(), parameters);
+            if (!DynamoDbClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion()))) {
+                ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.ILLEGAL_PARAMETER, "The service is not supported in this region");
+                return builder.error(errorBuilder.build()).build();
+            }
             AwsBasicCredentials cred = AwsBasicCredentials.create(configuration.getAccessKey(), configuration.getSecretKey());
             DynamoDbClientBuilder clientBuilder = DynamoDbClient.builder();
             DynamoDbClient client = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred)).region(Region.of(configuration.getRegion())).build();
diff --git a/components/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/DdbComponentVerifierExtensionTest.java b/components/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/DdbComponentVerifierExtensionTest.java
index eac7b7e..96e1c92 100644
--- a/components/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/DdbComponentVerifierExtensionTest.java
+++ b/components/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/DdbComponentVerifierExtensionTest.java
@@ -69,4 +69,19 @@ public class DdbComponentVerifierExtensionTest extends CamelTestSupport {
         assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
     }
 
+    @Test
+    public void testConnectivityAndRegion() throws Exception {
+        Component component = context().getComponent("aws2-ddb");
+        ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
+
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("secretKey", "l");
+        parameters.put("accessKey", "k");
+        parameters.put("region", "l");
+        parameters.put("tableName", "test");
+
+        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
+
+        assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
+    }
 }