Skip to content

Commit

Permalink
refactor : s3 properties 수정 #144 (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
bongsh0112 authored Jan 20, 2024
1 parent 6d79596 commit 782e08d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
43 changes: 38 additions & 5 deletions Core/src/main/java/tify/server/core/properties/S3Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
11 changes: 6 additions & 5 deletions Core/src/main/resources/application-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -37,6 +37,7 @@ cloud:
s3:
bucket: ${S3_BUCKET_NAME}
region:
name: ${S3_REGION}
static: ap-northeast-2
stack:
auto: false
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down

0 comments on commit 782e08d

Please sign in to comment.