53 lines
1.6 KiB
Java
53 lines
1.6 KiB
Java
package com.krylov.refound.config;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
|
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
|
import software.amazon.awssdk.regions.Region;
|
|
import software.amazon.awssdk.services.s3.S3Client;
|
|
import software.amazon.awssdk.services.s3.S3Configuration;
|
|
|
|
import java.net.URI;
|
|
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
|
|
|
|
@Configuration
|
|
@RequiredArgsConstructor
|
|
public class S3ClientConfig {
|
|
|
|
private final MinioProperties properties;
|
|
|
|
@Bean
|
|
public S3Client s3Client() {
|
|
return S3Client.builder()
|
|
.endpointOverride(URI.create(properties.endpoint()))
|
|
.region(Region.of(properties.region()))
|
|
.credentialsProvider(credentialsProvider())
|
|
.serviceConfiguration(pathStyleConfiguration())
|
|
.build();
|
|
}
|
|
|
|
@Bean
|
|
public S3Presigner s3Presigner() {
|
|
return S3Presigner.builder()
|
|
.endpointOverride(URI.create(properties.endpoint()))
|
|
.region(Region.of(properties.region()))
|
|
.credentialsProvider(credentialsProvider())
|
|
.serviceConfiguration(pathStyleConfiguration())
|
|
.build();
|
|
}
|
|
|
|
private StaticCredentialsProvider credentialsProvider() {
|
|
return StaticCredentialsProvider.create(
|
|
AwsBasicCredentials.create(properties.accessKey(), properties.secretKey()));
|
|
}
|
|
|
|
private S3Configuration pathStyleConfiguration() {
|
|
return S3Configuration.builder()
|
|
.pathStyleAccessEnabled(true)
|
|
.build();
|
|
}
|
|
|
|
}
|