|
|
|
|
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 org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnProperty(name = "storage.provider", havingValue = "s3")
|
|
|
|
|
public class AwsConfig {
|
|
|
|
|
|
|
|
|
|
@Value("${cloud.aws.credentials.access-key}")
|
|
|
|
|
private String accessKey;
|
|
|
|
|
|
|
|
|
|
@Value("${cloud.aws.credentials.secret-key}")
|
|
|
|
|
private String secretKey;
|
|
|
|
|
|
|
|
|
|
@Value("${cloud.aws.region.static}")
|
|
|
|
|
private String region;
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public S3Client s3Client() {
|
|
|
|
|
AwsBasicCredentials credentials = AwsBasicCredentials.create(accessKey, secretKey);
|
|
|
|
|
|
|
|
|
|
return S3Client.builder()
|
|
|
|
|
.region(Region.of(region))
|
|
|
|
|
.credentialsProvider(StaticCredentialsProvider.create(credentials))
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}
|