package com.caliverse.admin.global.configuration; import lombok.RequiredArgsConstructor; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; 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; @Configuration @RequiredArgsConstructor public class S3Config { @Value("${amazon.aws.accesskey}") private String accessKey; @Value("${amazon.aws.secretkey}") private String secretKey; @Value("${amazon.aws.region}") private String region; @Bean @ConditionalOnProperty(name = "amazon.s3.enabled", havingValue = "true") public S3Client s3Client() { if(!accessKey.isEmpty()) { AwsBasicCredentials credentials = AwsBasicCredentials.create(accessKey, secretKey); return S3Client.builder() .credentialsProvider(StaticCredentialsProvider.create(credentials)) .region(Region.of(region)) .build(); } return S3Client.builder() .build(); } }