-
Notifications
You must be signed in to change notification settings - Fork 4
supabase 버킷 데이터 조회 구현 #137
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
Open
Gyu-won
wants to merge
2
commits into
dev
Choose a base branch
from
Feat/issue-#136
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ out/ | |
| /newrelic | ||
| .secrets | ||
| .env | ||
| .env.local | ||
| .env.dev | ||
| .env.redis | ||
| .env.redis.dev | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
src/main/java/com/newzet/api/common/storage/StorageService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package com.newzet.api.common.storage; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import com.amazonaws.services.s3.AmazonS3; | ||
| import com.amazonaws.services.s3.model.AmazonS3Exception; | ||
| import com.amazonaws.services.s3.model.GetObjectRequest; | ||
| import com.amazonaws.services.s3.model.S3Object; | ||
| import com.amazonaws.services.s3.model.S3ObjectInputStream; | ||
| import com.newzet.api.common.exception.InternalErrorException; | ||
| import com.newzet.api.config.storage.StorageConfig; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Service | ||
| @Slf4j | ||
| public class StorageService { | ||
|
|
||
| private final AmazonS3 awsS3Client; | ||
| private final AmazonS3 supabaseS3Client; | ||
| private final StorageConfig storageConfig; | ||
|
|
||
| public StorageService(@Qualifier("awsS3Client") AmazonS3 awsS3Client, | ||
| @Qualifier("supabaseS3Client") AmazonS3 supabaseS3Client, | ||
| StorageConfig storageConfig) { | ||
| this.awsS3Client = awsS3Client; | ||
| this.supabaseS3Client = supabaseS3Client; | ||
| this.storageConfig = storageConfig; | ||
| } | ||
|
|
||
| public String getContent(String key, boolean isSaveInStorage) { | ||
| AmazonS3 client; | ||
| String bucketName; | ||
|
|
||
| if (isSaveInStorage) { | ||
| client = supabaseS3Client; | ||
| bucketName = storageConfig.getSupabaseBucketName(); | ||
| } else { | ||
| client = awsS3Client; | ||
| bucketName = storageConfig.getAwsBucketName(); | ||
| } | ||
|
|
||
| GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key); | ||
|
|
||
| try (S3Object s3Object = client.getObject(getObjectRequest); | ||
| S3ObjectInputStream inputStream = s3Object.getObjectContent()) { | ||
|
|
||
| byte[] contentBytes = inputStream.readAllBytes(); | ||
| return new String(contentBytes, StandardCharsets.UTF_8); | ||
|
|
||
| } catch (AmazonS3Exception e) { | ||
| log.error("Storage에서 객체를 가져오는 중 오류가 발생했습니다. Key: {}", key, e); | ||
| throw new InternalErrorException("아티클을 불러오는 과정에서 에러가 발생하였습니다."); | ||
| } catch (IOException e) { | ||
| log.error("Storage 파일 내용을 읽는 중 I/O 오류가 발생했습니다.", e); | ||
| throw new InternalErrorException("아티클을 불러오는 과정에서 에러가 발생하였습니다."); | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/main/java/com/newzet/api/config/storage/StorageConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.newzet.api.config.storage; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Qualifier; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import com.amazonaws.auth.AWSCredentials; | ||
| import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
| import com.amazonaws.auth.BasicAWSCredentials; | ||
| import com.amazonaws.client.builder.AwsClientBuilder; | ||
| import com.amazonaws.services.s3.AmazonS3; | ||
| import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Configuration | ||
| @Getter | ||
| public class StorageConfig { | ||
|
|
||
| // AWS S3 Credentials | ||
| @Value("${cloud.aws.s3.bucket}") | ||
| private String awsBucketName; | ||
| @Value("${cloud.aws.region.static}") | ||
| private String awsRegion; | ||
| @Value("${cloud.aws.credentials.access-key}") | ||
| private String awsAccessKey; | ||
| @Value("${cloud.aws.credentials.secret-key}") | ||
| private String awsSecretKey; | ||
|
|
||
| // Supabase S3-compatible Storage Credentials | ||
| @Value("${cloud.supabase.storage.bucket}") | ||
| private String supabaseBucketName; | ||
| @Value("${cloud.supabase.storage.region}") | ||
| private String supabaseRegion; | ||
| @Value("${cloud.supabase.storage.endpoint-url}") | ||
| private String supabaseEndpointUrl; | ||
| @Value("${cloud.supabase.storage.credentials.access-key}") | ||
| private String supabaseAccessKey; | ||
| @Value("${cloud.supabase.storage.credentials.secret-key}") | ||
| private String supabaseSecretKey; | ||
|
|
||
| @Bean | ||
| @Qualifier("awsS3Client") | ||
| public AmazonS3 awsS3Client() { | ||
| AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); | ||
| return AmazonS3ClientBuilder.standard() | ||
| .withRegion(awsRegion) | ||
| .withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean | ||
| @Qualifier("supabaseS3Client") | ||
| public AmazonS3 supabaseS3Client() { | ||
| AWSCredentials credentials = new BasicAWSCredentials(supabaseAccessKey, supabaseSecretKey); | ||
| AwsClientBuilder.EndpointConfiguration endpointConfig = | ||
| new AwsClientBuilder.EndpointConfiguration(supabaseEndpointUrl, supabaseRegion); | ||
|
|
||
| return AmazonS3ClientBuilder.standard() | ||
| .withEndpointConfiguration(endpointConfig) | ||
| .withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,4 +70,13 @@ cloud: | |
| static: ${S3_REGION} | ||
| credentials: | ||
| access-key: ${S3_ACCESS_KEY} | ||
| secret-key: ${S3_SECRET_KEY} | ||
| secret-key: ${S3_SECRET_KEY} | ||
|
|
||
| supabase: | ||
| storage: | ||
| bucket: ${SUPABASE_BUCKET_NAME} | ||
| endpoint-url: ${SUPABASE_ENDPOINT_URL} | ||
| region: ${SUPABASE_REGION} | ||
| credentials: | ||
| access-key: ${SUPABASE_ACCESS_KEY} | ||
| secret-key: ${SUPABASE_SECRET_KEY} | ||
|
Comment on lines
+75
to
+82
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추가된 값 배포 전에 노션에 최신화 부탁드립니다! 서버단에 바로 적용하겠습니다 |
||
100 changes: 0 additions & 100 deletions
100
src/test/java/com/newzet/api/common/s3/S3ServiceTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금은 꼭 필요할 것 같지는 않습니다만
확장성을 고려해서 포트 기반 구현체로 추후 리팩터링 과정에서 도입해도 좋을 것 같네영