Skip to content

Commit 4746857

Browse files
committed
CLAP-406 CI/CD: DevelopOnlyApi 어노테이션 적용
<footer> - #524
1 parent 7e5e946 commit 4746857

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package clap.server.common.utils;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.springframework.core.env.Environment;
5+
import org.springframework.stereotype.Component;
6+
import org.springframework.util.CollectionUtils;
7+
8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
@Component
12+
@RequiredArgsConstructor
13+
public class SpringEnvironmentHelper {
14+
15+
private final Environment environment;
16+
17+
private final String PROD = "prod";
18+
private final String DEV = "dev";
19+
private final String LOCAL = "local";
20+
21+
private final List<String> LOCAL_AND_DEV = List.of("local", "dev");
22+
23+
public Boolean isProdProfile() {
24+
String[] activeProfiles = environment.getActiveProfiles();
25+
List<String> currentProfile = Arrays.stream(activeProfiles).toList();
26+
return currentProfile.contains(PROD);
27+
}
28+
29+
public Boolean isLocalProfile() {
30+
String[] activeProfiles = environment.getActiveProfiles();
31+
List<String> currentProfile = Arrays.stream(activeProfiles).toList();
32+
return currentProfile.contains(LOCAL);
33+
}
34+
35+
public Boolean isDevProfile() {
36+
String[] activeProfiles = environment.getActiveProfiles();
37+
List<String> currentProfile = Arrays.stream(activeProfiles).toList();
38+
return currentProfile.contains(DEV);
39+
}
40+
41+
public Boolean isLocalAndDevProfile() {
42+
String[] activeProfiles = environment.getActiveProfiles();
43+
List<String> currentProfile = Arrays.stream(activeProfiles).toList();
44+
return CollectionUtils.containsAny(LOCAL_AND_DEV, currentProfile);
45+
}
46+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package clap.server.config.aop;
2+
3+
import clap.server.common.utils.SpringEnvironmentHelper;
4+
import clap.server.exception.ApplicationException;
5+
import lombok.RequiredArgsConstructor;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.aspectj.lang.ProceedingJoinPoint;
8+
import org.aspectj.lang.annotation.Around;
9+
import org.aspectj.lang.annotation.Aspect;
10+
import org.springframework.stereotype.Component;
11+
12+
import static clap.server.exception.code.GlobalErrorCode.BLOCKED_API;
13+
14+
@Aspect
15+
@Component
16+
@Slf4j
17+
@RequiredArgsConstructor
18+
public class ApiBlockingAspect {
19+
20+
private final SpringEnvironmentHelper springEnvironmentHelper;
21+
22+
@Around("@annotation(clap.server.common.annotation.swagger.DevelopOnlyApi)")
23+
public Object checkApiAcceptingCondition(ProceedingJoinPoint joinPoint) throws Throwable {
24+
if (springEnvironmentHelper.isProdProfile()) {
25+
throw new ApplicationException(BLOCKED_API) ;
26+
}
27+
return joinPoint.proceed();
28+
}
29+
}

0 commit comments

Comments
 (0)