Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] s3 properties 수정 #151

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading