-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Environment 환경 분리 * test: dev profile swagger permitAll * fix: fixtureMokey 수정 * refactor: dev 환경 배포 테스트 * refactor: dev 환경 배포 테스트 * fix: fixtureMokey 수정 * test: dev profile swagger permitAll * refactor: dev 환경 배포 테스트 * fix: push branch develop으로 변경 * fix: profile 예외 메세지
- Loading branch information
Showing
12 changed files
with
276 additions
and
19 deletions.
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.