From 782e08d37e682fc837c87a2c1fd9b293fb3e563e Mon Sep 17 00:00:00 2001 From: SeHwan Bong Date: Sat, 20 Jan 2024 15:05:56 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20s3=20properties=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#144=20(#151)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/core/properties/S3Properties.java | 43 ++++++++++++++++--- Core/src/main/resources/application-core.yml | 11 ++--- .../outer/s3/config/S3Config.java | 15 ++----- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/Core/src/main/java/tify/server/core/properties/S3Properties.java b/Core/src/main/java/tify/server/core/properties/S3Properties.java index d066737..8fead65 100644 --- a/Core/src/main/java/tify/server/core/properties/S3Properties.java +++ b/Core/src/main/java/tify/server/core/properties/S3Properties.java @@ -3,20 +3,53 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.Setter; +import org.apache.http.auth.Credentials; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConstructorBinding; @Getter @AllArgsConstructor @ConstructorBinding -@ConfigurationProperties(prefix = "s3") +@ConfigurationProperties(prefix = "cloud.aws") public class S3Properties { - private String accessKey; + private Credentials credentials; + private S3 s3; + private Region region; - private String secretKey; + @Getter + @Setter + public static class Credentials { + private String accessKey; + private String secretKey; + } - private String region; + @Getter + @Setter + public static class S3 { + private String bucket; + } - private String bucketName; + @Getter + @Setter + public static class Region { + private String name; + } + + public String getAccessKey() { + return credentials.getAccessKey(); + } + + public String getSecretKey() { + return credentials.getSecretKey(); + } + + public String getBucketName() { + return s3.getBucket(); + } + + public String getRegion() { + return region.getName(); + } } diff --git a/Core/src/main/resources/application-core.yml b/Core/src/main/resources/application-core.yml index b9f1524..c394b97 100644 --- a/Core/src/main/resources/application-core.yml +++ b/Core/src/main/resources/application-core.yml @@ -23,11 +23,11 @@ oauth2: key-path: ${APPLE_KEY_PATH} key: ${APPLE_KEY} -s3: - region: ${S3_REGION} - access-key: ${S3_ACCESS_KEY} - secret-key: ${S3_SECRET_KEY} - bucket-name: ${S3_BUCKET_NAME} +#s3: +# region: ${S3_REGION} +# access-key: ${S3_ACCESS_KEY} +# secret-key: ${S3_SECRET_KEY} +# bucket-name: ${S3_BUCKET_NAME} cloud: aws: @@ -37,6 +37,7 @@ cloud: s3: bucket: ${S3_BUCKET_NAME} region: + name: ${S3_REGION} static: ap-northeast-2 stack: auto: false \ No newline at end of file diff --git a/Infrastructure/src/main/java/tify/server/infrastructure/outer/s3/config/S3Config.java b/Infrastructure/src/main/java/tify/server/infrastructure/outer/s3/config/S3Config.java index bfa51b5..fc87739 100644 --- a/Infrastructure/src/main/java/tify/server/infrastructure/outer/s3/config/S3Config.java +++ b/Infrastructure/src/main/java/tify/server/infrastructure/outer/s3/config/S3Config.java @@ -6,7 +6,6 @@ import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import tify.server.core.properties.S3Properties; @@ -17,21 +16,13 @@ public class S3Config { private final S3Properties s3Properties; - @Value("${cloud.aws.credentials.accessKey}") - private String accessKey; - - @Value("${cloud.aws.credentials.secretKey}") - private String secretKey; - - @Value("${cloud.aws.region.static}") - private String region; - @Bean public AmazonS3Client amazonS3Client() { - BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); + BasicAWSCredentials awsCredentials = + new BasicAWSCredentials(s3Properties.getAccessKey(), s3Properties.getSecretKey()); return (AmazonS3Client) AmazonS3ClientBuilder.standard() - .withRegion(region) + .withRegion(s3Properties.getRegion()) .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) .build(); }