Skip to content
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

S3: Add possibility to configure the endpoint, accessKey, accessSecret, pathStyleAccessEnabled #645

Closed
thijslemmens opened this issue Oct 14, 2021 · 3 comments · Fixed by #649

Comments

@thijslemmens
Copy link

thijslemmens commented Oct 14, 2021

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.

@paulcwarren
Copy link
Owner

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

@thijslemmens
Copy link
Author

thijslemmens commented Oct 21, 2021

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

@paulcwarren
Copy link
Owner

paulcwarren commented Oct 22, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants