-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLAP-406 CI/CD: DevelopOnlyApi 어노테이션 적용
<footer> - #524
- Loading branch information
1 parent
7e5e946
commit 4746857
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/clap/server/common/utils/SpringEnvironmentHelper.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,46 @@ | ||
package clap.server.common.utils; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class SpringEnvironmentHelper { | ||
|
||
private final Environment environment; | ||
|
||
private final String PROD = "prod"; | ||
private final String DEV = "dev"; | ||
private final String LOCAL = "local"; | ||
|
||
private final List<String> LOCAL_AND_DEV = List.of("local", "dev"); | ||
|
||
public Boolean isProdProfile() { | ||
String[] activeProfiles = environment.getActiveProfiles(); | ||
List<String> currentProfile = Arrays.stream(activeProfiles).toList(); | ||
return currentProfile.contains(PROD); | ||
} | ||
|
||
public Boolean isLocalProfile() { | ||
String[] activeProfiles = environment.getActiveProfiles(); | ||
List<String> currentProfile = Arrays.stream(activeProfiles).toList(); | ||
return currentProfile.contains(LOCAL); | ||
} | ||
|
||
public Boolean isDevProfile() { | ||
String[] activeProfiles = environment.getActiveProfiles(); | ||
List<String> currentProfile = Arrays.stream(activeProfiles).toList(); | ||
return currentProfile.contains(DEV); | ||
} | ||
|
||
public Boolean isLocalAndDevProfile() { | ||
String[] activeProfiles = environment.getActiveProfiles(); | ||
List<String> currentProfile = Arrays.stream(activeProfiles).toList(); | ||
return CollectionUtils.containsAny(LOCAL_AND_DEV, currentProfile); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/clap/server/config/aop/ApiBlockingAspect.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,29 @@ | ||
package clap.server.config.aop; | ||
|
||
import clap.server.common.utils.SpringEnvironmentHelper; | ||
import clap.server.exception.ApplicationException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static clap.server.exception.code.GlobalErrorCode.BLOCKED_API; | ||
|
||
@Aspect | ||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class ApiBlockingAspect { | ||
|
||
private final SpringEnvironmentHelper springEnvironmentHelper; | ||
|
||
@Around("@annotation(clap.server.common.annotation.swagger.DevelopOnlyApi)") | ||
public Object checkApiAcceptingCondition(ProceedingJoinPoint joinPoint) throws Throwable { | ||
if (springEnvironmentHelper.isProdProfile()) { | ||
throw new ApplicationException(BLOCKED_API) ; | ||
} | ||
return joinPoint.proceed(); | ||
} | ||
} |