S3: Add possibility to configure the endpoint, accessKey, accessSecret, pathStyleAccessEnabled
Closed this issue · 3 comments
Describe the solution you'd like
It is already possible to configure the bucket to use spring.content.s3.bucket
. I'd like to have the option to add:
spring.content.s3.endpoint
spring.content.s3.accessKey
spring.content.s3.secretKey
spring.content.s3.pathStyleAccessEnabled
These options can be picked up by the spring-content-s3-boot-starter
to instantiate the AmazonS3 client without the need for application specific code.
Additional context
I'm using an S3 compatible storage provider that requires setting the endpoint and enable pathStyleAccess.
Hi @thijslemmens,
Are you connecting to minio? I was looking at this example. For your use case do you know if you have to set region and signer override in addition to these attributes?
Thanks
Hello @paulcwarren
No, we are not using Minio. We use a proprietary object storage solution (Datacore SWARM).
Currently we use this code to create the client:
@Bean
@ConditionalOnProperty(prefix = "spring.content.storage", name = "type", havingValue = "s3")
public AmazonS3 s3Client(S3ClientProperties s3ClientProperties) {
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
final String accessKey = s3ClientProperties.getAccessKey();
final String secretKey = s3ClientProperties.getSecretKey();
if (StringUtils.hasText(accessKey) || StringUtils.hasText(secretKey)) {
log.info("-- setting up s3client with accessKey: {} secretKey: {}",
accessKey.substring(0, 5) + accessKey.substring(5).replaceAll(".", "*"),
secretKey.substring(0, 5) + secretKey.substring(5).replaceAll(".", "*"));
builder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
} else {
log.info("No accessKey or secretKey configured, using default credentials provider chain");
}
final String endpoint = s3ClientProperties.getEndpoint();
if (StringUtils.hasText(endpoint)) {
builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null));
}
builder.setPathStyleAccessEnabled(true);
return builder.build();
}
That works, so I think the list of attributes is big enough for this use case. It makes sense to have a check that minio could work as well.
kind regards
OK. That's helpful and almost exactly what I have actually. So, I'll try not expose a region property then as it seems you don't need it.
This code makes existing tests fail in CI. I presume because moving to the AmazonS3ClientBuilder doesn't automatically set a region. Whereas instantiating AmzonS3Client directly does. But that is my problem to figure out.
Thanks for the info.