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

chore: Object Storage -> AWS S3 Bucket 으로 변경 #395

Merged
merged 2 commits into from
May 15, 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 @@ -25,7 +25,7 @@
import com.depromeet.global.error.exception.ErrorCode;
import com.depromeet.global.util.MemberUtil;
import com.depromeet.global.util.SpringEnvironmentUtil;
import com.depromeet.infra.config.storage.StorageProperties;
import com.depromeet.infra.config.s3.S3Properties;
import java.util.Date;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand All @@ -38,7 +38,7 @@
public class ImageService {
private final MemberUtil memberUtil;
private final SpringEnvironmentUtil springEnvironmentUtil;
private final StorageProperties storageProperties;
private final S3Properties s3Properties;
private final AmazonS3 amazonS3;
private final MissionRecordRepository missionRecordRepository;
private final MissionRecordTtlRepository missionRecordTtlRepository;
Expand All @@ -62,7 +62,7 @@ public PresignedUrlResponse createMissionRecordPresignedUrl(
request.imageFileExtension());
GeneratePresignedUrlRequest generatePresignedUrlRequest =
createGeneratePreSignedUrlRequest(
storageProperties.bucket(),
s3Properties.bucket(),
fileName,
request.imageFileExtension().getUploadExtension());

Expand Down Expand Up @@ -113,7 +113,7 @@ public PresignedUrlResponse createMemberProfilePresignedUrl(
request.imageFileExtension());
GeneratePresignedUrlRequest generatePresignedUrlRequest =
createGeneratePreSignedUrlRequest(
storageProperties.bucket(),
s3Properties.bucket(),
fileName,
request.imageFileExtension().getUploadExtension());

Expand Down Expand Up @@ -205,9 +205,9 @@ private String createUploadImageUrl(
Long targetId,
String imageKey,
ImageFileExtension imageFileExtension) {
return storageProperties.endpoint()
return s3Properties.endpoint()
+ "/"
+ storageProperties.bucket()
+ s3Properties.bucket()
+ "/"
+ springEnvironmentUtil.getCurrentProfile()
+ "/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.depromeet.infra.config.jwt.JwtProperties;
import com.depromeet.infra.config.oidc.OidcProperties;
import com.depromeet.infra.config.redis.RedisProperties;
import com.depromeet.infra.config.storage.StorageProperties;
import com.depromeet.infra.config.s3.S3Properties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@EnableConfigurationProperties({
StorageProperties.class,
S3Properties.class,
RedisProperties.class,
JwtProperties.class,
OidcProperties.class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.depromeet.infra.config.storage;
package com.depromeet.infra.config.s3;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
Expand All @@ -12,17 +12,16 @@

@Configuration
@RequiredArgsConstructor
public class StorageConfig {
private final StorageProperties storageProperties;
public class S3Config {
private final S3Properties s3Properties;

@Bean
public AmazonS3 amazonS3() {
AWSCredentials credentials =
new BasicAWSCredentials(
storageProperties.accessKey(), storageProperties.secretKey());
new BasicAWSCredentials(s3Properties.accessKey(), s3Properties.secretKey());
AwsClientBuilder.EndpointConfiguration endpointConfiguration =
new AwsClientBuilder.EndpointConfiguration(
storageProperties.endpoint(), storageProperties.region());
s3Properties.endpoint(), s3Properties.region());

return AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(endpointConfiguration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.depromeet.infra.config.storage;
package com.depromeet.infra.config.s3;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "storage")
public record StorageProperties(
public record S3Properties(
String accessKey, String secretKey, String region, String bucket, String endpoint) {}
10 changes: 5 additions & 5 deletions src/main/resources/application-storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ spring:
activate:
on-profile: "storage"
storage:
accessKey: ${STORAGE_ACCESS_KEY:}
secretKey: ${STORAGE_SECRET_KEY:}
bucket: ${STORAGE_BUCKET:}
region: ${STORAGE_REGION:}
endpoint: ${STORAGE_ENDPOINT:https://kr.object.ncloudstorage.com}
accessKey: ${AWS_ACCESS_KEY:}
secretKey: ${AWS_SECRET_KEY:}
bucket: ${S3_BUCKET:}
region: ${AWS_REGION:}
endpoint: ${S3_ENDPOINT:https://s3.ap-northeast-2.amazonaws.com}
Loading