You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
48 lines
1.5 KiB
package kr.re.etri.autoflow.common;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
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.S3ClientBuilder;
|
|
|
|
import java.net.URI;
|
|
|
|
@Configuration
|
|
public class AwsConfig {
|
|
|
|
@Value("${storage.provider:s3}")
|
|
private String storageProvider;
|
|
|
|
@Value("${cloud.aws.credentials.access-key:minio}")
|
|
private String accessKey;
|
|
|
|
@Value("${cloud.aws.credentials.secret-key:minio123}")
|
|
private String secretKey;
|
|
|
|
@Value("${cloud.aws.region.static:ap-northeast-2}")
|
|
private String region;
|
|
|
|
@Value("${minio.endpoint:http://localhost:9000}")
|
|
private String minioEndpoint;
|
|
|
|
@Bean
|
|
public S3Client s3Client() {
|
|
AwsBasicCredentials credentials = AwsBasicCredentials.create(accessKey, secretKey);
|
|
|
|
S3ClientBuilder builder = S3Client.builder()
|
|
.region(Region.of(region))
|
|
.credentialsProvider(StaticCredentialsProvider.create(credentials));
|
|
|
|
if ("minio".equalsIgnoreCase(storageProvider)) {
|
|
builder.endpointOverride(URI.create(minioEndpoint))
|
|
.forcePathStyle(true);
|
|
}
|
|
|
|
return builder.build();
|
|
}
|
|
}
|