The client type
+ * @return The configured AWS async client
+ */
+ public static & SdkAsyncClientBuilder, C extends SdkClient> C buildAsyncClient(
+ AwsCommonConfiguration config,
+ Supplier builderSupplier) {
+ return buildAsyncClient(config, builderSupplier, null);
+ }
+
/**
* Resolve the appropriate credentials provider based on configuration.
*
diff --git a/components/camel-aws/camel-aws2-ddb/pom.xml b/components/camel-aws/camel-aws2-ddb/pom.xml
index 925560e3ac859..abfe8babe75c4 100644
--- a/components/camel-aws/camel-aws2-ddb/pom.xml
+++ b/components/camel-aws/camel-aws2-ddb/pom.xml
@@ -36,6 +36,10 @@
+
+ org.apache.camel
+ camel-aws-common
+
org.apache.camel
camel-support
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Configuration.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Configuration.java
index b52f15d06beee..e733f4eb84565 100644
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Configuration.java
+++ b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.ddb;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
@UriParams
-public class Ddb2Configuration implements Cloneable {
+public class Ddb2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath
@Metadata(required = true)
@@ -297,7 +298,7 @@ public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvid
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Endpoint.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Endpoint.java
index d89f38d4ac92f..e7babc7a82e7a 100644
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Endpoint.java
+++ b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Endpoint.java
@@ -88,7 +88,7 @@ public void doStart() throws Exception {
super.doStart();
ddbClient = configuration.getAmazonDDBClient() != null
- ? configuration.getAmazonDDBClient() : Ddb2ClientFactory.getDynamoDBClient(configuration).getDynamoDBClient();
+ ? configuration.getAmazonDDBClient() : Ddb2ClientFactory.getDynamoDBClient(configuration);
String tableName = getConfiguration().getTableName();
LOG.trace("Querying whether table [{}] already exists...", tableName);
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/Ddb2ClientFactory.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/Ddb2ClientFactory.java
index 571ba3d63a912..b4d3647d9ec52 100644
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/Ddb2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/Ddb2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.ddb.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.ddb.Ddb2Configuration;
-import org.apache.camel.component.aws2.ddb.client.impl.Ddb2ClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.ddb.client.impl.Ddb2ClientIAMProfileOptimizedImpl;
-import org.apache.camel.component.aws2.ddb.client.impl.Ddb2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ddb.client.impl.Ddb2ClientStandardImpl;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
/**
- * Factory class to return the correct type of AWS DynamoDB client.
+ * Factory class to create AWS DynamoDB clients using common configuration.
*/
public final class Ddb2ClientFactory {
@@ -31,20 +29,14 @@ private Ddb2ClientFactory() {
}
/**
- * Return the correct AWS DynamoDB client (based on remote vs local).
+ * Create a DynamoDB client based on configuration.
*
- * @param configuration configuration
- * @return DynamoDBClient
+ * @param configuration The DynamoDB configuration
+ * @return Configured DynamoDbClient
*/
- public static Ddb2InternalClient getDynamoDBClient(Ddb2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new Ddb2ClientIAMOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new Ddb2ClientIAMProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new Ddb2ClientSessionTokenImpl(configuration);
- } else {
- return new Ddb2ClientStandardImpl(configuration);
- }
+ public static DynamoDbClient getDynamoDBClient(Ddb2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ DynamoDbClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/Ddb2InternalClient.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/Ddb2InternalClient.java
deleted file mode 100644
index 3adaf24ba893e..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/Ddb2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.ddb.client;
-
-import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
-
-/**
- * Manage the required actions of an DynamoDB client for either local or remote.
- */
-public interface Ddb2InternalClient {
-
- /**
- * Returns an DynamoDb client after a factory method determines which one to return.
- *
- * @return DynamoDbClient DynamoDbClient
- */
- DynamoDbClient getDynamoDBClient();
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientIAMOptimizedImpl.java
deleted file mode 100644
index bf3db027d99a0..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.ddb.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ddb.Ddb2Configuration;
-import org.apache.camel.component.aws2.ddb.client.Ddb2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS DynamoDB client for all users to use (enabling temporary creds). This implementation is for remote
- * instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class Ddb2ClientIAMOptimizedImpl implements Ddb2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ddb2ClientIAMOptimizedImpl.class);
- private Ddb2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ddb2ClientIAMOptimizedImpl(Ddb2Configuration configuration) {
- LOG.trace("Creating an AWS DynamoDB client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the DynamoDB aws client that is used.
- *
- * @return DynamoDB Client.
- */
- @Override
- public DynamoDbClient getDynamoDBClient() {
- DynamoDbClient client = null;
- DynamoDbClientBuilder clientBuilder = DynamoDbClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index c1a75666f951d..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.ddb.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ddb.Ddb2Configuration;
-import org.apache.camel.component.aws2.ddb.client.Ddb2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS DynamoDB client for all users to use (enabling temporary creds). This implementation is for remote
- * instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class Ddb2ClientIAMProfileOptimizedImpl implements Ddb2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ddb2ClientIAMProfileOptimizedImpl.class);
- private Ddb2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ddb2ClientIAMProfileOptimizedImpl(Ddb2Configuration configuration) {
- LOG.trace("Creating an AWS DynamoDB client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the DynamoDB aws client that is used.
- *
- * @return DynamoDB Client.
- */
- @Override
- public DynamoDbClient getDynamoDBClient() {
- DynamoDbClient client = null;
- DynamoDbClientBuilder clientBuilder = DynamoDbClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientSessionTokenImpl.java
deleted file mode 100644
index be6fce1c6b390..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.ddb.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ddb.Ddb2Configuration;
-import org.apache.camel.component.aws2.ddb.client.Ddb2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS DynamoDB client for all users to use. This implementation is for local instances to use a static and
- * solid credential set.
- */
-public class Ddb2ClientSessionTokenImpl implements Ddb2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ddb2ClientSessionTokenImpl.class);
- private Ddb2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ddb2ClientSessionTokenImpl(Ddb2Configuration configuration) {
- LOG.trace("Creating an AWS DynamoDB manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the DynamoDB AWS client that is used.
- *
- * @return Amazon DynamoDB Client.
- */
- @Override
- public DynamoDbClient getDynamoDBClient() {
- DynamoDbClient client = null;
- DynamoDbClientBuilder clientBuilder = DynamoDbClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientStandardImpl.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientStandardImpl.java
deleted file mode 100644
index a4579fa41ff7e..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/client/impl/Ddb2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.ddb.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ddb.Ddb2Configuration;
-import org.apache.camel.component.aws2.ddb.client.Ddb2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
-import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS DynamoDB client for all users to use. This implementation is for local instances to use a static and
- * solid credential set.
- */
-public class Ddb2ClientStandardImpl implements Ddb2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ddb2ClientStandardImpl.class);
- private Ddb2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ddb2ClientStandardImpl(Ddb2Configuration configuration) {
- LOG.trace("Creating an AWS DynamoDB manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the DynamoDB AWS client that is used.
- *
- * @return Amazon DynamoDB Client.
- */
- @Override
- public DynamoDbClient getDynamoDBClient() {
- DynamoDbClient client = null;
- DynamoDbClientBuilder clientBuilder = DynamoDbClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamConfiguration.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamConfiguration.java
index 2c9b858b886e9..c7769a7175a1d 100644
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamConfiguration.java
+++ b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamConfiguration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.ddbstream;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
@UriParams
-public class Ddb2StreamConfiguration implements Cloneable {
+public class Ddb2StreamConfiguration implements Cloneable, AwsCommonConfiguration {
@UriPath(label = "consumer", description = "Name of the dynamodb table")
@Metadata(required = true)
@@ -196,7 +197,7 @@ public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvid
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamEndpoint.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamEndpoint.java
index c9c72c939c51a..c270c89f6f51c 100644
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamEndpoint.java
+++ b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamEndpoint.java
@@ -66,7 +66,7 @@ public void doStart() throws Exception {
ddbStreamClient = configuration.getAmazonDynamoDbStreamsClient() != null
? configuration.getAmazonDynamoDbStreamsClient()
- : Ddb2StreamClientFactory.getDynamoDBStreamClient(configuration).getDynamoDBStreamClient();
+ : Ddb2StreamClientFactory.getDynamoDBStreamClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/Ddb2StreamClientFactory.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/Ddb2StreamClientFactory.java
index 1f8579d62d071..b895349f29755 100644
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/Ddb2StreamClientFactory.java
+++ b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/Ddb2StreamClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.ddbstream.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.ddbstream.Ddb2StreamConfiguration;
-import org.apache.camel.component.aws2.ddbstream.client.impl.Ddb2StreamClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.ddbstream.client.impl.Ddb2StreamClientIAMProfileOptimizedImpl;
-import org.apache.camel.component.aws2.ddbstream.client.impl.Ddb2StreamClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ddbstream.client.impl.Ddb2StreamClientStandardImpl;
+import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
/**
- * Factory class to return the correct type of AWS DynamoDB client.
+ * Factory class to create AWS DynamoDB Streams clients using common configuration.
*/
public final class Ddb2StreamClientFactory {
@@ -31,20 +29,14 @@ private Ddb2StreamClientFactory() {
}
/**
- * Return the correct AWS DynamoDB client (based on remote vs local).
+ * Create a DynamoDB Streams client based on configuration.
*
- * @param configuration configuration
- * @return DynamoDBClient
+ * @param configuration The DynamoDB Streams configuration
+ * @return Configured DynamoDbStreamsClient
*/
- public static Ddb2StreamInternalClient getDynamoDBStreamClient(Ddb2StreamConfiguration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new Ddb2StreamClientIAMOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new Ddb2StreamClientIAMProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new Ddb2StreamClientSessionTokenImpl(configuration);
- } else {
- return new Ddb2StreamClientStandardImpl(configuration);
- }
+ public static DynamoDbStreamsClient getDynamoDBStreamClient(Ddb2StreamConfiguration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ DynamoDbStreamsClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/Ddb2StreamInternalClient.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/Ddb2StreamInternalClient.java
deleted file mode 100644
index 31c0f625289e3..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/Ddb2StreamInternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.ddbstream.client;
-
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
-
-/**
- * Manage the required actions of an DynamoDB Stream client for either local or remote.
- */
-public interface Ddb2StreamInternalClient {
-
- /**
- * Returns an DynamoDB Stream client after a factory method determines which one to return.
- *
- * @return DynamoDbClient DynamoDbClient
- */
- DynamoDbStreamsClient getDynamoDBStreamClient();
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientIAMOptimizedImpl.java
deleted file mode 100644
index 66365ad5cf61f..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.component.aws2.ddbstream.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ddbstream.Ddb2StreamConfiguration;
-import org.apache.camel.component.aws2.ddbstream.client.Ddb2StreamInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS DynamoDB client for all users to use (enabling temporary creds). This implementation is for remote
- * instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class Ddb2StreamClientIAMOptimizedImpl implements Ddb2StreamInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ddb2StreamClientIAMOptimizedImpl.class);
- private Ddb2StreamConfiguration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ddb2StreamClientIAMOptimizedImpl(Ddb2StreamConfiguration configuration) {
- LOG.trace(
- "Creating an AWS DynamoDB Streams client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the DynamoDB Streams aws client that is used.
- *
- * @return DynamoDB Streams Client.
- */
- @Override
- public DynamoDbStreamsClient getDynamoDBStreamClient() {
- DynamoDbStreamsClient client = null;
- DynamoDbStreamsClientBuilder clientBuilder = DynamoDbStreamsClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index c3bcab74da5bf..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.component.aws2.ddbstream.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ddbstream.Ddb2StreamConfiguration;
-import org.apache.camel.component.aws2.ddbstream.client.Ddb2StreamInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS DynamoDB client for all users to use (enabling temporary creds). This implementation is for remote
- * instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class Ddb2StreamClientIAMProfileOptimizedImpl implements Ddb2StreamInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ddb2StreamClientIAMProfileOptimizedImpl.class);
- private Ddb2StreamConfiguration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ddb2StreamClientIAMProfileOptimizedImpl(Ddb2StreamConfiguration configuration) {
- LOG.trace(
- "Creating an AWS DynamoDB Streams client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the DynamoDB Streams aws client that is used.
- *
- * @return DynamoDB Streams Client.
- */
- @Override
- public DynamoDbStreamsClient getDynamoDBStreamClient() {
- DynamoDbStreamsClient client = null;
- DynamoDbStreamsClientBuilder clientBuilder = DynamoDbStreamsClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientSessionTokenImpl.java
deleted file mode 100644
index e5142610b7a16..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.ddbstream.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ddbstream.Ddb2StreamConfiguration;
-import org.apache.camel.component.aws2.ddbstream.client.Ddb2StreamInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS DynamoDB Streams client for all users to use. This implementation is for local instances to use a
- * static and solid credential set.
- */
-public class Ddb2StreamClientSessionTokenImpl implements Ddb2StreamInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ddb2StreamClientSessionTokenImpl.class);
- private Ddb2StreamConfiguration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ddb2StreamClientSessionTokenImpl(Ddb2StreamConfiguration configuration) {
- LOG.trace("Creating an AWS DynamoDB Streams manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the DynamoDB Streams AWS client that is used.
- *
- * @return Amazon DynamoDB Streams Client.
- */
- @Override
- public DynamoDbStreamsClient getDynamoDBStreamClient() {
- DynamoDbStreamsClient client = null;
- DynamoDbStreamsClientBuilder clientBuilder = DynamoDbStreamsClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientStandardImpl.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientStandardImpl.java
deleted file mode 100644
index 07c179dae7000..0000000000000
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddbstream/client/impl/Ddb2StreamClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.ddbstream.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ddbstream.Ddb2StreamConfiguration;
-import org.apache.camel.component.aws2.ddbstream.client.Ddb2StreamInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
-import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS DynamoDB Streams client for all users to use. This implementation is for local instances to use a
- * static and solid credential set.
- */
-public class Ddb2StreamClientStandardImpl implements Ddb2StreamInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ddb2StreamClientStandardImpl.class);
- private Ddb2StreamConfiguration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ddb2StreamClientStandardImpl(Ddb2StreamConfiguration configuration) {
- LOG.trace("Creating an AWS DynamoDB Streams manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the DynamoDB Streams AWS client that is used.
- *
- * @return Amazon DynamoDB Streams Client.
- */
- @Override
- public DynamoDbStreamsClient getDynamoDBStreamClient() {
- DynamoDbStreamsClient client = null;
- DynamoDbStreamsClientBuilder clientBuilder = DynamoDbStreamsClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/Ddb2ClientFactoryTest.java b/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/Ddb2ClientFactoryTest.java
index 9de2924014639..7d563a14edc95 100644
--- a/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/Ddb2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/Ddb2ClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.ddb;
import org.apache.camel.component.aws2.ddb.client.Ddb2ClientFactory;
-import org.apache.camel.component.aws2.ddb.client.Ddb2InternalClient;
-import org.apache.camel.component.aws2.ddb.client.impl.Ddb2ClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.ddb.client.impl.Ddb2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ddb.client.impl.Ddb2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class Ddb2ClientFactoryTest {
@Test
- public void getStandardDdb2ClientDefault() {
+ public void getDdb2ClientWithDefaultCredentials() {
Ddb2Configuration ddb2Configuration = new Ddb2Configuration();
- Ddb2InternalClient ddb2Client = Ddb2ClientFactory.getDynamoDBClient(ddb2Configuration);
- assertTrue(ddb2Client instanceof Ddb2ClientStandardImpl);
+ ddb2Configuration.setUseDefaultCredentialsProvider(true);
+ ddb2Configuration.setRegion("eu-west-1");
+ DynamoDbClient ddbClient = Ddb2ClientFactory.getDynamoDBClient(ddb2Configuration);
+ assertNotNull(ddbClient);
+ ddbClient.close();
}
@Test
- public void getStandardDdb2Client() {
+ public void getDdb2ClientWithStaticCredentials() {
Ddb2Configuration ddb2Configuration = new Ddb2Configuration();
- ddb2Configuration.setUseDefaultCredentialsProvider(false);
- Ddb2InternalClient ddb2Client = Ddb2ClientFactory.getDynamoDBClient(ddb2Configuration);
- assertTrue(ddb2Client instanceof Ddb2ClientStandardImpl);
+ ddb2Configuration.setAccessKey("testAccessKey");
+ ddb2Configuration.setSecretKey("testSecretKey");
+ ddb2Configuration.setRegion("eu-west-1");
+ DynamoDbClient ddbClient = Ddb2ClientFactory.getDynamoDBClient(ddb2Configuration);
+ assertNotNull(ddbClient);
+ ddbClient.close();
}
@Test
- public void getIAMOptimizedDdb2Client() {
+ public void getDdb2ClientWithEndpointOverride() {
Ddb2Configuration ddb2Configuration = new Ddb2Configuration();
ddb2Configuration.setUseDefaultCredentialsProvider(true);
- Ddb2InternalClient ddb2Client = Ddb2ClientFactory.getDynamoDBClient(ddb2Configuration);
- assertTrue(ddb2Client instanceof Ddb2ClientIAMOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenDdb2Client() {
- Ddb2Configuration ddb2Configuration = new Ddb2Configuration();
- ddb2Configuration.setUseSessionCredentials(true);
- Ddb2InternalClient ddb2Client = Ddb2ClientFactory.getDynamoDBClient(ddb2Configuration);
- assertTrue(ddb2Client instanceof Ddb2ClientSessionTokenImpl);
+ ddb2Configuration.setRegion("eu-west-1");
+ ddb2Configuration.setOverrideEndpoint(true);
+ ddb2Configuration.setUriEndpointOverride("http://localhost:4566");
+ DynamoDbClient ddbClient = Ddb2ClientFactory.getDynamoDBClient(ddb2Configuration);
+ assertNotNull(ddbClient);
+ ddbClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamClientFactoryTest.java b/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamClientFactoryTest.java
index 3f65393676109..f520eb5e4e54e 100644
--- a/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddbstream/Ddb2StreamClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.ddbstream;
import org.apache.camel.component.aws2.ddbstream.client.Ddb2StreamClientFactory;
-import org.apache.camel.component.aws2.ddbstream.client.Ddb2StreamInternalClient;
-import org.apache.camel.component.aws2.ddbstream.client.impl.Ddb2StreamClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.ddbstream.client.impl.Ddb2StreamClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ddbstream.client.impl.Ddb2StreamClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.dynamodb.streams.DynamoDbStreamsClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class Ddb2StreamClientFactoryTest {
@Test
- public void getStandardDdb2StreamClientDefault() {
+ public void getDdb2StreamClientWithDefaultCredentials() {
Ddb2StreamConfiguration ddb2StreamConfiguration = new Ddb2StreamConfiguration();
- Ddb2StreamInternalClient ddb2StreamClient = Ddb2StreamClientFactory.getDynamoDBStreamClient(ddb2StreamConfiguration);
- assertTrue(ddb2StreamClient instanceof Ddb2StreamClientStandardImpl);
+ ddb2StreamConfiguration.setUseDefaultCredentialsProvider(true);
+ ddb2StreamConfiguration.setRegion("eu-west-1");
+ DynamoDbStreamsClient ddbStreamClient = Ddb2StreamClientFactory.getDynamoDBStreamClient(ddb2StreamConfiguration);
+ assertNotNull(ddbStreamClient);
+ ddbStreamClient.close();
}
@Test
- public void getStandardDdb2StreamClient() {
+ public void getDdb2StreamClientWithStaticCredentials() {
Ddb2StreamConfiguration ddb2StreamConfiguration = new Ddb2StreamConfiguration();
- ddb2StreamConfiguration.setUseDefaultCredentialsProvider(false);
- Ddb2StreamInternalClient ddb2StreamClient = Ddb2StreamClientFactory.getDynamoDBStreamClient(ddb2StreamConfiguration);
- assertTrue(ddb2StreamClient instanceof Ddb2StreamClientStandardImpl);
+ ddb2StreamConfiguration.setAccessKey("testAccessKey");
+ ddb2StreamConfiguration.setSecretKey("testSecretKey");
+ ddb2StreamConfiguration.setRegion("eu-west-1");
+ DynamoDbStreamsClient ddbStreamClient = Ddb2StreamClientFactory.getDynamoDBStreamClient(ddb2StreamConfiguration);
+ assertNotNull(ddbStreamClient);
+ ddbStreamClient.close();
}
@Test
- public void getIAMOptimizedDdb2StreamClient() {
+ public void getDdb2StreamClientWithEndpointOverride() {
Ddb2StreamConfiguration ddb2StreamConfiguration = new Ddb2StreamConfiguration();
ddb2StreamConfiguration.setUseDefaultCredentialsProvider(true);
- Ddb2StreamInternalClient ddb2StreamClient = Ddb2StreamClientFactory.getDynamoDBStreamClient(ddb2StreamConfiguration);
- assertTrue(ddb2StreamClient instanceof Ddb2StreamClientIAMOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenDdb2StreamClient() {
- Ddb2StreamConfiguration ddb2StreamConfiguration = new Ddb2StreamConfiguration();
- ddb2StreamConfiguration.setUseSessionCredentials(true);
- Ddb2StreamInternalClient ddb2StreamClient = Ddb2StreamClientFactory.getDynamoDBStreamClient(ddb2StreamConfiguration);
- assertTrue(ddb2StreamClient instanceof Ddb2StreamClientSessionTokenImpl);
+ ddb2StreamConfiguration.setRegion("eu-west-1");
+ ddb2StreamConfiguration.setOverrideEndpoint(true);
+ ddb2StreamConfiguration.setUriEndpointOverride("http://localhost:4566");
+ DynamoDbStreamsClient ddbStreamClient = Ddb2StreamClientFactory.getDynamoDBStreamClient(ddb2StreamConfiguration);
+ assertNotNull(ddbStreamClient);
+ ddbStreamClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-ec2/pom.xml b/components/camel-aws/camel-aws2-ec2/pom.xml
index 6854db09c0f04..ea5a0d78878d4 100644
--- a/components/camel-aws/camel-aws2-ec2/pom.xml
+++ b/components/camel-aws/camel-aws2-ec2/pom.xml
@@ -40,6 +40,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
software.amazon.awssdk
ec2
diff --git a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Configuration.java b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Configuration.java
index 10de36ec9a085..b10991139587d 100644
--- a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Configuration.java
+++ b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.ec2;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.ec2.Ec2Client;
@UriParams
-public class AWS2EC2Configuration implements Cloneable {
+public class AWS2EC2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Logical name")
@Metadata(required = true)
@@ -218,14 +219,16 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the EC2 client should expect to load credentials through a default credentials provider or to expect
* static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
+ @Override
public boolean isUseProfileCredentialsProvider() {
return useProfileCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Endpoint.java b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Endpoint.java
index 62595174e32c3..896549489e7d6 100644
--- a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Endpoint.java
+++ b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Endpoint.java
@@ -62,7 +62,7 @@ public void doStart() throws Exception {
super.doStart();
ec2Client = configuration.getAmazonEc2Client() != null
- ? configuration.getAmazonEc2Client() : AWS2EC2ClientFactory.getEc2Client(configuration).getEc2Client();
+ ? configuration.getAmazonEc2Client() : AWS2EC2ClientFactory.getEc2Client(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/AWS2EC2ClientFactory.java b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/AWS2EC2ClientFactory.java
index 04c710ff3cdab..c95e3430feba2 100644
--- a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/AWS2EC2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/AWS2EC2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.ec2.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.ec2.AWS2EC2Configuration;
-import org.apache.camel.component.aws2.ec2.client.impl.AWS2EC2ClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.ec2.client.impl.AWS2EC2ClientIAMProfileOptimizedImpl;
-import org.apache.camel.component.aws2.ec2.client.impl.AWS2EC2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ec2.client.impl.AWS2EC2ClientStandardImpl;
+import software.amazon.awssdk.services.ec2.Ec2Client;
/**
- * Factory class to return the correct type of AWS Athena client.
+ * Factory class to create AWS EC2 clients using common configuration.
*/
public final class AWS2EC2ClientFactory {
@@ -31,20 +29,14 @@ private AWS2EC2ClientFactory() {
}
/**
- * Return the correct AWS EC2 client (based on remote vs local).
+ * Create an EC2 client based on configuration.
*
- * @param configuration configuration
- * @return Ec2Client
+ * @param configuration The EC2 configuration
+ * @return Configured Ec2Client
*/
- public static AWS2EC2InternalClient getEc2Client(AWS2EC2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new AWS2EC2ClientIAMOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new AWS2EC2ClientIAMProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new AWS2EC2ClientSessionTokenImpl(configuration);
- } else {
- return new AWS2EC2ClientStandardImpl(configuration);
- }
+ public static Ec2Client getEc2Client(AWS2EC2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ Ec2Client::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/AWS2EC2InternalClient.java b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/AWS2EC2InternalClient.java
deleted file mode 100644
index ee83d110d63a7..0000000000000
--- a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/AWS2EC2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.ec2.client;
-
-import software.amazon.awssdk.services.ec2.Ec2Client;
-
-/**
- * Manage the required actions of an EC2 client for either local or remote.
- */
-public interface AWS2EC2InternalClient {
-
- /**
- * Returns an EC2 client after a factory method determines which one to return.
- *
- * @return Ec2Client Ec2Client
- */
- Ec2Client getEc2Client();
-}
diff --git a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientIAMOptimizedImpl.java
deleted file mode 100644
index 389acc93bb184..0000000000000
--- a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.ec2.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ec2.AWS2EC2Configuration;
-import org.apache.camel.component.aws2.ec2.client.AWS2EC2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ec2.Ec2Client;
-import software.amazon.awssdk.services.ec2.Ec2ClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EC2 client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class AWS2EC2ClientIAMOptimizedImpl implements AWS2EC2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(AWS2EC2ClientIAMOptimizedImpl.class);
- private AWS2EC2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public AWS2EC2ClientIAMOptimizedImpl(AWS2EC2Configuration configuration) {
- LOG.trace("Creating an AWS EC2 client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the EC2 aws client that is used.
- *
- * @return Ec2Client Client.
- */
- @Override
- public Ec2Client getEc2Client() {
- Ec2Client client = null;
- Ec2ClientBuilder clientBuilder = Ec2Client.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index 0a8986a6a2e37..0000000000000
--- a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.ec2.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ec2.AWS2EC2Configuration;
-import org.apache.camel.component.aws2.ec2.client.AWS2EC2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ec2.Ec2Client;
-import software.amazon.awssdk.services.ec2.Ec2ClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EC2 client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class AWS2EC2ClientIAMProfileOptimizedImpl implements AWS2EC2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(AWS2EC2ClientIAMProfileOptimizedImpl.class);
- private AWS2EC2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public AWS2EC2ClientIAMProfileOptimizedImpl(AWS2EC2Configuration configuration) {
- LOG.trace("Creating an AWS EC2 client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the EC2 aws client that is used.
- *
- * @return Ec2Client Client.
- */
- @Override
- public Ec2Client getEc2Client() {
- Ec2Client client = null;
- Ec2ClientBuilder clientBuilder = Ec2Client.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientSessionTokenImpl.java
deleted file mode 100644
index 8a0a96cd20d58..0000000000000
--- a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.ec2.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ec2.AWS2EC2Configuration;
-import org.apache.camel.component.aws2.ec2.client.AWS2EC2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ec2.Ec2Client;
-import software.amazon.awssdk.services.ec2.Ec2ClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EC2 client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class AWS2EC2ClientSessionTokenImpl implements AWS2EC2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(AWS2EC2ClientSessionTokenImpl.class);
- private AWS2EC2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public AWS2EC2ClientSessionTokenImpl(AWS2EC2Configuration configuration) {
- LOG.trace("Creating an AWS EC2 manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the EC2 AWS client that is used.
- *
- * @return Amazon EC2 Client.
- */
- @Override
- public Ec2Client getEc2Client() {
- Ec2Client client = null;
- Ec2ClientBuilder clientBuilder = Ec2Client.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientStandardImpl.java b/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientStandardImpl.java
deleted file mode 100644
index 2848af0136fbe..0000000000000
--- a/components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/client/impl/AWS2EC2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.ec2.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ec2.AWS2EC2Configuration;
-import org.apache.camel.component.aws2.ec2.client.AWS2EC2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ec2.Ec2Client;
-import software.amazon.awssdk.services.ec2.Ec2ClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EC2 client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class AWS2EC2ClientStandardImpl implements AWS2EC2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(AWS2EC2ClientStandardImpl.class);
- private AWS2EC2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public AWS2EC2ClientStandardImpl(AWS2EC2Configuration configuration) {
- LOG.trace("Creating an AWS EC2 manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the EC2 AWS client that is used.
- *
- * @return Amazon EC2 Client.
- */
- @Override
- public Ec2Client getEc2Client() {
- Ec2Client client = null;
- Ec2ClientBuilder clientBuilder = Ec2Client.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/AWS2EC2ClientFactoryTest.java b/components/camel-aws/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/AWS2EC2ClientFactoryTest.java
index 41691844e79f4..635d1d4caa989 100644
--- a/components/camel-aws/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/AWS2EC2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-ec2/src/test/java/org/apache/camel/component/aws2/ec2/AWS2EC2ClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.ec2;
import org.apache.camel.component.aws2.ec2.client.AWS2EC2ClientFactory;
-import org.apache.camel.component.aws2.ec2.client.AWS2EC2InternalClient;
-import org.apache.camel.component.aws2.ec2.client.impl.AWS2EC2ClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.ec2.client.impl.AWS2EC2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ec2.client.impl.AWS2EC2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.ec2.Ec2Client;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class AWS2EC2ClientFactoryTest {
@Test
- public void getStandardEC2ClientDefault() {
- AWS2EC2Configuration ec2Configuration = new AWS2EC2Configuration();
- AWS2EC2InternalClient ec2Client = AWS2EC2ClientFactory.getEc2Client(ec2Configuration);
- assertTrue(ec2Client instanceof AWS2EC2ClientStandardImpl);
+ public void getEc2ClientWithDefaultCredentials() {
+ AWS2EC2Configuration configuration = new AWS2EC2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ Ec2Client ec2Client = AWS2EC2ClientFactory.getEc2Client(configuration);
+ assertNotNull(ec2Client);
+ ec2Client.close();
}
@Test
- public void getStandardEC2Client() {
- AWS2EC2Configuration ec2Configuration = new AWS2EC2Configuration();
- ec2Configuration.setUseDefaultCredentialsProvider(false);
- AWS2EC2InternalClient ec2Client = AWS2EC2ClientFactory.getEc2Client(ec2Configuration);
- assertTrue(ec2Client instanceof AWS2EC2ClientStandardImpl);
+ public void getEc2ClientWithStaticCredentials() {
+ AWS2EC2Configuration configuration = new AWS2EC2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ Ec2Client ec2Client = AWS2EC2ClientFactory.getEc2Client(configuration);
+ assertNotNull(ec2Client);
+ ec2Client.close();
}
@Test
- public void getIAMOptimizedEC2Client() {
- AWS2EC2Configuration ec2Configuration = new AWS2EC2Configuration();
- ec2Configuration.setUseDefaultCredentialsProvider(true);
- AWS2EC2InternalClient ec2Client = AWS2EC2ClientFactory.getEc2Client(ec2Configuration);
- assertTrue(ec2Client instanceof AWS2EC2ClientIAMOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenEC2Client() {
- AWS2EC2Configuration ec2Configuration = new AWS2EC2Configuration();
- ec2Configuration.setUseSessionCredentials(true);
- AWS2EC2InternalClient ec2Client = AWS2EC2ClientFactory.getEc2Client(ec2Configuration);
- assertTrue(ec2Client instanceof AWS2EC2ClientSessionTokenImpl);
+ public void getEc2ClientWithEndpointOverride() {
+ AWS2EC2Configuration configuration = new AWS2EC2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ Ec2Client ec2Client = AWS2EC2ClientFactory.getEc2Client(configuration);
+ assertNotNull(ec2Client);
+ ec2Client.close();
}
}
diff --git a/components/camel-aws/camel-aws2-ecs/pom.xml b/components/camel-aws/camel-aws2-ecs/pom.xml
index 49b2ca4eec3d3..cb97efb7095f0 100644
--- a/components/camel-aws/camel-aws2-ecs/pom.xml
+++ b/components/camel-aws/camel-aws2-ecs/pom.xml
@@ -40,6 +40,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
software.amazon.awssdk
ecs
diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Configuration.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Configuration.java
index c5a96af4b9631..8a4adbcf28d76 100644
--- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Configuration.java
+++ b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.ecs;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.ecs.EcsClient;
@UriParams
-public class ECS2Configuration implements Cloneable {
+public class ECS2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Logical name")
@Metadata(required = true)
@@ -217,14 +218,16 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the ECS client should expect to load credentials through a default credentials provider or to expect
* static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
+ @Override
public boolean isUseProfileCredentialsProvider() {
return useProfileCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Endpoint.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Endpoint.java
index 4d685b6b4a6fe..34a99d95de93f 100644
--- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Endpoint.java
+++ b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/ECS2Endpoint.java
@@ -67,7 +67,7 @@ public void doStart() throws Exception {
super.doStart();
ecsClient = configuration.getEcsClient() != null
- ? configuration.getEcsClient() : ECS2ClientFactory.getEcsClient(configuration).getEcsClient();
+ ? configuration.getEcsClient() : ECS2ClientFactory.getEcsClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/ECS2ClientFactory.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/ECS2ClientFactory.java
index 8e6848498cd86..494a5ebce7639 100644
--- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/ECS2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/ECS2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.ecs.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.ecs.ECS2Configuration;
-import org.apache.camel.component.aws2.ecs.client.impl.ECS2ClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.ecs.client.impl.ECS2ClientIAMProfileOptimizedImpl;
-import org.apache.camel.component.aws2.ecs.client.impl.ECS2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ecs.client.impl.ECS2ClientStandardImpl;
+import software.amazon.awssdk.services.ecs.EcsClient;
/**
- * Factory class to return the correct type of AWS Athena client.
+ * Factory class to create AWS ECS clients using common configuration.
*/
public final class ECS2ClientFactory {
@@ -31,20 +29,14 @@ private ECS2ClientFactory() {
}
/**
- * Return the correct AWS ECS client (based on remote vs local).
+ * Create an ECS client based on configuration.
*
- * @param configuration configuration
- * @return EcsClient
+ * @param configuration The ECS configuration
+ * @return Configured EcsClient
*/
- public static ECS2InternalClient getEcsClient(ECS2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new ECS2ClientIAMOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new ECS2ClientIAMProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new ECS2ClientSessionTokenImpl(configuration);
- } else {
- return new ECS2ClientStandardImpl(configuration);
- }
+ public static EcsClient getEcsClient(ECS2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ EcsClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/ECS2InternalClient.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/ECS2InternalClient.java
deleted file mode 100644
index 52ba959d028b6..0000000000000
--- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/ECS2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.ecs.client;
-
-import software.amazon.awssdk.services.ecs.EcsClient;
-
-/**
- * Manage the required actions of an ECS client for either local or remote.
- */
-public interface ECS2InternalClient {
-
- /**
- * Returns an ECS client after a factory method determines which one to return.
- *
- * @return EcSClient EcSClient
- */
- EcsClient getEcsClient();
-}
diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientIAMOptimizedImpl.java
deleted file mode 100644
index 315f2f8d86342..0000000000000
--- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.ecs.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ecs.ECS2Configuration;
-import org.apache.camel.component.aws2.ecs.client.ECS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ecs.EcsClient;
-import software.amazon.awssdk.services.ecs.EcsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS ECS client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class ECS2ClientIAMOptimizedImpl implements ECS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(ECS2ClientIAMOptimizedImpl.class);
- private ECS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public ECS2ClientIAMOptimizedImpl(ECS2Configuration configuration) {
- LOG.trace("Creating an AWS ECS client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the ECS aws client that is used.
- *
- * @return EcsClient Client.
- */
- @Override
- public EcsClient getEcsClient() {
- EcsClient client = null;
- EcsClientBuilder clientBuilder = EcsClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index ea44b4409cfbe..0000000000000
--- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.ecs.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ecs.ECS2Configuration;
-import org.apache.camel.component.aws2.ecs.client.ECS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ecs.EcsClient;
-import software.amazon.awssdk.services.ecs.EcsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS ECS client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class ECS2ClientIAMProfileOptimizedImpl implements ECS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(ECS2ClientIAMProfileOptimizedImpl.class);
- private ECS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public ECS2ClientIAMProfileOptimizedImpl(ECS2Configuration configuration) {
- LOG.trace("Creating an AWS ECS client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the ECS aws client that is used.
- *
- * @return EcsClient Client.
- */
- @Override
- public EcsClient getEcsClient() {
- EcsClient client = null;
- EcsClientBuilder clientBuilder = EcsClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientSessionTokenImpl.java
deleted file mode 100644
index 8c59f90b81485..0000000000000
--- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.ecs.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ecs.ECS2Configuration;
-import org.apache.camel.component.aws2.ecs.client.ECS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ecs.EcsClient;
-import software.amazon.awssdk.services.ecs.EcsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS ECS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class ECS2ClientSessionTokenImpl implements ECS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(ECS2ClientStandardImpl.class);
- private ECS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public ECS2ClientSessionTokenImpl(ECS2Configuration configuration) {
- LOG.trace("Creating an AWS ECS manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the ECS AWS client that is used.
- *
- * @return Amazon ECS Client.
- */
- @Override
- public EcsClient getEcsClient() {
- EcsClient client = null;
- EcsClientBuilder clientBuilder = EcsClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientStandardImpl.java b/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientStandardImpl.java
deleted file mode 100644
index 546f3f9b28665..0000000000000
--- a/components/camel-aws/camel-aws2-ecs/src/main/java/org/apache/camel/component/aws2/ecs/client/impl/ECS2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.ecs.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ecs.ECS2Configuration;
-import org.apache.camel.component.aws2.ecs.client.ECS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ecs.EcsClient;
-import software.amazon.awssdk.services.ecs.EcsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS ECS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class ECS2ClientStandardImpl implements ECS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(ECS2ClientStandardImpl.class);
- private ECS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public ECS2ClientStandardImpl(ECS2Configuration configuration) {
- LOG.trace("Creating an AWS ECS manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the ECS AWS client that is used.
- *
- * @return Amazon ECS Client.
- */
- @Override
- public EcsClient getEcsClient() {
- EcsClient client = null;
- EcsClientBuilder clientBuilder = EcsClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ecs/src/test/java/org/apache/camel/component/aws2/ecs/ECS2ClientFactoryTest.java b/components/camel-aws/camel-aws2-ecs/src/test/java/org/apache/camel/component/aws2/ecs/ECS2ClientFactoryTest.java
index 0a152d8f9f9f5..f748a68b6458f 100644
--- a/components/camel-aws/camel-aws2-ecs/src/test/java/org/apache/camel/component/aws2/ecs/ECS2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-ecs/src/test/java/org/apache/camel/component/aws2/ecs/ECS2ClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.ecs;
import org.apache.camel.component.aws2.ecs.client.ECS2ClientFactory;
-import org.apache.camel.component.aws2.ecs.client.ECS2InternalClient;
-import org.apache.camel.component.aws2.ecs.client.impl.ECS2ClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.ecs.client.impl.ECS2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ecs.client.impl.ECS2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.ecs.EcsClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class ECS2ClientFactoryTest {
@Test
- public void getStandardECS2ClientDefault() {
- ECS2Configuration ec2Configuration = new ECS2Configuration();
- ECS2InternalClient ec2Client = ECS2ClientFactory.getEcsClient(ec2Configuration);
- assertTrue(ec2Client instanceof ECS2ClientStandardImpl);
+ public void getEcsClientWithDefaultCredentials() {
+ ECS2Configuration configuration = new ECS2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ EcsClient ecsClient = ECS2ClientFactory.getEcsClient(configuration);
+ assertNotNull(ecsClient);
+ ecsClient.close();
}
@Test
- public void getStandardECS2Client() {
- ECS2Configuration ec2Configuration = new ECS2Configuration();
- ec2Configuration.setUseDefaultCredentialsProvider(false);
- ECS2InternalClient ec2Client = ECS2ClientFactory.getEcsClient(ec2Configuration);
- assertTrue(ec2Client instanceof ECS2ClientStandardImpl);
+ public void getEcsClientWithStaticCredentials() {
+ ECS2Configuration configuration = new ECS2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ EcsClient ecsClient = ECS2ClientFactory.getEcsClient(configuration);
+ assertNotNull(ecsClient);
+ ecsClient.close();
}
@Test
- public void getIAMOptimizedECS2Client() {
- ECS2Configuration ec2Configuration = new ECS2Configuration();
- ec2Configuration.setUseDefaultCredentialsProvider(true);
- ECS2InternalClient ec2Client = ECS2ClientFactory.getEcsClient(ec2Configuration);
- assertTrue(ec2Client instanceof ECS2ClientIAMOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenECS2Client() {
- ECS2Configuration ec2Configuration = new ECS2Configuration();
- ec2Configuration.setUseSessionCredentials(true);
- ECS2InternalClient ec2Client = ECS2ClientFactory.getEcsClient(ec2Configuration);
- assertTrue(ec2Client instanceof ECS2ClientSessionTokenImpl);
+ public void getEcsClientWithEndpointOverride() {
+ ECS2Configuration configuration = new ECS2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ EcsClient ecsClient = ECS2ClientFactory.getEcsClient(configuration);
+ assertNotNull(ecsClient);
+ ecsClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-eks/pom.xml b/components/camel-aws/camel-aws2-eks/pom.xml
index 88641f4e6909d..5b6a132898c6d 100644
--- a/components/camel-aws/camel-aws2-eks/pom.xml
+++ b/components/camel-aws/camel-aws2-eks/pom.xml
@@ -40,6 +40,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
software.amazon.awssdk
eks
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Configuration.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Configuration.java
index e05b4c594278d..44322f9059458 100644
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Configuration.java
+++ b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.eks;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.eks.EksClient;
@UriParams
-public class EKS2Configuration implements Cloneable {
+public class EKS2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Logical name")
@Metadata(required = true)
@@ -216,14 +217,16 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the EKS client should expect to load credentials through a default credentials provider or to expect
* static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
+ @Override
public boolean isUseProfileCredentialsProvider() {
return useProfileCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Endpoint.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Endpoint.java
index ea54c814f8bec..5ca1727beb9d2 100644
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Endpoint.java
+++ b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Endpoint.java
@@ -67,7 +67,7 @@ public void doStart() throws Exception {
super.doStart();
eksClient = configuration.getEksClient() != null
- ? configuration.getEksClient() : EKS2ClientFactory.getEksClient(configuration).getEksClient();
+ ? configuration.getEksClient() : EKS2ClientFactory.getEksClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/EKS2ClientFactory.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/EKS2ClientFactory.java
index 58e1f0d697f48..ded08760b7a87 100644
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/EKS2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/EKS2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.eks.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.eks.EKS2Configuration;
-import org.apache.camel.component.aws2.eks.client.impl.EKS2ClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.eks.client.impl.EKS2ClientIAMProfileOptimizedImpl;
-import org.apache.camel.component.aws2.eks.client.impl.EKS2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.eks.client.impl.EKS2ClientStandardImpl;
+import software.amazon.awssdk.services.eks.EksClient;
/**
- * Factory class to return the correct type of AWS EKS client.
+ * Factory class to create AWS EKS clients using common configuration.
*/
public final class EKS2ClientFactory {
@@ -31,20 +29,14 @@ private EKS2ClientFactory() {
}
/**
- * Return the correct AWS EKS client (based on remote vs local).
+ * Create an EKS client based on configuration.
*
- * @param configuration configuration
- * @return EKSClient
+ * @param configuration The EKS configuration
+ * @return Configured EksClient
*/
- public static EKS2InternalClient getEksClient(EKS2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new EKS2ClientIAMOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new EKS2ClientIAMProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new EKS2ClientSessionTokenImpl(configuration);
- } else {
- return new EKS2ClientStandardImpl(configuration);
- }
+ public static EksClient getEksClient(EKS2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ EksClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/EKS2InternalClient.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/EKS2InternalClient.java
deleted file mode 100644
index 2929d7f3c5196..0000000000000
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/EKS2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.eks.client;
-
-import software.amazon.awssdk.services.eks.EksClient;
-
-/**
- * Manage the required actions of an EKS client for either local or remote.
- */
-public interface EKS2InternalClient {
-
- /**
- * Returns an EKS client after a factory method determines which one to return.
- *
- * @return EksClient EksClient
- */
- EksClient getEksClient();
-}
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientIAMOptimizedImpl.java
deleted file mode 100644
index 83e1cce109760..0000000000000
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.eks.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.eks.EKS2Configuration;
-import org.apache.camel.component.aws2.eks.client.EKS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.eks.EksClient;
-import software.amazon.awssdk.services.eks.EksClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EKS client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class EKS2ClientIAMOptimizedImpl implements EKS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(EKS2ClientIAMOptimizedImpl.class);
- private EKS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public EKS2ClientIAMOptimizedImpl(EKS2Configuration configuration) {
- LOG.trace("Creating an AWS EKS client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the EKS aws client that is used.
- *
- * @return EcsClient Client.
- */
- @Override
- public EksClient getEksClient() {
- EksClient client = null;
- EksClientBuilder clientBuilder = EksClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index 1b441e95697a7..0000000000000
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.eks.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.eks.EKS2Configuration;
-import org.apache.camel.component.aws2.eks.client.EKS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.eks.EksClient;
-import software.amazon.awssdk.services.eks.EksClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EKS client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class EKS2ClientIAMProfileOptimizedImpl implements EKS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(EKS2ClientIAMProfileOptimizedImpl.class);
- private EKS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public EKS2ClientIAMProfileOptimizedImpl(EKS2Configuration configuration) {
- LOG.trace("Creating an AWS EKS client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the EKS aws client that is used.
- *
- * @return EcsClient Client.
- */
- @Override
- public EksClient getEksClient() {
- EksClient client = null;
- EksClientBuilder clientBuilder = EksClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientSessionTokenImpl.java
deleted file mode 100644
index 8645f3ab50550..0000000000000
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.eks.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.eks.EKS2Configuration;
-import org.apache.camel.component.aws2.eks.client.EKS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.eks.EksClient;
-import software.amazon.awssdk.services.eks.EksClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EKS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class EKS2ClientSessionTokenImpl implements EKS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(EKS2ClientSessionTokenImpl.class);
- private EKS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public EKS2ClientSessionTokenImpl(EKS2Configuration configuration) {
- LOG.trace("Creating an AWS EKS manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the EKS AWS client that is used.
- *
- * @return Amazon EKS Client.
- */
- @Override
- public EksClient getEksClient() {
- EksClient client = null;
- EksClientBuilder clientBuilder = EksClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientStandardImpl.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientStandardImpl.java
deleted file mode 100644
index 22d4011d129c2..0000000000000
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/client/impl/EKS2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.eks.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.eks.EKS2Configuration;
-import org.apache.camel.component.aws2.eks.client.EKS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.eks.EksClient;
-import software.amazon.awssdk.services.eks.EksClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EKS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class EKS2ClientStandardImpl implements EKS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(EKS2ClientStandardImpl.class);
- private EKS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public EKS2ClientStandardImpl(EKS2Configuration configuration) {
- LOG.trace("Creating an AWS EKS manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the EKS AWS client that is used.
- *
- * @return Amazon EKS Client.
- */
- @Override
- public EksClient getEksClient() {
- EksClient client = null;
- EksClientBuilder clientBuilder = EksClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ClientFactoryTest.java b/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ClientFactoryTest.java
index f2222e79c0609..238ecc63ded6f 100644
--- a/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.eks;
import org.apache.camel.component.aws2.eks.client.EKS2ClientFactory;
-import org.apache.camel.component.aws2.eks.client.EKS2InternalClient;
-import org.apache.camel.component.aws2.eks.client.impl.EKS2ClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.eks.client.impl.EKS2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.eks.client.impl.EKS2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.eks.EksClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class EKS2ClientFactoryTest {
@Test
- public void getStandardEKS2ClientDefault() {
- EKS2Configuration eks2Configuration = new EKS2Configuration();
- EKS2InternalClient eks2Client = EKS2ClientFactory.getEksClient(eks2Configuration);
- assertTrue(eks2Client instanceof EKS2ClientStandardImpl);
+ public void getEksClientWithDefaultCredentials() {
+ EKS2Configuration configuration = new EKS2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ EksClient eksClient = EKS2ClientFactory.getEksClient(configuration);
+ assertNotNull(eksClient);
+ eksClient.close();
}
@Test
- public void getStandardEKS2Client() {
- EKS2Configuration eks2Configuration = new EKS2Configuration();
- eks2Configuration.setUseDefaultCredentialsProvider(false);
- EKS2InternalClient eks2Client = EKS2ClientFactory.getEksClient(eks2Configuration);
- assertTrue(eks2Client instanceof EKS2ClientStandardImpl);
+ public void getEksClientWithStaticCredentials() {
+ EKS2Configuration configuration = new EKS2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ EksClient eksClient = EKS2ClientFactory.getEksClient(configuration);
+ assertNotNull(eksClient);
+ eksClient.close();
}
@Test
- public void getIAMOptimizedEKS2Client() {
- EKS2Configuration eks2Configuration = new EKS2Configuration();
- eks2Configuration.setUseDefaultCredentialsProvider(true);
- EKS2InternalClient eks2Client = EKS2ClientFactory.getEksClient(eks2Configuration);
- assertTrue(eks2Client instanceof EKS2ClientIAMOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenEKS2Client() {
- EKS2Configuration eks2Configuration = new EKS2Configuration();
- eks2Configuration.setUseSessionCredentials(true);
- EKS2InternalClient eks2Client = EKS2ClientFactory.getEksClient(eks2Configuration);
- assertTrue(eks2Client instanceof EKS2ClientSessionTokenImpl);
+ public void getEksClientWithEndpointOverride() {
+ EKS2Configuration configuration = new EKS2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ EksClient eksClient = EKS2ClientFactory.getEksClient(configuration);
+ assertNotNull(eksClient);
+ eksClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-iam/pom.xml b/components/camel-aws/camel-aws2-iam/pom.xml
index 69f8731e5b5bd..9dcdc0c25fc09 100644
--- a/components/camel-aws/camel-aws2-iam/pom.xml
+++ b/components/camel-aws/camel-aws2-iam/pom.xml
@@ -40,6 +40,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
software.amazon.awssdk
iam
diff --git a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Configuration.java b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Configuration.java
index 386398198f4d1..96bbe1d299554 100644
--- a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Configuration.java
+++ b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.iam;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -26,7 +27,7 @@
import software.amazon.awssdk.services.iam.IamClient;
@UriParams
-public class IAM2Configuration implements Cloneable {
+public class IAM2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Logical name")
@Metadata(required = true)
@@ -220,14 +221,16 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the IAM client should expect to load credentials through a default credentials provider or to expect
* static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
+ @Override
public boolean isUseProfileCredentialsProvider() {
return useProfileCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Endpoint.java b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Endpoint.java
index e26247fa21cbb..9b7e51eff70b0 100644
--- a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Endpoint.java
+++ b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Endpoint.java
@@ -68,7 +68,7 @@ public void doStart() throws Exception {
iamClient = configuration.getIamClient() != null
? configuration.getIamClient()
- : IAM2ClientFactory.getIamClient(configuration).getIamClient();
+ : IAM2ClientFactory.getIamClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/IAM2ClientFactory.java b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/IAM2ClientFactory.java
index 2f7fbc21bb10a..9381a1f483060 100644
--- a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/IAM2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/IAM2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.iam.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.iam.IAM2Configuration;
-import org.apache.camel.component.aws2.iam.client.impl.IAM2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.iam.client.impl.IAM2ClientProfileOptimizedImpl;
-import org.apache.camel.component.aws2.iam.client.impl.IAM2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.iam.client.impl.IAM2ClientStandardImpl;
+import software.amazon.awssdk.services.iam.IamClient;
/**
- * Factory class to return the correct type of AWS IAM client.
+ * Factory class to create AWS IAM clients using common configuration.
*/
public final class IAM2ClientFactory {
@@ -31,20 +29,14 @@ private IAM2ClientFactory() {
}
/**
- * Return the correct AWS IAM client (based on remote vs local).
+ * Create an IAM client based on configuration.
*
- * @param configuration configuration
- * @return IamClient
+ * @param configuration The IAM configuration
+ * @return Configured IamClient
*/
- public static IAM2InternalClient getIamClient(IAM2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new IAM2ClientOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new IAM2ClientProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new IAM2ClientSessionTokenImpl(configuration);
- } else {
- return new IAM2ClientStandardImpl(configuration);
- }
+ public static IamClient getIamClient(IAM2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ IamClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/IAM2InternalClient.java b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/IAM2InternalClient.java
deleted file mode 100644
index 198448ef43ad6..0000000000000
--- a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/IAM2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.iam.client;
-
-import software.amazon.awssdk.services.iam.IamClient;
-
-/**
- * Manage the required actions of an IAM client for either local or remote.
- */
-public interface IAM2InternalClient {
-
- /**
- * Returns an IAM client after a factory method determines which one to return.
- *
- * @return IamClient IamClient
- */
- IamClient getIamClient();
-}
diff --git a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientOptimizedImpl.java b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientOptimizedImpl.java
deleted file mode 100644
index e0f5db754c949..0000000000000
--- a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.iam.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.iam.IAM2Configuration;
-import org.apache.camel.component.aws2.iam.client.IAM2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.iam.IamClient;
-import software.amazon.awssdk.services.iam.IamClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS IAM client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class IAM2ClientOptimizedImpl implements IAM2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(IAM2ClientOptimizedImpl.class);
- private IAM2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public IAM2ClientOptimizedImpl(IAM2Configuration configuration) {
- LOG.trace("Creating an AWS IAM client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the IAM aws client that is used.
- *
- * @return IAM Client.
- */
- @Override
- public IamClient getIamClient() {
- IamClient client = null;
- IamClientBuilder clientBuilder = IamClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientProfileOptimizedImpl.java
deleted file mode 100644
index de0c4498ec052..0000000000000
--- a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.iam.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.iam.IAM2Configuration;
-import org.apache.camel.component.aws2.iam.client.IAM2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.iam.IamClient;
-import software.amazon.awssdk.services.iam.IamClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS IAM client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class IAM2ClientProfileOptimizedImpl implements IAM2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(IAM2ClientProfileOptimizedImpl.class);
- private IAM2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public IAM2ClientProfileOptimizedImpl(IAM2Configuration configuration) {
- LOG.trace("Creating an AWS IAM client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the IAM aws client that is used.
- *
- * @return IAM Client.
- */
- @Override
- public IamClient getIamClient() {
- IamClient client = null;
- IamClientBuilder clientBuilder = IamClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientSessionTokenImpl.java
deleted file mode 100644
index ac1355b344c1b..0000000000000
--- a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.iam.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.iam.IAM2Configuration;
-import org.apache.camel.component.aws2.iam.client.IAM2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.iam.IamClient;
-import software.amazon.awssdk.services.iam.IamClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EKS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class IAM2ClientSessionTokenImpl implements IAM2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(IAM2ClientStandardImpl.class);
- private IAM2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public IAM2ClientSessionTokenImpl(IAM2Configuration configuration) {
- LOG.trace("Creating an AWS IAM manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the IAM AWS client that is used.
- *
- * @return Amazon IAM Client.
- */
- @Override
- public IamClient getIamClient() {
- IamClient client = null;
- IamClientBuilder clientBuilder = IamClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientStandardImpl.java b/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientStandardImpl.java
deleted file mode 100644
index fbb6d9b94f5fc..0000000000000
--- a/components/camel-aws/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/client/impl/IAM2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.iam.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.iam.IAM2Configuration;
-import org.apache.camel.component.aws2.iam.client.IAM2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.iam.IamClient;
-import software.amazon.awssdk.services.iam.IamClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS EKS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class IAM2ClientStandardImpl implements IAM2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(IAM2ClientStandardImpl.class);
- private IAM2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public IAM2ClientStandardImpl(IAM2Configuration configuration) {
- LOG.trace("Creating an AWS IAM manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the IAM AWS client that is used.
- *
- * @return Amazon IAM Client.
- */
- @Override
- public IamClient getIamClient() {
- IamClient client = null;
- IamClientBuilder clientBuilder = IamClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-iam/src/test/java/org/apache/camel/component/aws2/iam/IAMClientFactoryTest.java b/components/camel-aws/camel-aws2-iam/src/test/java/org/apache/camel/component/aws2/iam/IAMClientFactoryTest.java
index ec283ebaf766d..4bf369411c74f 100644
--- a/components/camel-aws/camel-aws2-iam/src/test/java/org/apache/camel/component/aws2/iam/IAMClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-iam/src/test/java/org/apache/camel/component/aws2/iam/IAMClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.iam;
import org.apache.camel.component.aws2.iam.client.IAM2ClientFactory;
-import org.apache.camel.component.aws2.iam.client.IAM2InternalClient;
-import org.apache.camel.component.aws2.iam.client.impl.IAM2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.iam.client.impl.IAM2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.iam.client.impl.IAM2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.iam.IamClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class IAMClientFactoryTest {
@Test
- public void getStandardEIamClientDefault() {
- IAM2Configuration iam2Configuration = new IAM2Configuration();
- IAM2InternalClient iamClient = IAM2ClientFactory.getIamClient(iam2Configuration);
- assertTrue(iamClient instanceof IAM2ClientStandardImpl);
+ public void getIamClientWithDefaultCredentials() {
+ IAM2Configuration configuration = new IAM2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("aws-global");
+ IamClient iamClient = IAM2ClientFactory.getIamClient(configuration);
+ assertNotNull(iamClient);
+ iamClient.close();
}
@Test
- public void getStandardIamClient() {
- IAM2Configuration iam2Configuration = new IAM2Configuration();
- iam2Configuration.setUseDefaultCredentialsProvider(false);
- IAM2InternalClient iamClient = IAM2ClientFactory.getIamClient(iam2Configuration);
- assertTrue(iamClient instanceof IAM2ClientStandardImpl);
+ public void getIamClientWithStaticCredentials() {
+ IAM2Configuration configuration = new IAM2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("aws-global");
+ IamClient iamClient = IAM2ClientFactory.getIamClient(configuration);
+ assertNotNull(iamClient);
+ iamClient.close();
}
@Test
- public void getIAMOptimizedIamClient() {
- IAM2Configuration iam2Configuration = new IAM2Configuration();
- iam2Configuration.setUseDefaultCredentialsProvider(true);
- IAM2InternalClient iamClient = IAM2ClientFactory.getIamClient(iam2Configuration);
- assertTrue(iamClient instanceof IAM2ClientOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenIamClient() {
- IAM2Configuration iam2Configuration = new IAM2Configuration();
- iam2Configuration.setUseSessionCredentials(true);
- IAM2InternalClient iamClient = IAM2ClientFactory.getIamClient(iam2Configuration);
- assertTrue(iamClient instanceof IAM2ClientSessionTokenImpl);
+ public void getIamClientWithEndpointOverride() {
+ IAM2Configuration configuration = new IAM2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("aws-global");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ IamClient iamClient = IAM2ClientFactory.getIamClient(configuration);
+ assertNotNull(iamClient);
+ iamClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-kinesis/pom.xml b/components/camel-aws/camel-aws2-kinesis/pom.xml
index ac572cbe67baf..4a7ca805451bd 100644
--- a/components/camel-aws/camel-aws2-kinesis/pom.xml
+++ b/components/camel-aws/camel-aws2-kinesis/pom.xml
@@ -33,6 +33,10 @@
Consuming and Producing data to AWS Kinesis Service
+
+ org.apache.camel
+ camel-aws-common
+
org.apache.camel
camel-support
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/KinesisFirehose2Configuration.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/KinesisFirehose2Configuration.java
index 3960113314d6d..c2062cbe956cb 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/KinesisFirehose2Configuration.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/KinesisFirehose2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.firehose;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.firehose.FirehoseClient;
@UriParams
-public class KinesisFirehose2Configuration implements Cloneable {
+public class KinesisFirehose2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Name of the stream")
@Metadata(required = true)
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/KinesisFirehose2Endpoint.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/KinesisFirehose2Endpoint.java
index d55f055012211..35e73ae69161e 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/KinesisFirehose2Endpoint.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/KinesisFirehose2Endpoint.java
@@ -71,7 +71,7 @@ protected void doStart() throws Exception {
}
kinesisFirehoseClient = configuration.getAmazonKinesisFirehoseClient() != null
? configuration.getAmazonKinesisFirehoseClient()
- : KinesisFirehoseClientFactory.getKinesisFirehoseClient(configuration).getKinesisFirehoseClient();
+ : KinesisFirehoseClientFactory.getKinesisFirehoseClient(configuration);
}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/KinesisFirehoseClientFactory.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/KinesisFirehoseClientFactory.java
index 0992a8ce8c67b..d8b815e0a55cb 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/KinesisFirehoseClientFactory.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/KinesisFirehoseClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.firehose.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.firehose.KinesisFirehose2Configuration;
-import org.apache.camel.component.aws2.firehose.client.impl.KinesisFirehoseClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.firehose.client.impl.KinesisFirehoseClientIAMProfileOptimizedImpl;
-import org.apache.camel.component.aws2.firehose.client.impl.KinesisFirehoseClientSessionTokenImpl;
-import org.apache.camel.component.aws2.firehose.client.impl.KinesisFirehoseClientStandardImpl;
+import software.amazon.awssdk.services.firehose.FirehoseClient;
/**
- * Factory class to return the correct type of AWS Kinesis client.
+ * Factory class to create AWS Kinesis Firehose clients using common configuration.
*/
public final class KinesisFirehoseClientFactory {
@@ -31,20 +29,14 @@ private KinesisFirehoseClientFactory() {
}
/**
- * Return the correct aws Kinesis Firehose client (based on remote vs local).
+ * Create a Firehose client based on configuration.
*
- * @param configuration configuration
- * @return FirehoseClient
+ * @param configuration The Firehose configuration
+ * @return Configured FirehoseClient
*/
- public static KinesisFirehoseInternalClient getKinesisFirehoseClient(KinesisFirehose2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new KinesisFirehoseClientIAMOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new KinesisFirehoseClientIAMProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new KinesisFirehoseClientSessionTokenImpl(configuration);
- } else {
- return new KinesisFirehoseClientStandardImpl(configuration);
- }
+ public static FirehoseClient getKinesisFirehoseClient(KinesisFirehose2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ FirehoseClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/KinesisFirehoseInternalClient.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/KinesisFirehoseInternalClient.java
deleted file mode 100644
index 13e158a30adf2..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/KinesisFirehoseInternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.firehose.client;
-
-import software.amazon.awssdk.services.firehose.FirehoseClient;
-
-/**
- * Manage the required actions of a Kinesis Firehose client for either local or remote.
- */
-public interface KinesisFirehoseInternalClient {
-
- /**
- * Returns a Kinesis Firehose client after a factory method determines which one to return.
- *
- * @return FirehoseClient client
- */
- FirehoseClient getKinesisFirehoseClient();
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientIAMOptimizedImpl.java
deleted file mode 100644
index 9d7dba54eeaf5..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.component.aws2.firehose.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.firehose.KinesisFirehose2Configuration;
-import org.apache.camel.component.aws2.firehose.client.KinesisFirehoseInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.firehose.FirehoseClient;
-import software.amazon.awssdk.services.firehose.FirehoseClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis Firehose client for all users to use (enabling temporary creds). This implementation is for
- * remote instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class KinesisFirehoseClientIAMOptimizedImpl implements KinesisFirehoseInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisFirehoseClientIAMOptimizedImpl.class);
- private KinesisFirehose2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisFirehoseClientIAMOptimizedImpl(KinesisFirehose2Configuration configuration) {
- LOG.trace(
- "Creating an AWS Kinesis Firehose client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis client that is used.
- *
- * @return Amazon Kinesis Client.
- */
- @Override
- public FirehoseClient getKinesisFirehoseClient() {
- FirehoseClient client = null;
- FirehoseClientBuilder clientBuilder = FirehoseClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
-
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index a721694db6537..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.component.aws2.firehose.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.firehose.KinesisFirehose2Configuration;
-import org.apache.camel.component.aws2.firehose.client.KinesisFirehoseInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.firehose.FirehoseClient;
-import software.amazon.awssdk.services.firehose.FirehoseClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis Firehose client for all users to use (enabling temporary creds). This implementation is for
- * remote instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class KinesisFirehoseClientIAMProfileOptimizedImpl implements KinesisFirehoseInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisFirehoseClientIAMProfileOptimizedImpl.class);
- private KinesisFirehose2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisFirehoseClientIAMProfileOptimizedImpl(KinesisFirehose2Configuration configuration) {
- LOG.trace(
- "Creating an AWS Kinesis Firehose client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis client that is used.
- *
- * @return Amazon Kinesis Client.
- */
- @Override
- public FirehoseClient getKinesisFirehoseClient() {
- FirehoseClient client = null;
- FirehoseClientBuilder clientBuilder = FirehoseClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
-
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientSessionTokenImpl.java
deleted file mode 100644
index 304246620054d..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.firehose.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.firehose.KinesisFirehose2Configuration;
-import org.apache.camel.component.aws2.firehose.client.KinesisFirehoseInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.firehose.FirehoseClient;
-import software.amazon.awssdk.services.firehose.FirehoseClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis Firehose client for all users to use. This implementation is for local instances to use a
- * static and solid credential set.
- */
-public class KinesisFirehoseClientSessionTokenImpl implements KinesisFirehoseInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisFirehoseClientSessionTokenImpl.class);
- private KinesisFirehose2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisFirehoseClientSessionTokenImpl(KinesisFirehose2Configuration configuration) {
- LOG.trace("Creating an AWS Kinesis Firehose manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis Firehose client that is used.
- *
- * @return Amazon Kinesis Firehose Client.
- */
- @Override
- public FirehoseClient getKinesisFirehoseClient() {
- FirehoseClient client = null;
- FirehoseClientBuilder clientBuilder = FirehoseClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientStandardImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientStandardImpl.java
deleted file mode 100644
index 1761b1e4c9fbf..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/firehose/client/impl/KinesisFirehoseClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.firehose.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.firehose.KinesisFirehose2Configuration;
-import org.apache.camel.component.aws2.firehose.client.KinesisFirehoseInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.firehose.FirehoseClient;
-import software.amazon.awssdk.services.firehose.FirehoseClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis Firehose client for all users to use. This implementation is for local instances to use a
- * static and solid credential set.
- */
-public class KinesisFirehoseClientStandardImpl implements KinesisFirehoseInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisFirehoseClientStandardImpl.class);
- private KinesisFirehose2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisFirehoseClientStandardImpl(KinesisFirehose2Configuration configuration) {
- LOG.trace("Creating an AWS Kinesis Firehose manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis Firehose client that is used.
- *
- * @return Amazon Kinesis Firehose Client.
- */
- @Override
- public FirehoseClient getKinesisFirehoseClient() {
- FirehoseClient client = null;
- FirehoseClientBuilder clientBuilder = FirehoseClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Configuration.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Configuration.java
index 2a8273783b13b..072e9c2dc04a8 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Configuration.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/Kinesis2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.kinesis;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -29,7 +30,7 @@
import software.amazon.awssdk.services.kinesis.model.ShardIteratorType;
@UriParams
-public class Kinesis2Configuration implements Cloneable {
+public class Kinesis2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Name of the stream")
@Metadata(required = true)
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/KinesisConnection.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/KinesisConnection.java
index b265c9632cd86..b02cab0b8b7ed 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/KinesisConnection.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/KinesisConnection.java
@@ -41,7 +41,7 @@ public KinesisClient getClient(final Kinesis2Endpoint endpoint) {
if (Objects.isNull(kinesisClient)) {
kinesisClient = endpoint.getConfiguration().getAmazonKinesisClient() != null
? endpoint.getConfiguration().getAmazonKinesisClient()
- : KinesisClientFactory.getKinesisClient(endpoint.getConfiguration()).getKinesisClient();
+ : KinesisClientFactory.getKinesisClient(endpoint.getConfiguration());
}
return kinesisClient;
} finally {
@@ -55,7 +55,7 @@ public KinesisAsyncClient getAsyncClient(final Kinesis2Endpoint endpoint) {
if (Objects.isNull(kinesisAsyncClient)) {
kinesisAsyncClient = endpoint.getConfiguration().getAmazonKinesisAsyncClient() != null
? endpoint.getConfiguration().getAmazonKinesisAsyncClient()
- : KinesisClientFactory.getKinesisAsyncClient(endpoint.getConfiguration()).getKinesisAsyncClient();
+ : KinesisClientFactory.getKinesisAsyncClient(endpoint.getConfiguration());
}
return kinesisAsyncClient;
} finally {
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisAsyncInternalClient.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisAsyncInternalClient.java
deleted file mode 100644
index 963fe277fb8ae..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisAsyncInternalClient.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client;
-
-import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
-
-/**
- * Manage the required actions of a Kinesis Async client for either local or remote.
- */
-public interface KinesisAsyncInternalClient {
- /**
- * Returns a Kinesis Async client.
- *
- * @return KinesisAsyncClient client
- */
- KinesisAsyncClient getKinesisAsyncClient();
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisClientFactory.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisClientFactory.java
index e8233c67b5f7f..66d65d709c835 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisClientFactory.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisClientFactory.java
@@ -16,11 +16,13 @@
*/
package org.apache.camel.component.aws2.kinesis.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.impl.*;
+import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
/**
- * Factory class to return the correct type of AWS Kinesis client.
+ * Factory class to create AWS Kinesis clients using common configuration.
*/
public final class KinesisClientFactory {
@@ -28,38 +30,26 @@ private KinesisClientFactory() {
}
/**
- * Return the correct aws Kinesis client (based on remote vs local).
+ * Create a Kinesis sync client based on configuration.
*
- * @param configuration configuration
- * @return KinesisClient
+ * @param configuration The Kinesis configuration
+ * @return Configured KinesisClient
*/
- public static KinesisInternalClient getKinesisClient(Kinesis2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new KinesisClientIAMOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new KinesisClientIAMProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new KinesisClientSessionTokenImpl(configuration);
- } else {
- return new KinesisClientStandardImpl(configuration);
- }
+ public static KinesisClient getKinesisClient(Kinesis2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ KinesisClient::builder);
}
/**
- * Return the standard aws Kinesis Async client.
+ * Create a Kinesis async client based on configuration.
*
- * @param configuration configuration
- * @return KinesisAsyncClient
+ * @param configuration The Kinesis configuration
+ * @return Configured KinesisAsyncClient
*/
- public static KinesisAsyncInternalClient getKinesisAsyncClient(Kinesis2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new KinesisAsyncClientIAMOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new KinesisAsyncClientIAMProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new KinesisAsyncClientSessionTokenImpl(configuration);
- } else {
- return new KinesisAsyncClientStandardImpl(configuration);
- }
+ public static KinesisAsyncClient getKinesisAsyncClient(Kinesis2Configuration configuration) {
+ return AwsClientBuilderUtil.buildAsyncClient(
+ configuration,
+ KinesisAsyncClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisInternalClient.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisInternalClient.java
deleted file mode 100644
index e22cf6d723b68..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/KinesisInternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client;
-
-import software.amazon.awssdk.services.kinesis.KinesisClient;
-
-/**
- * Manage the required actions of a Kinesis client for either local or remote.
- */
-public interface KinesisInternalClient {
-
- /**
- * Returns a Kinesis client after a factory method determines which one to return.
- *
- * @return KinesisClient client
- */
- KinesisClient getKinesisClient();
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientIAMOptimizedImpl.java
deleted file mode 100644
index 0f68516d31d39..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.KinesisAsyncInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
-import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
-import software.amazon.awssdk.http.nio.netty.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis Async client for all users to use (enabling temporary creds). This implementation is for remote
- * instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class KinesisAsyncClientIAMOptimizedImpl implements KinesisAsyncInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisAsyncClientIAMOptimizedImpl.class);
- private Kinesis2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisAsyncClientIAMOptimizedImpl(Kinesis2Configuration configuration) {
- LOG.trace("Creating an AWS Kinesis Async client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis Async client that is used.
- *
- * @return Amazon Kinesis Async Client.
- */
- @Override
- public KinesisAsyncClient getKinesisAsyncClient() {
- var clientBuilder = KinesisAsyncClient.builder();
- SdkAsyncHttpClient.Builder httpClientBuilder = null;
-
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- var proxyConfig = ProxyConfiguration
- .builder()
- .scheme(configuration.getProxyProtocol().toString())
- .host(configuration.getProxyHost())
- .port(configuration.getProxyPort())
- .build();
- httpClientBuilder = NettyNioAsyncHttpClient
- .builder()
- .proxyConfiguration(proxyConfig);
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = NettyNioAsyncHttpClient.builder();
- }
- SdkAsyncHttpClient ahc = httpClientBuilder
- .buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- return clientBuilder.build();
- }
-
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index 3153f0684729f..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.KinesisAsyncInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
-import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
-import software.amazon.awssdk.http.nio.netty.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis Async client for all users to use (enabling temporary creds). This implementation is for remote
- * instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class KinesisAsyncClientIAMProfileOptimizedImpl implements KinesisAsyncInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisAsyncClientIAMProfileOptimizedImpl.class);
- private Kinesis2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisAsyncClientIAMProfileOptimizedImpl(Kinesis2Configuration configuration) {
- LOG.trace("Creating an AWS Kinesis Async client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the KinesisAsync client that is used.
- *
- * @return Amazon Kinesis Async Client.
- */
- @Override
- public KinesisAsyncClient getKinesisAsyncClient() {
- var clientBuilder = KinesisAsyncClient.builder();
- SdkAsyncHttpClient.Builder httpClientBuilder = null;
-
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- var proxyConfig = ProxyConfiguration
- .builder()
- .scheme(configuration.getProxyProtocol().toString())
- .host(configuration.getProxyHost())
- .port(configuration.getProxyPort())
- .build();
- httpClientBuilder = NettyNioAsyncHttpClient
- .builder()
- .proxyConfiguration(proxyConfig);
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = NettyNioAsyncHttpClient.builder();
- }
- SdkAsyncHttpClient ahc = httpClientBuilder
- .buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- return clientBuilder.build();
- }
-
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientSessionTokenImpl.java
deleted file mode 100644
index d6db29ad541a6..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientSessionTokenImpl.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client.impl;
-
-import java.net.URI;
-import java.util.Objects;
-
-import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.KinesisAsyncInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
-import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
-import software.amazon.awssdk.http.nio.netty.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Async Kinesis client for all users to use. This implementation is for local instances to use a static
- * and solid credential set.
- */
-public class KinesisAsyncClientSessionTokenImpl implements KinesisAsyncInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisAsyncClientSessionTokenImpl.class);
- private Kinesis2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisAsyncClientSessionTokenImpl(Kinesis2Configuration configuration) {
- LOG.trace("Creating an AWS Async Kinesis manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis Async client that is used.
- *
- * @return Amazon Kinesis Async Client.
- */
- @Override
- public KinesisAsyncClient getKinesisAsyncClient() {
- var clientBuilder = KinesisAsyncClient.builder();
- var isClientConfigFound = false;
- SdkAsyncHttpClient.Builder httpClientBuilder = null;
-
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- var proxyConfig = ProxyConfiguration
- .builder()
- .scheme(configuration.getProxyProtocol().toString())
- .host(configuration.getProxyHost())
- .port(configuration.getProxyPort())
- .build();
- httpClientBuilder = NettyNioAsyncHttpClient
- .builder()
- .proxyConfiguration(proxyConfig);
- isClientConfigFound = true;
- }
- if (Objects.nonNull(configuration.getAccessKey()) && Objects.nonNull(configuration.getSecretKey())
- && Objects.nonNull(configuration.getSessionToken())) {
- var cred = AwsSessionCredentials.create(configuration.getAccessKey(), configuration.getSecretKey(),
- configuration.getSessionToken());
- if (isClientConfigFound) {
- clientBuilder = clientBuilder
- .httpClientBuilder(httpClientBuilder)
- .credentialsProvider(StaticCredentialsProvider.create(cred));
- } else {
- clientBuilder = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred));
- }
- } else {
- if (!isClientConfigFound) {
- clientBuilder = clientBuilder.httpClientBuilder(null);
- }
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = NettyNioAsyncHttpClient.builder();
- }
- SdkAsyncHttpClient ahc = httpClientBuilder
- .buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- return clientBuilder.build();
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientStandardImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientStandardImpl.java
deleted file mode 100644
index b743e66ea6c34..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisAsyncClientStandardImpl.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client.impl;
-
-import java.net.URI;
-import java.util.Objects;
-
-import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.KinesisAsyncInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
-import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
-import software.amazon.awssdk.http.nio.netty.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Async Kinesis client for all users to use. This implementation is for local instances to use a static
- * and solid credential set.
- */
-public class KinesisAsyncClientStandardImpl implements KinesisAsyncInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisAsyncClientStandardImpl.class);
- private Kinesis2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisAsyncClientStandardImpl(Kinesis2Configuration configuration) {
- LOG.trace("Creating an AWS Async Kinesis manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis Async client that is used.
- *
- * @return Amazon Kinesis Async Client.
- */
- @Override
- public KinesisAsyncClient getKinesisAsyncClient() {
- var clientBuilder = KinesisAsyncClient.builder();
- var isClientConfigFound = false;
- SdkAsyncHttpClient.Builder httpClientBuilder = null;
-
- if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
- var proxyConfig = ProxyConfiguration
- .builder()
- .scheme(configuration.getProxyProtocol().toString())
- .host(configuration.getProxyHost())
- .port(configuration.getProxyPort())
- .build();
- httpClientBuilder = NettyNioAsyncHttpClient
- .builder()
- .proxyConfiguration(proxyConfig);
- isClientConfigFound = true;
- }
- if (Objects.nonNull(configuration.getAccessKey()) && Objects.nonNull(configuration.getSecretKey())) {
- var 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(null);
- }
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = NettyNioAsyncHttpClient.builder();
- }
- SdkAsyncHttpClient ahc = httpClientBuilder
- .buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- return clientBuilder.build();
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientIAMOptimizedImpl.java
deleted file mode 100644
index f4ce342dd2d7f..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientIAMOptimizedImpl.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.KinesisInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kinesis.KinesisClient;
-import software.amazon.awssdk.services.kinesis.KinesisClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis client for all users to use (enabling temporary creds). This implementation is for remote
- * instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class KinesisClientIAMOptimizedImpl implements KinesisInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisClientIAMOptimizedImpl.class);
- private Kinesis2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisClientIAMOptimizedImpl(Kinesis2Configuration configuration) {
- LOG.trace("Creating an AWS Kinesis client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis client that is used.
- *
- * @return Amazon Kinesis Client.
- */
- @Override
- public KinesisClient getKinesisClient() {
- KinesisClient client = null;
- KinesisClientBuilder clientBuilder = KinesisClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
-
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientIAMProfileOptimizedImpl.java
deleted file mode 100644
index a5c9cd6689b17..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientIAMProfileOptimizedImpl.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.KinesisInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kinesis.KinesisClient;
-import software.amazon.awssdk.services.kinesis.KinesisClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis client for all users to use (enabling temporary creds). This implementation is for remote
- * instances to manage the credentials on their own (eliminating credential rotations)
- */
-public class KinesisClientIAMProfileOptimizedImpl implements KinesisInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisClientIAMProfileOptimizedImpl.class);
- private Kinesis2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisClientIAMProfileOptimizedImpl(Kinesis2Configuration configuration) {
- LOG.trace("Creating an AWS Kinesis client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis client that is used.
- *
- * @return Amazon Kinesis Client.
- */
- @Override
- public KinesisClient getKinesisClient() {
- KinesisClient client = null;
- KinesisClientBuilder clientBuilder = KinesisClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
-
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientSessionTokenImpl.java
deleted file mode 100644
index 41eeffb9b576b..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.KinesisInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kinesis.KinesisClient;
-import software.amazon.awssdk.services.kinesis.KinesisClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis client for all users to use. This implementation is for local instances to use a static and
- * solid credential set.
- */
-public class KinesisClientSessionTokenImpl implements KinesisInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisClientSessionTokenImpl.class);
- private Kinesis2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisClientSessionTokenImpl(Kinesis2Configuration configuration) {
- LOG.trace("Creating an AWS Kinesis manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis client that is used.
- *
- * @return Amazon Kinesis Client.
- */
- @Override
- public KinesisClient getKinesisClient() {
- KinesisClient client = null;
- KinesisClientBuilder clientBuilder = KinesisClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientStandardImpl.java b/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientStandardImpl.java
deleted file mode 100644
index 5858f852233e1..0000000000000
--- a/components/camel-aws/camel-aws2-kinesis/src/main/java/org/apache/camel/component/aws2/kinesis/client/impl/KinesisClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.kinesis.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kinesis.Kinesis2Configuration;
-import org.apache.camel.component.aws2.kinesis.client.KinesisInternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kinesis.KinesisClient;
-import software.amazon.awssdk.services.kinesis.KinesisClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS Kinesis client for all users to use. This implementation is for local instances to use a static and
- * solid credential set.
- */
-public class KinesisClientStandardImpl implements KinesisInternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KinesisClientStandardImpl.class);
- private Kinesis2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KinesisClientStandardImpl(Kinesis2Configuration configuration) {
- LOG.trace("Creating an AWS Kinesis manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kinesis client that is used.
- *
- * @return Amazon Kinesis Client.
- */
- @Override
- public KinesisClient getKinesisClient() {
- KinesisClient client = null;
- KinesisClientBuilder clientBuilder = KinesisClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/firehose/KinesisFirehoseClientFactoryTest.java b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/firehose/KinesisFirehoseClientFactoryTest.java
index 75872d01c32c1..97476556500f7 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/firehose/KinesisFirehoseClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/firehose/KinesisFirehoseClientFactoryTest.java
@@ -17,48 +17,43 @@
package org.apache.camel.component.aws2.firehose;
import org.apache.camel.component.aws2.firehose.client.KinesisFirehoseClientFactory;
-import org.apache.camel.component.aws2.firehose.client.KinesisFirehoseInternalClient;
-import org.apache.camel.component.aws2.firehose.client.impl.KinesisFirehoseClientIAMOptimizedImpl;
-import org.apache.camel.component.aws2.firehose.client.impl.KinesisFirehoseClientSessionTokenImpl;
-import org.apache.camel.component.aws2.firehose.client.impl.KinesisFirehoseClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.firehose.FirehoseClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class KinesisFirehoseClientFactoryTest {
@Test
- public void getStandardFirehoseClientDefault() {
- KinesisFirehose2Configuration kinesis2Configuration = new KinesisFirehose2Configuration();
- KinesisFirehoseInternalClient kinesisFirehoseClient
- = KinesisFirehoseClientFactory.getKinesisFirehoseClient(kinesis2Configuration);
- assertTrue(kinesisFirehoseClient instanceof KinesisFirehoseClientStandardImpl);
+ public void getFirehoseClientWithDefaultCredentials() {
+ KinesisFirehose2Configuration configuration = new KinesisFirehose2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ FirehoseClient firehoseClient = KinesisFirehoseClientFactory.getKinesisFirehoseClient(configuration);
+ assertNotNull(firehoseClient);
+ firehoseClient.close();
}
@Test
- public void getStandardFirehoseClient() {
- KinesisFirehose2Configuration kinesis2Configuration = new KinesisFirehose2Configuration();
- kinesis2Configuration.setUseDefaultCredentialsProvider(false);
- KinesisFirehoseInternalClient kinesisFirehoseClient
- = KinesisFirehoseClientFactory.getKinesisFirehoseClient(kinesis2Configuration);
- assertTrue(kinesisFirehoseClient instanceof KinesisFirehoseClientStandardImpl);
+ public void getFirehoseClientWithStaticCredentials() {
+ KinesisFirehose2Configuration configuration = new KinesisFirehose2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ FirehoseClient firehoseClient = KinesisFirehoseClientFactory.getKinesisFirehoseClient(configuration);
+ assertNotNull(firehoseClient);
+ firehoseClient.close();
}
@Test
- public void getIAMOptimizedFirehoseClient() {
- KinesisFirehose2Configuration kinesis2Configuration = new KinesisFirehose2Configuration();
- kinesis2Configuration.setUseDefaultCredentialsProvider(true);
- KinesisFirehoseInternalClient kinesisFirehoseClient
- = KinesisFirehoseClientFactory.getKinesisFirehoseClient(kinesis2Configuration);
- assertTrue(kinesisFirehoseClient instanceof KinesisFirehoseClientIAMOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenFirehoseClient() {
- KinesisFirehose2Configuration kinesis2Configuration = new KinesisFirehose2Configuration();
- kinesis2Configuration.setUseSessionCredentials(true);
- KinesisFirehoseInternalClient kinesisFirehoseClient
- = KinesisFirehoseClientFactory.getKinesisFirehoseClient(kinesis2Configuration);
- assertTrue(kinesisFirehoseClient instanceof KinesisFirehoseClientSessionTokenImpl);
+ public void getFirehoseClientWithEndpointOverride() {
+ KinesisFirehose2Configuration configuration = new KinesisFirehose2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ FirehoseClient firehoseClient = KinesisFirehoseClientFactory.getKinesisFirehoseClient(configuration);
+ assertNotNull(firehoseClient);
+ firehoseClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisClientFactoryTest.java b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisClientFactoryTest.java
index f9ad5b8e5a7f9..d77fa7911985c 100644
--- a/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-kinesis/src/test/java/org/apache/camel/component/aws2/kinesis/KinesisClientFactoryTest.java
@@ -16,60 +16,66 @@
*/
package org.apache.camel.component.aws2.kinesis;
-import org.apache.camel.component.aws2.kinesis.client.KinesisAsyncInternalClient;
import org.apache.camel.component.aws2.kinesis.client.KinesisClientFactory;
-import org.apache.camel.component.aws2.kinesis.client.KinesisInternalClient;
-import org.apache.camel.component.aws2.kinesis.client.impl.*;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
+import software.amazon.awssdk.services.kinesis.KinesisClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
class KinesisClientFactoryTest {
@Test
- void getStandardKinesisClientDefault() {
+ void getKinesisClientWithDefaultCredentials() {
Kinesis2Configuration kinesis2Configuration = new Kinesis2Configuration();
- KinesisInternalClient kinesisClient = KinesisClientFactory.getKinesisClient(kinesis2Configuration);
- assertTrue(kinesisClient instanceof KinesisClientStandardImpl);
+ kinesis2Configuration.setUseDefaultCredentialsProvider(true);
+ kinesis2Configuration.setRegion("eu-west-1");
+ KinesisClient kinesisClient = KinesisClientFactory.getKinesisClient(kinesis2Configuration);
+ assertNotNull(kinesisClient);
+ kinesisClient.close();
}
@Test
- void getStandardKinesisClient() {
+ void getKinesisClientWithStaticCredentials() {
Kinesis2Configuration kinesis2Configuration = new Kinesis2Configuration();
- kinesis2Configuration.setUseDefaultCredentialsProvider(false);
- KinesisInternalClient kinesisClient = KinesisClientFactory.getKinesisClient(kinesis2Configuration);
- assertTrue(kinesisClient instanceof KinesisClientStandardImpl);
+ kinesis2Configuration.setAccessKey("testAccessKey");
+ kinesis2Configuration.setSecretKey("testSecretKey");
+ kinesis2Configuration.setRegion("eu-west-1");
+ KinesisClient kinesisClient = KinesisClientFactory.getKinesisClient(kinesis2Configuration);
+ assertNotNull(kinesisClient);
+ kinesisClient.close();
}
@Test
- void getIAMOptimizedKinesisClient() {
+ void getKinesisAsyncClientWithDefaultCredentials() {
Kinesis2Configuration kinesis2Configuration = new Kinesis2Configuration();
kinesis2Configuration.setUseDefaultCredentialsProvider(true);
- KinesisInternalClient kinesisClient = KinesisClientFactory.getKinesisClient(kinesis2Configuration);
- assertTrue(kinesisClient instanceof KinesisClientIAMOptimizedImpl);
- }
-
- @Test
- void getSessionTokenKinesisClient() {
- Kinesis2Configuration kinesis2Configuration = new Kinesis2Configuration();
- kinesis2Configuration.setUseSessionCredentials(true);
- KinesisInternalClient kinesisClient = KinesisClientFactory.getKinesisClient(kinesis2Configuration);
- assertTrue(kinesisClient instanceof KinesisClientSessionTokenImpl);
+ kinesis2Configuration.setRegion("eu-west-1");
+ KinesisAsyncClient kinesisAsyncClient = KinesisClientFactory.getKinesisAsyncClient(kinesis2Configuration);
+ assertNotNull(kinesisAsyncClient);
+ kinesisAsyncClient.close();
}
@Test
- void getSessionTokenAsyncKinesisClient() {
+ void getKinesisAsyncClientWithStaticCredentials() {
Kinesis2Configuration kinesis2Configuration = new Kinesis2Configuration();
- kinesis2Configuration.setUseSessionCredentials(true);
- KinesisAsyncInternalClient kinesisClient = KinesisClientFactory.getKinesisAsyncClient(kinesis2Configuration);
- assertTrue(kinesisClient instanceof KinesisAsyncClientSessionTokenImpl);
+ kinesis2Configuration.setAccessKey("testAccessKey");
+ kinesis2Configuration.setSecretKey("testSecretKey");
+ kinesis2Configuration.setRegion("eu-west-1");
+ KinesisAsyncClient kinesisAsyncClient = KinesisClientFactory.getKinesisAsyncClient(kinesis2Configuration);
+ assertNotNull(kinesisAsyncClient);
+ kinesisAsyncClient.close();
}
@Test
- void getStandardKinesisAsyncClient() {
+ void getKinesisClientWithEndpointOverride() {
Kinesis2Configuration kinesis2Configuration = new Kinesis2Configuration();
- kinesis2Configuration.setAsyncClient(true);
- KinesisAsyncInternalClient kinesisClient = KinesisClientFactory.getKinesisAsyncClient(kinesis2Configuration);
- assertTrue(kinesisClient instanceof KinesisAsyncClientStandardImpl);
+ kinesis2Configuration.setUseDefaultCredentialsProvider(true);
+ kinesis2Configuration.setRegion("eu-west-1");
+ kinesis2Configuration.setOverrideEndpoint(true);
+ kinesis2Configuration.setUriEndpointOverride("http://localhost:4566");
+ KinesisClient kinesisClient = KinesisClientFactory.getKinesisClient(kinesis2Configuration);
+ assertNotNull(kinesisClient);
+ kinesisClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-kms/pom.xml b/components/camel-aws/camel-aws2-kms/pom.xml
index 8fb74096fa4b6..0e1335b48ed6f 100644
--- a/components/camel-aws/camel-aws2-kms/pom.xml
+++ b/components/camel-aws/camel-aws2-kms/pom.xml
@@ -42,6 +42,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
software.amazon.awssdk
kms
diff --git a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Configuration.java b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Configuration.java
index 4d9b494e6d2c2..a0535f46c0fa5 100644
--- a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Configuration.java
+++ b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.kms;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.kms.KmsClient;
@UriParams
-public class KMS2Configuration implements Cloneable {
+public class KMS2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Logical name")
@Metadata(required = true)
@@ -216,14 +217,16 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the KMS client should expect to load credentials through a default credentials provider or to expect
* static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
+ @Override
public boolean isUseProfileCredentialsProvider() {
return useProfileCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Endpoint.java b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Endpoint.java
index db44a94c1c326..8a111b4e40e26 100644
--- a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Endpoint.java
+++ b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Endpoint.java
@@ -63,7 +63,7 @@ public void doStart() throws Exception {
kmsClient = configuration.getKmsClient() != null
? configuration.getKmsClient()
- : KMS2ClientFactory.getKmsClient(configuration).getKmsClient();
+ : KMS2ClientFactory.getKmsClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/KMS2ClientFactory.java b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/KMS2ClientFactory.java
index 3ea8a699ab574..dffceba3a4b23 100644
--- a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/KMS2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/KMS2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.kms.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.kms.KMS2Configuration;
-import org.apache.camel.component.aws2.kms.client.impl.KMS2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.kms.client.impl.KMS2ClientProfileOptimizedImpl;
-import org.apache.camel.component.aws2.kms.client.impl.KMS2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.kms.client.impl.KMS2ClientStandardImpl;
+import software.amazon.awssdk.services.kms.KmsClient;
/**
- * Factory class to return the correct type of AWS KMS client.
+ * Factory class to create AWS KMS clients using common configuration.
*/
public final class KMS2ClientFactory {
@@ -31,20 +29,14 @@ private KMS2ClientFactory() {
}
/**
- * Return the correct AWS KMS client (based on remote vs local).
+ * Create a KMS client based on configuration.
*
- * @param configuration configuration
- * @return KMSClient
+ * @param configuration The KMS configuration
+ * @return Configured KmsClient
*/
- public static KMS2InternalClient getKmsClient(KMS2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new KMS2ClientOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new KMS2ClientProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new KMS2ClientSessionTokenImpl(configuration);
- } else {
- return new KMS2ClientStandardImpl(configuration);
- }
+ public static KmsClient getKmsClient(KMS2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ KmsClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/KMS2InternalClient.java b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/KMS2InternalClient.java
deleted file mode 100644
index 51b832abfa748..0000000000000
--- a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/KMS2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.kms.client;
-
-import software.amazon.awssdk.services.kms.KmsClient;
-
-/**
- * Manage the required actions of an KMS client for either local or remote.
- */
-public interface KMS2InternalClient {
-
- /**
- * Returns an KMS client after a factory method determines which one to return.
- *
- * @return KmsClient KmsClient
- */
- KmsClient getKmsClient();
-}
diff --git a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientOptimizedImpl.java b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientOptimizedImpl.java
deleted file mode 100644
index c5248688f193a..0000000000000
--- a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.kms.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kms.KMS2Configuration;
-import org.apache.camel.component.aws2.kms.client.KMS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kms.KmsClient;
-import software.amazon.awssdk.services.kms.KmsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS KMS client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class KMS2ClientOptimizedImpl implements KMS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KMS2ClientOptimizedImpl.class);
- private KMS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KMS2ClientOptimizedImpl(KMS2Configuration configuration) {
- LOG.trace("Creating an AWS KMS client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the KMS aws client that is used.
- *
- * @return KMS Client.
- */
- @Override
- public KmsClient getKmsClient() {
- KmsClient client = null;
- KmsClientBuilder clientBuilder = KmsClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientProfileOptimizedImpl.java
deleted file mode 100644
index 7f434cb762bba..0000000000000
--- a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.kms.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kms.KMS2Configuration;
-import org.apache.camel.component.aws2.kms.client.KMS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kms.KmsClient;
-import software.amazon.awssdk.services.kms.KmsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS KMS client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class KMS2ClientProfileOptimizedImpl implements KMS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KMS2ClientProfileOptimizedImpl.class);
- private KMS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KMS2ClientProfileOptimizedImpl(KMS2Configuration configuration) {
- LOG.trace("Creating an AWS KMS client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the KMS aws client that is used.
- *
- * @return KMS Client.
- */
- @Override
- public KmsClient getKmsClient() {
- KmsClient client = null;
- KmsClientBuilder clientBuilder = KmsClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientSessionTokenImpl.java
deleted file mode 100644
index 9c17d4cef3fce..0000000000000
--- a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.kms.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kms.KMS2Configuration;
-import org.apache.camel.component.aws2.kms.client.KMS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kms.KmsClient;
-import software.amazon.awssdk.services.kms.KmsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS KMS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class KMS2ClientSessionTokenImpl implements KMS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KMS2ClientSessionTokenImpl.class);
- private KMS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KMS2ClientSessionTokenImpl(KMS2Configuration configuration) {
- LOG.trace("Creating an AWS KMS manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the KMS AWS client that is used.
- *
- * @return Amazon KMS Client.
- */
- @Override
- public KmsClient getKmsClient() {
- KmsClient client = null;
- KmsClientBuilder clientBuilder = KmsClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientStandardImpl.java b/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientStandardImpl.java
deleted file mode 100644
index 69959d3601a7a..0000000000000
--- a/components/camel-aws/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/client/impl/KMS2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.kms.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.kms.KMS2Configuration;
-import org.apache.camel.component.aws2.kms.client.KMS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kms.KmsClient;
-import software.amazon.awssdk.services.kms.KmsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS KMS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class KMS2ClientStandardImpl implements KMS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(KMS2ClientStandardImpl.class);
- private KMS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public KMS2ClientStandardImpl(KMS2Configuration configuration) {
- LOG.trace("Creating an AWS KMS manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the KMS AWS client that is used.
- *
- * @return Amazon KMS Client.
- */
- @Override
- public KmsClient getKmsClient() {
- KmsClient client = null;
- KmsClientBuilder clientBuilder = KmsClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/KMSClientFactoryTest.java b/components/camel-aws/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/KMSClientFactoryTest.java
index 597af7a45095c..04a882f49324a 100644
--- a/components/camel-aws/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/KMSClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-kms/src/test/java/org/apache/camel/component/aws2/kms/KMSClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.kms;
import org.apache.camel.component.aws2.kms.client.KMS2ClientFactory;
-import org.apache.camel.component.aws2.kms.client.KMS2InternalClient;
-import org.apache.camel.component.aws2.kms.client.impl.KMS2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.kms.client.impl.KMS2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.kms.client.impl.KMS2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.kms.KmsClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class KMSClientFactoryTest {
@Test
- public void getStandardKMSClientDefault() {
- KMS2Configuration kms2Configuration = new KMS2Configuration();
- KMS2InternalClient kmsClient = KMS2ClientFactory.getKmsClient(kms2Configuration);
- assertTrue(kmsClient instanceof KMS2ClientStandardImpl);
+ public void getKmsClientWithDefaultCredentials() {
+ KMS2Configuration configuration = new KMS2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ KmsClient kmsClient = KMS2ClientFactory.getKmsClient(configuration);
+ assertNotNull(kmsClient);
+ kmsClient.close();
}
@Test
- public void getStandardKMSClient() {
- KMS2Configuration kms2Configuration = new KMS2Configuration();
- kms2Configuration.setUseDefaultCredentialsProvider(false);
- KMS2InternalClient kmsClient = KMS2ClientFactory.getKmsClient(kms2Configuration);
- assertTrue(kmsClient instanceof KMS2ClientStandardImpl);
+ public void getKmsClientWithStaticCredentials() {
+ KMS2Configuration configuration = new KMS2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ KmsClient kmsClient = KMS2ClientFactory.getKmsClient(configuration);
+ assertNotNull(kmsClient);
+ kmsClient.close();
}
@Test
- public void getIAMOptimizedKMSClient() {
- KMS2Configuration kms2Configuration = new KMS2Configuration();
- kms2Configuration.setUseDefaultCredentialsProvider(true);
- KMS2InternalClient kmsClient = KMS2ClientFactory.getKmsClient(kms2Configuration);
- assertTrue(kmsClient instanceof KMS2ClientOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenKMSClient() {
- KMS2Configuration kms2Configuration = new KMS2Configuration();
- kms2Configuration.setUseSessionCredentials(true);
- KMS2InternalClient kmsClient = KMS2ClientFactory.getKmsClient(kms2Configuration);
- assertTrue(kmsClient instanceof KMS2ClientSessionTokenImpl);
+ public void getKmsClientWithEndpointOverride() {
+ KMS2Configuration configuration = new KMS2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ KmsClient kmsClient = KMS2ClientFactory.getKmsClient(configuration);
+ assertNotNull(kmsClient);
+ kmsClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-mq/pom.xml b/components/camel-aws/camel-aws2-mq/pom.xml
index 8767cd9f332a6..f55d59b54d88f 100644
--- a/components/camel-aws/camel-aws2-mq/pom.xml
+++ b/components/camel-aws/camel-aws2-mq/pom.xml
@@ -40,6 +40,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
software.amazon.awssdk
mq
diff --git a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Configuration.java b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Configuration.java
index 763a74b1e6d37..11de90978f691 100644
--- a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Configuration.java
+++ b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.mq;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.mq.MqClient;
@UriParams
-public class MQ2Configuration implements Cloneable {
+public class MQ2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Logical name")
@Metadata(required = true)
@@ -217,14 +218,16 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the MQ client should expect to load credentials through a default credentials provider or to expect
* static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
+ @Override
public boolean isUseProfileCredentialsProvider() {
return useProfileCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Endpoint.java b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Endpoint.java
index e81b9c56bca42..af3dfc01bcc03 100644
--- a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Endpoint.java
+++ b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/MQ2Endpoint.java
@@ -67,7 +67,7 @@ public void doStart() throws Exception {
mqClient = configuration.getAmazonMqClient() != null
? configuration.getAmazonMqClient()
- : MQ2ClientFactory.getMqClient(configuration).getMqClient();
+ : MQ2ClientFactory.getMqClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/MQ2ClientFactory.java b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/MQ2ClientFactory.java
index 56df2b0cbd3d2..70ba82c7adcd5 100644
--- a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/MQ2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/MQ2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.mq.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.mq.MQ2Configuration;
-import org.apache.camel.component.aws2.mq.client.impl.MQ2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.mq.client.impl.MQ2ClientProfileOptimizedImpl;
-import org.apache.camel.component.aws2.mq.client.impl.MQ2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.mq.client.impl.MQ2ClientStandardImpl;
+import software.amazon.awssdk.services.mq.MqClient;
/**
- * Factory class to return the correct type of AWS MQ client.
+ * Factory class to create AWS MQ clients using common configuration.
*/
public final class MQ2ClientFactory {
@@ -31,20 +29,14 @@ private MQ2ClientFactory() {
}
/**
- * Return the correct AWS Mq client (based on remote vs local).
+ * Create an MQ client based on configuration.
*
- * @param configuration configuration
- * @return MqClient
+ * @param configuration The MQ configuration
+ * @return Configured MqClient
*/
- public static MQ2InternalClient getMqClient(MQ2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new MQ2ClientOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new MQ2ClientProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new MQ2ClientSessionTokenImpl(configuration);
- } else {
- return new MQ2ClientStandardImpl(configuration);
- }
+ public static MqClient getMqClient(MQ2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ MqClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/MQ2InternalClient.java b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/MQ2InternalClient.java
deleted file mode 100644
index 743fa57d80fda..0000000000000
--- a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/MQ2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.mq.client;
-
-import software.amazon.awssdk.services.mq.MqClient;
-
-/**
- * Manage the required actions of an MQ client for either local or remote.
- */
-public interface MQ2InternalClient {
-
- /**
- * Returns an MQ client after a factory method determines which one to return.
- *
- * @return MqClient MqClient
- */
- MqClient getMqClient();
-}
diff --git a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientOptimizedImpl.java b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientOptimizedImpl.java
deleted file mode 100644
index 19abefef76bfc..0000000000000
--- a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.mq.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.mq.MQ2Configuration;
-import org.apache.camel.component.aws2.mq.client.MQ2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.mq.MqClient;
-import software.amazon.awssdk.services.mq.MqClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MQ client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class MQ2ClientOptimizedImpl implements MQ2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MQ2ClientOptimizedImpl.class);
- private MQ2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MQ2ClientOptimizedImpl(MQ2Configuration configuration) {
- LOG.trace("Creating an AWS MQ client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the MQ aws client that is used.
- *
- * @return MQ Client.
- */
- @Override
- public MqClient getMqClient() {
- MqClient client = null;
- MqClientBuilder clientBuilder = MqClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientProfileOptimizedImpl.java
deleted file mode 100644
index a9e75f5f2669c..0000000000000
--- a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.mq.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.mq.MQ2Configuration;
-import org.apache.camel.component.aws2.mq.client.MQ2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.mq.MqClient;
-import software.amazon.awssdk.services.mq.MqClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MQ client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class MQ2ClientProfileOptimizedImpl implements MQ2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MQ2ClientProfileOptimizedImpl.class);
- private MQ2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MQ2ClientProfileOptimizedImpl(MQ2Configuration configuration) {
- LOG.trace("Creating an AWS MQ client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the MQ aws client that is used.
- *
- * @return MQ Client.
- */
- @Override
- public MqClient getMqClient() {
- MqClient client = null;
- MqClientBuilder clientBuilder = MqClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientSessionTokenImpl.java
deleted file mode 100644
index a447ec8687382..0000000000000
--- a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.mq.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.mq.MQ2Configuration;
-import org.apache.camel.component.aws2.mq.client.MQ2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.mq.MqClient;
-import software.amazon.awssdk.services.mq.MqClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MQ client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class MQ2ClientSessionTokenImpl implements MQ2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MQ2ClientSessionTokenImpl.class);
- private MQ2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MQ2ClientSessionTokenImpl(MQ2Configuration configuration) {
- LOG.trace("Creating an AWS MQ manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the MQ AWS client that is used.
- *
- * @return Amazon MQ Client.
- */
- @Override
- public MqClient getMqClient() {
- MqClient client = null;
- MqClientBuilder clientBuilder = MqClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientStandardImpl.java b/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientStandardImpl.java
deleted file mode 100644
index f9f9060bae6b3..0000000000000
--- a/components/camel-aws/camel-aws2-mq/src/main/java/org/apache/camel/component/aws2/mq/client/impl/MQ2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.mq.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.mq.MQ2Configuration;
-import org.apache.camel.component.aws2.mq.client.MQ2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.mq.MqClient;
-import software.amazon.awssdk.services.mq.MqClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MQ client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class MQ2ClientStandardImpl implements MQ2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MQ2ClientStandardImpl.class);
- private MQ2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MQ2ClientStandardImpl(MQ2Configuration configuration) {
- LOG.trace("Creating an AWS MQ manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the MQ AWS client that is used.
- *
- * @return Amazon MQ Client.
- */
- @Override
- public MqClient getMqClient() {
- MqClient client = null;
- MqClientBuilder clientBuilder = MqClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-mq/src/test/java/org/apache/camel/component/aws2/mq/MQ2ClientFactoryTest.java b/components/camel-aws/camel-aws2-mq/src/test/java/org/apache/camel/component/aws2/mq/MQ2ClientFactoryTest.java
index 6841bf3ef6310..925a6348f9ee9 100644
--- a/components/camel-aws/camel-aws2-mq/src/test/java/org/apache/camel/component/aws2/mq/MQ2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-mq/src/test/java/org/apache/camel/component/aws2/mq/MQ2ClientFactoryTest.java
@@ -17,43 +17,43 @@
package org.apache.camel.component.aws2.mq;
import org.apache.camel.component.aws2.mq.client.MQ2ClientFactory;
-import org.apache.camel.component.aws2.mq.client.MQ2InternalClient;
-import org.apache.camel.component.aws2.mq.client.impl.MQ2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.mq.client.impl.MQ2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.mq.MqClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class MQ2ClientFactoryTest {
@Test
- public void getStandardMQClientDefault() {
- MQ2Configuration mq2Configuration = new MQ2Configuration();
- MQ2InternalClient mqClient = MQ2ClientFactory.getMqClient(mq2Configuration);
- assertTrue(mqClient instanceof MQ2ClientStandardImpl);
+ public void getMqClientWithDefaultCredentials() {
+ MQ2Configuration configuration = new MQ2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ MqClient mqClient = MQ2ClientFactory.getMqClient(configuration);
+ assertNotNull(mqClient);
+ mqClient.close();
}
@Test
- public void getStandardMQClient() {
- MQ2Configuration mq2Configuration = new MQ2Configuration();
- mq2Configuration.setUseDefaultCredentialsProvider(false);
- MQ2InternalClient mqClient = MQ2ClientFactory.getMqClient(mq2Configuration);
- assertTrue(mqClient instanceof MQ2ClientStandardImpl);
+ public void getMqClientWithStaticCredentials() {
+ MQ2Configuration configuration = new MQ2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ MqClient mqClient = MQ2ClientFactory.getMqClient(configuration);
+ assertNotNull(mqClient);
+ mqClient.close();
}
@Test
- public void getIAMOptimizedMQClient() {
- MQ2Configuration mq2Configuration = new MQ2Configuration();
- mq2Configuration.setUseDefaultCredentialsProvider(true);
- MQ2InternalClient mqClient = MQ2ClientFactory.getMqClient(mq2Configuration);
- assertTrue(mqClient instanceof MQ2ClientOptimizedImpl);
- }
-
- @Test
- public void getSessionTokenMQClient() {
- MQ2Configuration mq2Configuration = new MQ2Configuration();
- mq2Configuration.setUseDefaultCredentialsProvider(true);
- MQ2InternalClient mqClient = MQ2ClientFactory.getMqClient(mq2Configuration);
- assertTrue(mqClient instanceof MQ2ClientOptimizedImpl);
+ public void getMqClientWithEndpointOverride() {
+ MQ2Configuration configuration = new MQ2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ MqClient mqClient = MQ2ClientFactory.getMqClient(configuration);
+ assertNotNull(mqClient);
+ mqClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-msk/pom.xml b/components/camel-aws/camel-aws2-msk/pom.xml
index 3ba40fbb6af42..e97b725747408 100644
--- a/components/camel-aws/camel-aws2-msk/pom.xml
+++ b/components/camel-aws/camel-aws2-msk/pom.xml
@@ -40,6 +40,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
software.amazon.awssdk
kafka
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Configuration.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Configuration.java
index ab383fc2afcd6..4c77bcfdd5224 100644
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Configuration.java
+++ b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.msk;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.kafka.KafkaClient;
@UriParams
-public class MSK2Configuration implements Cloneable {
+public class MSK2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Logical name")
@Metadata(required = true)
@@ -217,14 +218,16 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the Kafka client should expect to load credentials through a default credentials provider or to
* expect static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
+ @Override
public boolean isUseProfileCredentialsProvider() {
return useProfileCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Endpoint.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Endpoint.java
index 0b739c572c299..d4c34d4c2ebad 100644
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Endpoint.java
+++ b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/MSK2Endpoint.java
@@ -68,7 +68,7 @@ public void doStart() throws Exception {
mskClient = configuration.getMskClient() != null
? configuration.getMskClient()
- : MSK2ClientFactory.getKafkaClient(configuration).getKafkaClient();
+ : MSK2ClientFactory.getKafkaClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2ClientFactory.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2ClientFactory.java
index a344541f508a4..3f413ecaff068 100644
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.msk.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.msk.MSK2Configuration;
-import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientProfileOptimizedImpl;
-import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientStandardImpl;
+import software.amazon.awssdk.services.kafka.KafkaClient;
/**
- * Factory class to return the correct type of AWS Kafka client.
+ * Factory class to create AWS MSK (Kafka) clients using common configuration.
*/
public final class MSK2ClientFactory {
@@ -31,20 +29,14 @@ private MSK2ClientFactory() {
}
/**
- * Return the correct AWS Kafka client (based on remote vs local).
+ * Create an MSK (Kafka) client based on configuration.
*
- * @param configuration configuration
- * @return MqClient
+ * @param configuration The MSK configuration
+ * @return Configured KafkaClient
*/
- public static MSK2InternalClient getKafkaClient(MSK2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new MSK2ClientOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new MSK2ClientProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new MSK2ClientSessionTokenImpl(configuration);
- } else {
- return new MSK2ClientStandardImpl(configuration);
- }
+ public static KafkaClient getKafkaClient(MSK2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ KafkaClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2InternalClient.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2InternalClient.java
deleted file mode 100644
index 9d43ecbd44829..0000000000000
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/MSK2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.msk.client;
-
-import software.amazon.awssdk.services.kafka.KafkaClient;
-
-/**
- * Manage the required actions of a Kafka client for either local or remote.
- */
-public interface MSK2InternalClient {
-
- /**
- * Returns an Kafka client after a factory method determines which one to return.
- *
- * @return KafkaClient KafkaClient
- */
- KafkaClient getKafkaClient();
-}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientOptimizedImpl.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientOptimizedImpl.java
deleted file mode 100644
index e6c048006c6f0..0000000000000
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.msk.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.msk.MSK2Configuration;
-import org.apache.camel.component.aws2.msk.client.MSK2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kafka.KafkaClient;
-import software.amazon.awssdk.services.kafka.KafkaClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MSK client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class MSK2ClientOptimizedImpl implements MSK2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MSK2ClientOptimizedImpl.class);
- private MSK2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MSK2ClientOptimizedImpl(MSK2Configuration configuration) {
- LOG.trace("Creating an AWS MSK client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kafka aws client that is used.
- *
- * @return Kafka Client.
- */
- @Override
- public KafkaClient getKafkaClient() {
- KafkaClient client = null;
- KafkaClientBuilder clientBuilder = KafkaClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientProfileOptimizedImpl.java
deleted file mode 100644
index 13c84a8a245d7..0000000000000
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.msk.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.msk.MSK2Configuration;
-import org.apache.camel.component.aws2.msk.client.MSK2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kafka.KafkaClient;
-import software.amazon.awssdk.services.kafka.KafkaClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MSK client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class MSK2ClientProfileOptimizedImpl implements MSK2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MSK2ClientProfileOptimizedImpl.class);
- private MSK2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MSK2ClientProfileOptimizedImpl(MSK2Configuration configuration) {
- LOG.trace("Creating an AWS MSK client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the Kafka aws client that is used.
- *
- * @return Kafka Client.
- */
- @Override
- public KafkaClient getKafkaClient() {
- KafkaClient client = null;
- KafkaClientBuilder clientBuilder = KafkaClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientSessionTokenImpl.java
deleted file mode 100644
index e146cbad9a748..0000000000000
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.msk.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.msk.MSK2Configuration;
-import org.apache.camel.component.aws2.msk.client.MSK2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kafka.KafkaClient;
-import software.amazon.awssdk.services.kafka.KafkaClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MQ client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class MSK2ClientSessionTokenImpl implements MSK2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MSK2ClientSessionTokenImpl.class);
- private MSK2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MSK2ClientSessionTokenImpl(MSK2Configuration configuration) {
- LOG.trace("Creating an AWS MSK manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the MQ AWS client that is used.
- *
- * @return Amazon MQ Client.
- */
- @Override
- public KafkaClient getKafkaClient() {
- KafkaClient client = null;
- KafkaClientBuilder clientBuilder = KafkaClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientStandardImpl.java b/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientStandardImpl.java
deleted file mode 100644
index a64a61f2fa110..0000000000000
--- a/components/camel-aws/camel-aws2-msk/src/main/java/org/apache/camel/component/aws2/msk/client/impl/MSK2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.msk.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.msk.MSK2Configuration;
-import org.apache.camel.component.aws2.msk.client.MSK2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.kafka.KafkaClient;
-import software.amazon.awssdk.services.kafka.KafkaClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MQ client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class MSK2ClientStandardImpl implements MSK2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(MSK2ClientStandardImpl.class);
- private MSK2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public MSK2ClientStandardImpl(MSK2Configuration configuration) {
- LOG.trace("Creating an AWS MSK manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the MQ AWS client that is used.
- *
- * @return Amazon MQ Client.
- */
- @Override
- public KafkaClient getKafkaClient() {
- KafkaClient client = null;
- KafkaClientBuilder clientBuilder = KafkaClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-msk/src/test/java/org/apache/camel/component/aws2/msk/MSK2ClientFactoryTest.java b/components/camel-aws/camel-aws2-msk/src/test/java/org/apache/camel/component/aws2/msk/MSK2ClientFactoryTest.java
index be2467ea8ea33..224dfb0bff57c 100644
--- a/components/camel-aws/camel-aws2-msk/src/test/java/org/apache/camel/component/aws2/msk/MSK2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-msk/src/test/java/org/apache/camel/component/aws2/msk/MSK2ClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.msk;
import org.apache.camel.component.aws2.msk.client.MSK2ClientFactory;
-import org.apache.camel.component.aws2.msk.client.MSK2InternalClient;
-import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.msk.client.impl.MSK2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.kafka.KafkaClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class MSK2ClientFactoryTest {
@Test
- public void getStandardMSKClientDefault() {
- MSK2Configuration msk2Configuration = new MSK2Configuration();
- MSK2InternalClient mskClient = MSK2ClientFactory.getKafkaClient(msk2Configuration);
- assertTrue(mskClient instanceof MSK2ClientStandardImpl);
+ public void getMskClientWithDefaultCredentials() {
+ MSK2Configuration configuration = new MSK2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ KafkaClient kafkaClient = MSK2ClientFactory.getKafkaClient(configuration);
+ assertNotNull(kafkaClient);
+ kafkaClient.close();
}
@Test
- public void getStandardMSKClient() {
- MSK2Configuration msk2Configuration = new MSK2Configuration();
- msk2Configuration.setUseDefaultCredentialsProvider(false);
- MSK2InternalClient mskClient = MSK2ClientFactory.getKafkaClient(msk2Configuration);
- assertTrue(mskClient instanceof MSK2ClientStandardImpl);
+ public void getMskClientWithStaticCredentials() {
+ MSK2Configuration configuration = new MSK2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ KafkaClient kafkaClient = MSK2ClientFactory.getKafkaClient(configuration);
+ assertNotNull(kafkaClient);
+ kafkaClient.close();
}
@Test
- public void getMSKOptimizedMSKClient() {
- MSK2Configuration msk2Configuration = new MSK2Configuration();
- msk2Configuration.setUseDefaultCredentialsProvider(true);
- MSK2InternalClient mskClient = MSK2ClientFactory.getKafkaClient(msk2Configuration);
- assertTrue(mskClient instanceof MSK2ClientOptimizedImpl);
- }
-
- @Test
- public void getMSKSessionTokenClient() {
- MSK2Configuration msk2Configuration = new MSK2Configuration();
- msk2Configuration.setUseSessionCredentials(true);
- MSK2InternalClient mskClient = MSK2ClientFactory.getKafkaClient(msk2Configuration);
- assertTrue(mskClient instanceof MSK2ClientSessionTokenImpl);
+ public void getMskClientWithEndpointOverride() {
+ MSK2Configuration configuration = new MSK2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ KafkaClient kafkaClient = MSK2ClientFactory.getKafkaClient(configuration);
+ assertNotNull(kafkaClient);
+ kafkaClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-ses/pom.xml b/components/camel-aws/camel-aws2-ses/pom.xml
index db6a6879ececc..e33c208c47e92 100644
--- a/components/camel-aws/camel-aws2-ses/pom.xml
+++ b/components/camel-aws/camel-aws2-ses/pom.xml
@@ -40,6 +40,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
org.eclipse.angus
angus-mail
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Configuration.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Configuration.java
index b7bcbfe7f30fc..79639ea06fc55 100644
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Configuration.java
+++ b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.ses;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -25,7 +26,7 @@
import software.amazon.awssdk.services.ses.SesClient;
@UriParams
-public class Ses2Configuration implements Cloneable {
+public class Ses2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath
@Metadata(required = true)
@@ -285,7 +286,7 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the Ses client should expect to load credentials through a default credentials provider or to expect
* static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
@@ -303,7 +304,8 @@ public void setConfigurationSet(String configurationSet) {
this.configurationSet = configurationSet;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Endpoint.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Endpoint.java
index c8857fbde779f..6a9f420d202f9 100644
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Endpoint.java
+++ b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Endpoint.java
@@ -56,7 +56,7 @@ public void doStart() throws Exception {
super.doStart();
sesClient = configuration.getAmazonSESClient() != null
? configuration.getAmazonSESClient()
- : Ses2ClientFactory.getSesClient(configuration).getSesClient();
+ : Ses2ClientFactory.getSesClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/Ses2ClientFactory.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/Ses2ClientFactory.java
index 985a0379f2d12..d2feb71b34a98 100644
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/Ses2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/Ses2ClientFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.aws2.ses.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.ses.Ses2Configuration;
-import org.apache.camel.component.aws2.ses.client.impl.Ses2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.ses.client.impl.Ses2ClientProfileOptimizedImpl;
-import org.apache.camel.component.aws2.ses.client.impl.Ses2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ses.client.impl.Ses2ClientStandardImpl;
+import software.amazon.awssdk.services.ses.SesClient;
/**
- * Factory class to return the correct type of AWS SES client.
+ * Factory class to create AWS SES clients using common configuration.
*/
public final class Ses2ClientFactory {
@@ -31,20 +29,14 @@ private Ses2ClientFactory() {
}
/**
- * Return the correct AWS SES client (based on remote vs local).
+ * Create a SES client based on configuration.
*
- * @param configuration configuration
- * @return SesClient
+ * @param configuration The SES configuration
+ * @return Configured SesClient
*/
- public static Ses2InternalClient getSesClient(Ses2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new Ses2ClientOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new Ses2ClientProfileOptimizedImpl(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseSessionCredentials())) {
- return new Ses2ClientSessionTokenImpl(configuration);
- } else {
- return new Ses2ClientStandardImpl(configuration);
- }
+ public static SesClient getSesClient(Ses2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ SesClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/Ses2InternalClient.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/Ses2InternalClient.java
deleted file mode 100644
index 45f24d643a723..0000000000000
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/Ses2InternalClient.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.component.aws2.ses.client;
-
-import software.amazon.awssdk.services.ses.SesClient;
-
-/**
- * Manage the required actions of a SES client for either local or remote.
- */
-public interface Ses2InternalClient {
-
- /**
- * Returns an SES client after a factory method determines which one to return.
- *
- * @return SesClient SesClient
- */
- SesClient getSesClient();
-}
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientOptimizedImpl.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientOptimizedImpl.java
deleted file mode 100644
index b487e49bbce6b..0000000000000
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientOptimizedImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.component.aws2.ses.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ses.Ses2Configuration;
-import org.apache.camel.component.aws2.ses.client.Ses2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ses.SesClient;
-import software.amazon.awssdk.services.ses.SesClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MSK client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class Ses2ClientOptimizedImpl implements Ses2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ses2ClientOptimizedImpl.class);
- private Ses2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ses2ClientOptimizedImpl(Ses2Configuration configuration) {
- LOG.trace("Creating an AWS SES client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the SES AWS client that is used.
- *
- * @return SES Client.
- */
- @Override
- public SesClient getSesClient() {
- SesClient client = null;
- SesClientBuilder clientBuilder = SesClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientProfileOptimizedImpl.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientProfileOptimizedImpl.java
deleted file mode 100644
index 7e5d3e4503703..0000000000000
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientProfileOptimizedImpl.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.component.aws2.ses.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ses.Ses2Configuration;
-import org.apache.camel.component.aws2.ses.client.Ses2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ses.SesClient;
-import software.amazon.awssdk.services.ses.SesClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS MSK client for all users to use (enabling temporary creds). This implementation is for remote instances
- * to manage the credentials on their own (eliminating credential rotations)
- */
-public class Ses2ClientProfileOptimizedImpl implements Ses2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ses2ClientProfileOptimizedImpl.class);
- private Ses2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ses2ClientProfileOptimizedImpl(Ses2Configuration configuration) {
- LOG.trace("Creating an AWS SES client for an ec2 instance with IAM temporary credentials (normal for ec2s).");
- this.configuration = configuration;
- }
-
- /**
- * Getting the SES AWS client that is used.
- *
- * @return SES Client.
- */
- @Override
- public SesClient getSesClient() {
- SesClient client = null;
- SesClientBuilder clientBuilder = SesClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientSessionTokenImpl.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientSessionTokenImpl.java
deleted file mode 100644
index fd51eede61b1a..0000000000000
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientSessionTokenImpl.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.component.aws2.ses.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ses.Ses2Configuration;
-import org.apache.camel.component.aws2.ses.client.Ses2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ses.SesClient;
-import software.amazon.awssdk.services.ses.SesClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS SES client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class Ses2ClientSessionTokenImpl implements Ses2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ses2ClientSessionTokenImpl.class);
- private Ses2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ses2ClientSessionTokenImpl(Ses2Configuration configuration) {
- LOG.trace("Creating an AWS SES manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the SES AWS client that is used.
- *
- * @return Amazon SES Client.
- */
- @Override
- public SesClient getSesClient() {
- SesClient client = null;
- SesClientBuilder clientBuilder = SesClient.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
- && configuration.getSessionToken() != null) {
- AwsSessionCredentials cred = AwsSessionCredentials.create(configuration.getAccessKey(),
- configuration.getSecretKey(), configuration.getSessionToken());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientStandardImpl.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientStandardImpl.java
deleted file mode 100644
index cd20dd15b9a4c..0000000000000
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/client/impl/Ses2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.ses.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.ses.Ses2Configuration;
-import org.apache.camel.component.aws2.ses.client.Ses2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.ses.SesClient;
-import software.amazon.awssdk.services.ses.SesClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS SES client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class Ses2ClientStandardImpl implements Ses2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(Ses2ClientStandardImpl.class);
- private Ses2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public Ses2ClientStandardImpl(Ses2Configuration configuration) {
- LOG.trace("Creating an AWS SES manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the SES AWS client that is used.
- *
- * @return Amazon SES Client.
- */
- @Override
- public SesClient getSesClient() {
- SesClient client = null;
- SesClientBuilder clientBuilder = SesClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ClientFactoryTest.java b/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ClientFactoryTest.java
index b194e8787e49e..343663d861734 100644
--- a/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ClientFactoryTest.java
@@ -17,44 +17,43 @@
package org.apache.camel.component.aws2.ses;
import org.apache.camel.component.aws2.ses.client.Ses2ClientFactory;
-import org.apache.camel.component.aws2.ses.client.Ses2InternalClient;
-import org.apache.camel.component.aws2.ses.client.impl.Ses2ClientOptimizedImpl;
-import org.apache.camel.component.aws2.ses.client.impl.Ses2ClientSessionTokenImpl;
-import org.apache.camel.component.aws2.ses.client.impl.Ses2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.ses.SesClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class Ses2ClientFactoryTest {
@Test
- public void getStandardSESClientDefault() {
- Ses2Configuration ses2Configuration = new Ses2Configuration();
- Ses2InternalClient sesClient = Ses2ClientFactory.getSesClient(ses2Configuration);
- assertTrue(sesClient instanceof Ses2ClientStandardImpl);
+ public void getSesClientWithDefaultCredentials() {
+ Ses2Configuration configuration = new Ses2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ SesClient sesClient = Ses2ClientFactory.getSesClient(configuration);
+ assertNotNull(sesClient);
+ sesClient.close();
}
@Test
- public void getStandardSESClient() {
- Ses2Configuration ses2Configuration = new Ses2Configuration();
- ses2Configuration.setUseDefaultCredentialsProvider(false);
- Ses2InternalClient sesClient = Ses2ClientFactory.getSesClient(ses2Configuration);
- assertTrue(sesClient instanceof Ses2ClientStandardImpl);
+ public void getSesClientWithStaticCredentials() {
+ Ses2Configuration configuration = new Ses2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ SesClient sesClient = Ses2ClientFactory.getSesClient(configuration);
+ assertNotNull(sesClient);
+ sesClient.close();
}
@Test
- public void getSESOptimizedIAMClient() {
- Ses2Configuration ses2Configuration = new Ses2Configuration();
- ses2Configuration.setUseDefaultCredentialsProvider(true);
- Ses2InternalClient sesClient = Ses2ClientFactory.getSesClient(ses2Configuration);
- assertTrue(sesClient instanceof Ses2ClientOptimizedImpl);
- }
-
- @Test
- public void getSESSessionTokenImplClient() {
- Ses2Configuration ses2Configuration = new Ses2Configuration();
- ses2Configuration.setUseSessionCredentials(true);
- Ses2InternalClient sesClient = Ses2ClientFactory.getSesClient(ses2Configuration);
- assertTrue(sesClient instanceof Ses2ClientSessionTokenImpl);
+ public void getSesClientWithEndpointOverride() {
+ Ses2Configuration configuration = new Ses2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ SesClient sesClient = Ses2ClientFactory.getSesClient(configuration);
+ assertNotNull(sesClient);
+ sesClient.close();
}
}
diff --git a/components/camel-aws/camel-aws2-sts/pom.xml b/components/camel-aws/camel-aws2-sts/pom.xml
index fdf7173de19b8..54711b913c02c 100644
--- a/components/camel-aws/camel-aws2-sts/pom.xml
+++ b/components/camel-aws/camel-aws2-sts/pom.xml
@@ -40,6 +40,10 @@
org.apache.camel
camel-support
+
+ org.apache.camel
+ camel-aws-common
+
software.amazon.awssdk
sts
diff --git a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Configuration.java b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Configuration.java
index e3c0505b0576e..79c93bc9d2dc4 100644
--- a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Configuration.java
+++ b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Configuration.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.aws2.sts;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.aws.common.AwsCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -26,7 +27,7 @@
import software.amazon.awssdk.services.sts.StsClient;
@UriParams
-public class STS2Configuration implements Cloneable {
+public class STS2Configuration implements Cloneable, AwsCommonConfiguration {
@UriPath(description = "Logical name")
@Metadata(required = true)
@@ -203,18 +204,32 @@ public void setUriEndpointOverride(String uriEndpointOverride) {
* Set whether the STS client should expect to load credentials through a default credentials provider or to expect
* static credentials to be passed in.
*/
- public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) {
+ public void setUseDefaultCredentialsProvider(boolean useDefaultCredentialsProvider) {
this.useDefaultCredentialsProvider = useDefaultCredentialsProvider;
}
- public Boolean isUseDefaultCredentialsProvider() {
+ @Override
+ public boolean isUseDefaultCredentialsProvider() {
return useDefaultCredentialsProvider;
}
+ @Override
public boolean isUseProfileCredentialsProvider() {
return useProfileCredentialsProvider;
}
+ @Override
+ public String getSessionToken() {
+ // STS doesn't use session tokens - it provides them
+ return null;
+ }
+
+ @Override
+ public boolean isUseSessionCredentials() {
+ // STS doesn't use session credentials - it provides them
+ return false;
+ }
+
/**
* Set whether the STS client should expect to load credentials through a profile credentials provider.
*/
diff --git a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Endpoint.java b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Endpoint.java
index d2c9373cfdc06..525faf79c2c1b 100644
--- a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Endpoint.java
+++ b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/STS2Endpoint.java
@@ -65,7 +65,7 @@ public void doStart() throws Exception {
stsClient = configuration.getStsClient() != null
? configuration.getStsClient()
- : STS2ClientFactory.getStsClient(configuration).getStsClient();
+ : STS2ClientFactory.getStsClient(configuration);
}
@Override
diff --git a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/STS2ClientFactory.java b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/STS2ClientFactory.java
index 53bcdc58da82c..cffeb6c19d228 100644
--- a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/STS2ClientFactory.java
+++ b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/STS2ClientFactory.java
@@ -16,13 +16,12 @@
*/
package org.apache.camel.component.aws2.sts.client;
+import org.apache.camel.component.aws.common.AwsClientBuilderUtil;
import org.apache.camel.component.aws2.sts.STS2Configuration;
-import org.apache.camel.component.aws2.sts.client.impl.STS2ClientIAMOptimized;
-import org.apache.camel.component.aws2.sts.client.impl.STS2ClientIAMProfileOptimized;
-import org.apache.camel.component.aws2.sts.client.impl.STS2ClientStandardImpl;
+import software.amazon.awssdk.services.sts.StsClient;
/**
- * Factory class to return the correct type of AWS STS aws.
+ * Factory class to create AWS STS clients using common configuration.
*/
public final class STS2ClientFactory {
@@ -30,18 +29,14 @@ private STS2ClientFactory() {
}
/**
- * Return the correct aws STS client (based on remote vs local).
+ * Create an STS client based on configuration.
*
- * @param configuration configuration
- * @return StsClient
+ * @param configuration The STS configuration
+ * @return Configured StsClient
*/
- public static STS2InternalClient getStsClient(STS2Configuration configuration) {
- if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) {
- return new STS2ClientIAMOptimized(configuration);
- } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) {
- return new STS2ClientIAMProfileOptimized(configuration);
- } else {
- return new STS2ClientStandardImpl(configuration);
- }
+ public static StsClient getStsClient(STS2Configuration configuration) {
+ return AwsClientBuilderUtil.buildClient(
+ configuration,
+ StsClient::builder);
}
}
diff --git a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/STS2InternalClient.java b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/STS2InternalClient.java
deleted file mode 100644
index d30cdc3cb5aa9..0000000000000
--- a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/STS2InternalClient.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.component.aws2.sts.client;
-
-import software.amazon.awssdk.services.sts.StsClient;
-
-public interface STS2InternalClient {
-
- /**
- * Returns an sts client after a factory method determines which one to return.
- *
- * @return StsClient stsClient
- */
- StsClient getStsClient();
-
-}
diff --git a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientIAMOptimized.java b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientIAMOptimized.java
deleted file mode 100644
index a4d5616040f72..0000000000000
--- a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientIAMOptimized.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.component.aws2.sts.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.sts.STS2Configuration;
-import org.apache.camel.component.aws2.sts.client.STS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.sts.StsClient;
-import software.amazon.awssdk.services.sts.StsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS STS client for all users to use. This implementation is for remote instances to manage the credentials
- * on their own (eliminating credential rotations)
- */
-public class STS2ClientIAMOptimized implements STS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(STS2ClientIAMOptimized.class);
- private STS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public STS2ClientIAMOptimized(STS2Configuration configuration) {
- LOG.trace("Creating an AWS STS client for working on AWS Services");
- this.configuration = configuration;
- }
-
- /**
- * Getting the STS aws client that is used.
- *
- * @return Amazon STS Client.
- */
- @Override
- public StsClient getStsClient() {
- StsClient client = null;
- StsClientBuilder clientBuilder = StsClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
-
- 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());
- 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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientIAMProfileOptimized.java b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientIAMProfileOptimized.java
deleted file mode 100644
index 497728e212b5e..0000000000000
--- a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientIAMProfileOptimized.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.component.aws2.sts.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.sts.STS2Configuration;
-import org.apache.camel.component.aws2.sts.client.STS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.sts.StsClient;
-import software.amazon.awssdk.services.sts.StsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS STS client for all users to use. This implementation is for remote instances to manage the credentials
- * on their own (eliminating credential rotations)
- */
-public class STS2ClientIAMProfileOptimized implements STS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(STS2ClientIAMProfileOptimized.class);
- private STS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public STS2ClientIAMProfileOptimized(STS2Configuration configuration) {
- LOG.trace("Creating an AWS STS client for working on AWS Services");
- this.configuration = configuration;
- }
-
- /**
- * Getting the STS aws client that is used.
- *
- * @return Amazon STS Client.
- */
- @Override
- public StsClient getStsClient() {
- StsClient client = null;
- StsClientBuilder clientBuilder = StsClient.builder();
- ProxyConfiguration.Builder proxyConfig = null;
- ApacheHttpClient.Builder httpClientBuilder = null;
-
- 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());
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder);
- }
- if (configuration.getProfileCredentialsName() != null) {
- clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder)
- .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName()));
- }
- if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
- clientBuilder = clientBuilder.region(Region.of(configuration.getRegion()));
- }
- if (configuration.isOverrideEndpoint()) {
- clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride()));
- }
- if (configuration.isTrustAllCertificates()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientStandardImpl.java b/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientStandardImpl.java
deleted file mode 100644
index 9821ea4a4395b..0000000000000
--- a/components/camel-aws/camel-aws2-sts/src/main/java/org/apache/camel/component/aws2/sts/client/impl/STS2ClientStandardImpl.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.component.aws2.sts.client.impl;
-
-import java.net.URI;
-
-import org.apache.camel.component.aws2.sts.STS2Configuration;
-import org.apache.camel.component.aws2.sts.client.STS2InternalClient;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.http.SdkHttpClient;
-import software.amazon.awssdk.http.SdkHttpConfigurationOption;
-import software.amazon.awssdk.http.apache.ApacheHttpClient;
-import software.amazon.awssdk.http.apache.ProxyConfiguration;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.sts.StsClient;
-import software.amazon.awssdk.services.sts.StsClientBuilder;
-import software.amazon.awssdk.utils.AttributeMap;
-
-/**
- * Manage an AWS STS client for all users to use. This implementation is for local instances to use a static and solid
- * credential set.
- */
-public class STS2ClientStandardImpl implements STS2InternalClient {
- private static final Logger LOG = LoggerFactory.getLogger(STS2ClientStandardImpl.class);
- private STS2Configuration configuration;
-
- /**
- * Constructor that uses the config file.
- */
- public STS2ClientStandardImpl(STS2Configuration configuration) {
- LOG.trace("Creating an AWS STS manager using static credentials.");
- this.configuration = configuration;
- }
-
- /**
- * Getting the STS aws client that is used.
- *
- * @return Amazon STS Client.
- */
- @Override
- public StsClient getStsClient() {
- StsClient client = null;
- StsClientBuilder clientBuilder = StsClient.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()) {
- if (httpClientBuilder == null) {
- httpClientBuilder = ApacheHttpClient.builder();
- }
- SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap
- .builder()
- .put(
- SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES,
- Boolean.TRUE)
- .build());
- // set created http client to use instead of builder
- clientBuilder.httpClient(ahc);
- clientBuilder.httpClientBuilder(null);
- }
- client = clientBuilder.build();
- return client;
- }
-}
diff --git a/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ClientFactoryTest.java b/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ClientFactoryTest.java
index d9aa7ce527862..1cc30dfdd958d 100644
--- a/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ClientFactoryTest.java
+++ b/components/camel-aws/camel-aws2-sts/src/test/java/org/apache/camel/component/aws2/sts/STS2ClientFactoryTest.java
@@ -17,35 +17,43 @@
package org.apache.camel.component.aws2.sts;
import org.apache.camel.component.aws2.sts.client.STS2ClientFactory;
-import org.apache.camel.component.aws2.sts.client.STS2InternalClient;
-import org.apache.camel.component.aws2.sts.client.impl.STS2ClientIAMOptimized;
-import org.apache.camel.component.aws2.sts.client.impl.STS2ClientStandardImpl;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.sts.StsClient;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class STS2ClientFactoryTest {
@Test
- public void getStandardSTSClientDefault() {
- STS2Configuration sts2Configuration = new STS2Configuration();
- STS2InternalClient stsClient = STS2ClientFactory.getStsClient(sts2Configuration);
- assertTrue(stsClient instanceof STS2ClientStandardImpl);
+ public void getStsClientWithDefaultCredentials() {
+ STS2Configuration configuration = new STS2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ StsClient stsClient = STS2ClientFactory.getStsClient(configuration);
+ assertNotNull(stsClient);
+ stsClient.close();
}
@Test
- public void getStandardSTSClient() {
- STS2Configuration sts2Configuration = new STS2Configuration();
- sts2Configuration.setUseDefaultCredentialsProvider(false);
- STS2InternalClient stsClient = STS2ClientFactory.getStsClient(sts2Configuration);
- assertTrue(stsClient instanceof STS2ClientStandardImpl);
+ public void getStsClientWithStaticCredentials() {
+ STS2Configuration configuration = new STS2Configuration();
+ configuration.setAccessKey("testAccessKey");
+ configuration.setSecretKey("testSecretKey");
+ configuration.setRegion("eu-west-1");
+ StsClient stsClient = STS2ClientFactory.getStsClient(configuration);
+ assertNotNull(stsClient);
+ stsClient.close();
}
@Test
- public void getSTSOptimizedIAMClient() {
- STS2Configuration sts2Configuration = new STS2Configuration();
- sts2Configuration.setUseDefaultCredentialsProvider(true);
- STS2InternalClient stsClient = STS2ClientFactory.getStsClient(sts2Configuration);
- assertTrue(stsClient instanceof STS2ClientIAMOptimized);
+ public void getStsClientWithEndpointOverride() {
+ STS2Configuration configuration = new STS2Configuration();
+ configuration.setUseDefaultCredentialsProvider(true);
+ configuration.setRegion("eu-west-1");
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride("http://localhost:4566");
+ StsClient stsClient = STS2ClientFactory.getStsClient(configuration);
+ assertNotNull(stsClient);
+ stsClient.close();
}
}