Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/self-depoly.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Docker CI/CD - Deploy

on:
push:
branches: [ develop ]
workflow_dispatch:
branches:
- develop
jobs:
deploy:
runs-on: self-hosted
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/life/mosu/mosuserver/MosuServerApplication.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package life.mosu.mosuserver;

import life.mosu.mosuserver.global.util.ProfileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MosuServerApplication {
@Slf4j
public class MosuServerApplication implements CommandLineRunner {

public static void main(String[] args) {
SpringApplication.run(MosuServerApplication.class, args);
}

@Override
public void run(String... args) throws Exception {
log.info("Active Profiles: {}", (Object) ProfileUtil.getActiveProfilesStatic());
log.info("profile : {}", ProfileUtil.isProfileActiveStatic("prod"));
log.info("profile : {}", ProfileUtil.isProfileActiveStatic("test"));
Comment on lines +19 to +21
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

안녕하세요. 애플리케이션 시작 시 활성 프로필을 확인하기 위한 로그를 추가하신 것으로 보입니다. 이 로그는 개발 및 디버깅 과정에서는 유용하지만, 프로덕션 환경에서는 불필요한 정보가 될 수 있습니다. log.debug 레벨로 변경하여 개발 환경에서만 확인하고 프로덕션 로그에서는 제외하는 것을 권장합니다.

Suggested change
log.info("Active Profiles: {}", (Object) ProfileUtil.getActiveProfilesStatic());
log.info("profile : {}", ProfileUtil.isProfileActiveStatic("prod"));
log.info("profile : {}", ProfileUtil.isProfileActiveStatic("test"));
log.debug("Active Profiles: {}", (Object) ProfileUtil.getActiveProfilesStatic());
log.debug("profile 'prod' is active: {}", ProfileUtil.isProfileActiveStatic("prod"));
log.debug("profile 'test' is active: {}", ProfileUtil.isProfileActiveStatic("test"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class NotifyService {
retryFor = {CustomRuntimeException.class}
)
public void notify(LunaNotificationEvent event) {
String phone = retrievePhoneNumberByUserId(event.userId()).replaceFirst("^.", "");
String phone = retrievePhoneNumberByUserId(event.userId());
LunaNotificationVariable notifyVariable = notifyVariableFactory.create(event);
NotifySender<LunaNotificationVariable> sender = senderResolver.resolve(event.status());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public static String createLocalCookieString(String name, String value, Long max
*/
public static ResponseCookie createDevelopResponseCookie(String name, String value,
Long maxAge) {
boolean isProd = ProfileUtil.isProfileActiveStatic("prod");

return createBaseResponseCookieBuilder(name, value, maxAge)
.secure(true)
.secure(isProd)
.domain(".mosuedu.com")
.sameSite("Strict")
.build();
Comment on lines +67 to 73
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

안녕하세요. prod 프로필 여부에 따라 쿠키의 secure 속성을 동적으로 설정하도록 변경하신 부분 잘 보았습니다. 하지만 createDevelopCookie 메소드(86라인)에서는 여전히 secure 속성을 true로 하드코딩하고 있어 createDevelopResponseCookie 메소드와 동작이 일치하지 않습니다. 두 메소드의 동작을 일관성 있게 유지하기 위해 createDevelopCookie 메소드도 동일한 로직을 적용하도록 수정하는 것을 고려해 보시는 것이 좋겠습니다. 이 불일치는 예기치 않은 쿠키 관련 문제를 일으킬 수 있습니다.

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/life/mosu/mosuserver/global/util/ProfileUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package life.mosu.mosuserver.global.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
public class ProfileUtil implements ApplicationContextAware {

private static Environment environment;

public static String[] getActiveProfilesStatic() {
return environment.getActiveProfiles();
}

public static boolean isProfileActiveStatic(String profile) {
for (String active : environment.getActiveProfiles()) {
if (active.equals(profile)) {
return true;
}
}
return false;
}
Comment on lines +18 to +25
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

isProfileActiveStatic 메소드의 구현을 Java Stream API를 사용하여 더 간결하게 개선할 수 있습니다. 가독성을 높이고 코드를 더 현대적인 스타일로 유지하는 데 도움이 됩니다.

    public static boolean isProfileActiveStatic(String profile) {
        return java.util.Arrays.stream(environment.getActiveProfiles())
                .anyMatch(profile::equals);
    }


@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
environment = applicationContext.getEnvironment();
}
}
Comment on lines +10 to +31
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

ApplicationContextAwarestatic 필드를 사용하여 Environment에 접근하는 방식은 동작은 하지만, 몇 가지 설계적인 단점이 있습니다.

  • 테스트의 어려움: static 필드에 의존하는 코드는 단위 테스트하기가 더 어렵습니다. Environment를 모의(mock) 객체로 대체하기가 까다롭습니다.
  • 강한 결합도: ProfileUtil이 스프링 컨텍스트에 강하게 결합됩니다.

더 나은 대안으로, ProfileUtil을 일반적인 빈(bean)으로 만들고 Environment를 생성자를 통해 주입받는 것을 고려해볼 수 있습니다. 이 유틸리티를 사용하는 CookieBuilderUtil 같은 클래스도 @UtilityClass 대신 빈으로 만들고 ProfileUtil을 주입받도록 리팩토링하면 전체적인 설계가 더 깔끔해지고 테스트하기 쉬워질 것입니다.

물론 현재 구조에서 @UtilityClass를 유지해야 한다면 지금의 구현이 현실적인 해결책일 수 있습니다. 장기적인 관점에서 리팩토링을 고려해보시면 좋을 것 같습니다.