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
The following commit(s) were added to refs/heads/master by this push:
new 2634964 CAMEL-14850 - Camel-AWS2-*: Improve the verifiers to check if
a particular service works on a specified region, EC2
2634964 is described below
commit 263496492ee208499f9195ad7769141d366ccc35
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Apr 6 16:50:33 2020 +0200
CAMEL-14850 - Camel-AWS2-*: Improve the verifiers to check if a particular
service works on a specified region, EC2
---
.../aws2/ec2/AWS2EC2ComponentVerifierExtension.java | 4 ++++
.../aws2/ec2/EC2ComponentVerifierExtensionTest.java | 17 +++++++++++++++++
2 files changed, 21 insertions(+)
diff --git
a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2ComponentVerifierExtension.java
b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2ComponentVerifierExtension.java
index a61daea..05dfed5 100644
---
a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2ComponentVerifierExtension.java
+++
b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2ComponentVerifierExtension.java
@@ -66,6 +66,10 @@ public class AWS2EC2ComponentVerifierExtension extends
DefaultComponentVerifierE
try {
AWS2EC2Configuration configuration = setProperties(new
AWS2EC2Configuration(), parameters);
+ if
(!Ec2Client.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());
Ec2ClientBuilder clientBuilder = Ec2Client.builder();
Ec2Client client =
clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred)).region(Region.of(configuration.getRegion())).build();
diff --git
a/components/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/EC2ComponentVerifierExtensionTest.java
b/components/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/EC2ComponentVerifierExtensionTest.java
index 6dc844b..7447776 100644
---
a/components/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/EC2ComponentVerifierExtensionTest.java
+++
b/components/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/EC2ComponentVerifierExtensionTest.java
@@ -70,5 +70,22 @@ public class EC2ComponentVerifierExtensionTest extends
CamelTestSupport {
assertEquals(ComponentVerifierExtension.Result.Status.ERROR,
result.getStatus());
}
+
+ @Test
+ public void testConnectivityAndRegion() throws Exception {
+ Component component = context().getComponent("aws2-ec2");
+ 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("label", "test");
+ parameters.put("operation",
AWS2EC2Operations.describeInstances.toString());
+
+ ComponentVerifierExtension.Result result =
verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
+
+ assertEquals(ComponentVerifierExtension.Result.Status.ERROR,
result.getStatus());
+ }
}