-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to customize httpClientBuilder for s3 client #50
base: master
Are you sure you want to change the base?
Conversation
@@ -301,12 +312,33 @@ private BlobStorageClient createAmazonS3Client() { | |||
this.getAmazonEndpointOverride().ifPresent(clientBuilder::endpointOverride); | |||
this.getAmazonRegion().ifPresent(clientBuilder::region); | |||
this.getAmazonCredentialsProvider().ifPresent(clientBuilder::credentialsProvider); | |||
if (this.getTlsTrustManagerProvider().isPresent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use ifPresent API as seen above
@@ -69,6 +69,7 @@ void shouldRoundtrip(final RoundtripArgument argument) { | |||
final String bucket = "bucket"; | |||
final String basePath = "s3://" + bucket + "/base/"; | |||
final Map<String, Object> properties = ImmutableMap.<String, Object>builder() | |||
.put(AbstractLargeMessageConfig.S3_TLS_TRUST_MANAGER_PROVIDER_CONFIG,DefaultTlsTrustManagersProvider.class.getName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.put(AbstractLargeMessageConfig.S3_TLS_TRUST_MANAGER_PROVIDER_CONFIG,DefaultTlsTrustManagersProvider.class.getName()) | |
.put(AbstractLargeMessageConfig.S3_TLS_TRUST_MANAGER_PROVIDER_CONFIG, DefaultTlsTrustManagersProvider.class.getName()) |
@@ -36,6 +36,7 @@ | |||
import io.confluent.common.config.ConfigDef; | |||
import io.confluent.common.config.ConfigDef.Importance; | |||
import io.confluent.common.config.ConfigDef.Type; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting does not follow our guildes in the README
if (this.enableAmazonS3PathStyleAccess()) { | ||
clientBuilder.forcePathStyle(true); | ||
} | ||
return new AmazonS3Client(clientBuilder.build()); | ||
} | ||
|
||
private Optional<TlsTrustManagersProvider> getTlsTrustManagerProvider() { | ||
Class<?> c = this.getClass(S3_TLS_TRUST_MANAGER_PROVIDER_CONFIG); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class<?> c = this.getClass(S3_TLS_TRUST_MANAGER_PROVIDER_CONFIG); | |
final Class<?> c = this.getClass(S3_TLS_TRUST_MANAGER_PROVIDER_CONFIG); |
if (c == null) { | ||
return Optional.empty(); | ||
} else { | ||
Object o = Utils.newInstance(c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object o = Utils.newInstance(c); | |
final Object o = Utils.newInstance(c); |
@@ -301,12 +312,33 @@ private BlobStorageClient createAmazonS3Client() { | |||
this.getAmazonEndpointOverride().ifPresent(clientBuilder::endpointOverride); | |||
this.getAmazonRegion().ifPresent(clientBuilder::region); | |||
this.getAmazonCredentialsProvider().ifPresent(clientBuilder::credentialsProvider); | |||
if (this.getTlsTrustManagerProvider().isPresent()) { | |||
clientBuilder.httpClientBuilder( | |||
ApacheHttpClient.builder().tlsTrustManagersProvider( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which client is used by default? Would it be instead feasible to specify a HttpClientProvider and the user can implement it? Then we can get rid of the dependency on the apache module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments, I will try to figure out if it is feasible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is software.amazon.awssdk.core.internal.http.loader.DefaultSdkHttpClientBuilder
And I update the PR to let user specify the HttpClientProvider instead of TlsTrustManagerProvider
437a6cf
to
47b61e7
Compare
Pull Request
What
Add a new parameter S3_SDK_HTTP_CLIENT_BUILDER_CONFIG
This is a class to customize the httpClient used by the s3 client
Why
Our use case is:
We have a minio server with https endpoint. And the minio server uses self-signed certificate to do the TLS.
When our kafka client uses this lib to put object to that minio, we need to make sure the CA certificate of the minio server should in the truststore used by the s3 client. This is the reason we want to customize the httpClient.
Another limitation is that we need add the CA certificate to the truststore in the code instead of using the keytool command line. Since the command line is hard to automate in our use case. So finally I choose add this support in the this lib.
How
Test
I added this parameter with DefaultTlsTrustManagersProvider in the UT and it works fine.