-
Notifications
You must be signed in to change notification settings - Fork 2
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
[WALWAL-148] Dev, Prod 환경 분리 #56
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
52153f0
feat: Environment 환경 분리
char-yb 175afb5
test: dev profile swagger permitAll
char-yb f9c3099
fix: fixtureMokey 수정
char-yb 548ee0b
refactor: dev 환경 배포 테스트
char-yb 4e02730
refactor: dev 환경 배포 테스트
char-yb af0f7f1
fix: fixtureMokey 수정
char-yb a0c1f6a
test: dev profile swagger permitAll
char-yb 7c4a0b9
refactor: dev 환경 배포 테스트
char-yb 75aed9b
fix: push branch develop으로 변경
char-yb 845b4ad
fix: profile 예외 메세지
char-yb 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 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 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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/depromeet/stonebed/global/annotation/ConditionalOnProfile.java
This file contains 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,15 @@ | ||
package com.depromeet.stonebed.global.annotation; | ||
|
||
import com.depromeet.stonebed.global.common.constants.EnvironmentConstants; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.context.annotation.Conditional; | ||
|
||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Conditional({OnProfileCondition.class}) | ||
public @interface ConditionalOnProfile { | ||
EnvironmentConstants[] value() default {EnvironmentConstants.LOCAL}; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/depromeet/stonebed/global/annotation/OnProfileCondition.java
This file contains 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,32 @@ | ||
package com.depromeet.stonebed.global.annotation; | ||
|
||
import static java.util.Objects.*; | ||
|
||
import com.depromeet.stonebed.global.common.constants.EnvironmentConstants; | ||
import java.util.Arrays; | ||
import org.springframework.context.annotation.Condition; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
public class OnProfileCondition implements Condition { | ||
|
||
@Override | ||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
String[] activeProfiles = context.getEnvironment().getActiveProfiles(); | ||
EnvironmentConstants[] targetProfiles = getTargetProfiles(metadata); | ||
|
||
return Arrays.stream(targetProfiles) | ||
.anyMatch( | ||
targetProfile -> | ||
Arrays.asList(activeProfiles).contains(targetProfile.getValue())); | ||
} | ||
|
||
private EnvironmentConstants[] getTargetProfiles(AnnotatedTypeMetadata metadata) { | ||
return (EnvironmentConstants[]) | ||
requireNonNull( | ||
metadata.getAnnotationAttributes( | ||
ConditionalOnProfile.class.getName()), | ||
"target Profiles가 null입니다.") | ||
.get("value"); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/depromeet/stonebed/global/common/constants/EnvironmentConstants.java
This file contains 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,27 @@ | ||
package com.depromeet.stonebed.global.common.constants; | ||
|
||
import static com.depromeet.stonebed.global.common.constants.EnvironmentConstants.Constants.*; | ||
|
||
import java.util.List; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum EnvironmentConstants { | ||
PROD(PROD_ENV), | ||
DEV(DEV_ENV), | ||
LOCAL(LOCAL_ENV); | ||
|
||
private final String value; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public static class Constants { | ||
public static final String PROD_ENV = "prod"; | ||
public static final String DEV_ENV = "dev"; | ||
public static final String LOCAL_ENV = "local"; | ||
public static final List<String> PROD_AND_DEV_ENV = List.of(PROD_ENV, DEV_ENV); | ||
} | ||
} |
This file contains 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 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 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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/depromeet/stonebed/global/util/SpringEnvironmentUtil.java
This file contains 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,39 @@ | ||
package com.depromeet.stonebed.global.util; | ||
|
||
import static com.depromeet.stonebed.global.common.constants.EnvironmentConstants.Constants.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Stream; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class SpringEnvironmentUtil { | ||
|
||
private final Environment environment; | ||
|
||
public String getCurrentProfile() { | ||
return getActiveProfiles() | ||
.filter(profile -> profile.equals(PROD_ENV) || profile.equals(DEV_ENV)) | ||
.findFirst() | ||
.orElse(LOCAL_ENV); | ||
} | ||
|
||
public boolean isProdProfile() { | ||
return getActiveProfiles().anyMatch(PROD_ENV::equals); | ||
} | ||
|
||
public boolean isDevProfile() { | ||
return getActiveProfiles().anyMatch(DEV_ENV::equals); | ||
} | ||
|
||
public boolean isProdAndDevProfile() { | ||
return getActiveProfiles().anyMatch(PROD_AND_DEV_ENV::contains); | ||
} | ||
|
||
private Stream<String> getActiveProfiles() { | ||
return Arrays.stream(environment.getActiveProfiles()); | ||
} | ||
} |
This file contains 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 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
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.
이 부분에서 requireNonNull로 널 체크를 하고 있는데 명시적으로 예외처리를 체크하는 건 어떤가요?
Optional 처리해서 널 값다루거나 예외를 던지는 식으로요!
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.
requireNonNull의 두 번째 인자로 에러 메세지를 던지는 방식은 어떤가용??
"target Profiles가 null입니다." 이런 식으로요!
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.
원래는 if문을 통한 예외 처리가 일반적이라고 생각했는데, 보내주신 레퍼런스를 확인해보니 requireNonNull로 처리하고 에러메세지를 던지는것도 가독성이 좋아보이네용! 좋습니다~!