Skip to content

Commit

Permalink
CLAP-406 CI/CD: DevelopOnlyApi 어노테이션 적용
Browse files Browse the repository at this point in the history
<footer>
- #524
  • Loading branch information
hyoseong-Choi committed Feb 12, 2025
1 parent 7e5e946 commit 4746857
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
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 src/main/java/clap/server/config/aop/ApiBlockingAspect.java
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();
}
}

0 comments on commit 4746857

Please sign in to comment.