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 2021/05/27 12:53:13 UTC
[camel] 03/06: CAMEL-16465 - Camel-AWS: Add
useDefaultCredentialProvider option to all the components - Translate
Component
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 7bf25bd1b1eaa895fea1ead2821541de3c2ff3f6
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu May 27 14:37:58 2021 +0200
CAMEL-16465 - Camel-AWS: Add useDefaultCredentialProvider option to all the components - Translate Component
---
.../aws2/translate/Translate2Component.java | 4 +-
.../aws2/translate/Translate2Endpoint.java | 51 ++--------------------
.../translate/client/Translate2ClientFactory.java | 2 +-
3 files changed, 7 insertions(+), 50 deletions(-)
diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Component.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Component.java
index 56602fd..b8eeced 100644
--- a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Component.java
+++ b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Component.java
@@ -54,9 +54,9 @@ public class Translate2Component extends DefaultComponent {
Translate2Endpoint endpoint = new Translate2Endpoint(uri, this, configuration);
setProperties(endpoint, parameters);
- if (configuration.getTranslateClient() == null
+ if (!configuration.isUseDefaultCredentialsProvider() && configuration.getTranslateClient() == null
&& (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
- throw new IllegalArgumentException("Amazon translate client or accessKey and secretKey must be specified");
+ throw new IllegalArgumentException("useDefaultCredentialsProvider is set to false, Amazon translate client or accessKey and secretKey must be specified");
}
return endpoint;
}
diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Endpoint.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Endpoint.java
index 9dedb37..65c7bd5 100644
--- a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Endpoint.java
+++ b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Endpoint.java
@@ -23,6 +23,7 @@ import org.apache.camel.Component;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
+import org.apache.camel.component.aws2.translate.client.Translate2ClientFactory;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.support.ScheduledPollEndpoint;
@@ -70,7 +71,9 @@ public class Translate2Endpoint extends ScheduledPollEndpoint {
super.doStart();
translateClient
- = configuration.getTranslateClient() != null ? configuration.getTranslateClient() : createTranslateClient();
+ = configuration.getTranslateClient() != null
+ ? configuration.getTranslateClient()
+ : Translate2ClientFactory.getTranslateClient(configuration).getTranslateClient();
}
@Override
@@ -90,50 +93,4 @@ public class Translate2Endpoint extends ScheduledPollEndpoint {
public TranslateClient getTranslateClient() {
return translateClient;
}
-
- TranslateClient createTranslateClient() {
- TranslateClient client = null;
- TranslateClientBuilder clientBuilder = TranslateClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- boolean isClientConfigFound = false;
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- proxyConfig = ProxyConfiguration.builder();
- URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":"
- + configuration.getProxyPort());
- proxyConfig.endpoint(proxyEndpoint);
- httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build());
- isClientConfigFound = true;
- }
- if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
- AwsBasicCredentials cred = AwsBasicCredentials.create(configuration.getAccessKey(), configuration.getSecretKey());
- if (isClientConfigFound) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
- .credentialsProvider(StaticCredentialsProvider.create(cred));
- } else {
- clientBuilder = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred));
- }
- } else {
- if (!isClientConfigFound) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- SdkHttpClient ahc = ApacheHttpClient.builder().buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- clientBuilder.httpClient(ahc);
- }
- client = clientBuilder.build();
- return client;
- }
}
diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/client/Translate2ClientFactory.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/client/Translate2ClientFactory.java
index 9773fc0..ef9e9c7 100644
--- a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/client/Translate2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/client/Translate2ClientFactory.java
@@ -34,7 +34,7 @@ public final class Translate2ClientFactory {
* @param configuration configuration
* @return TranslateClient
*/
- public static Translate2InternalClient getStsClient(Translate2Configuration configuration) {
+ public static Translate2InternalClient getTranslateClient(Translate2Configuration configuration) {
return configuration.isUseDefaultCredentialsProvider()
? new Translate2ClientIAMOptimized(configuration) : new Translate2ClientStandardImpl(configuration);
}