-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[BE/FEAT] 스웨거 비밀번호 설정
- Loading branch information
Showing
7 changed files
with
140 additions
and
11 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
46 changes: 46 additions & 0 deletions
46
src/main/java/com/gaebaljip/exceed/common/helper/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 com.gaebaljip.exceed.common.helper; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.commons.collections.CollectionUtils; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class SpringEnvironmentHelper { | ||
|
||
private final Environment environment; | ||
|
||
private final String PROD = "prod"; | ||
private final String STAGING = "staging"; | ||
private final String DEV = "dev"; | ||
private final List<String> PROD_AND_STAGING = List.of("staging", "prod"); | ||
|
||
public Boolean isProdProfile() { | ||
String[] activeProfiles = environment.getActiveProfiles(); | ||
List<String> currentProfile = Arrays.stream(activeProfiles).toList(); | ||
return currentProfile.contains(PROD); | ||
} | ||
|
||
public Boolean isStagingProfile() { | ||
String[] activeProfiles = environment.getActiveProfiles(); | ||
List<String> currentProfile = Arrays.stream(activeProfiles).toList(); | ||
return currentProfile.contains(STAGING); | ||
} | ||
|
||
public Boolean isDevProfile() { | ||
String[] activeProfiles = environment.getActiveProfiles(); | ||
List<String> currentProfile = Arrays.stream(activeProfiles).toList(); | ||
return currentProfile.contains(DEV); | ||
} | ||
|
||
public Boolean isProdAndStagingProfile() { | ||
String[] activeProfiles = environment.getActiveProfiles(); | ||
List<String> currentProfile = Arrays.stream(activeProfiles).toList(); | ||
return CollectionUtils.containsAny(PROD_AND_STAGING, currentProfile); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/gaebaljip/exceed/common/swagger/SwaggerCannotProdException.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,11 @@ | ||
package com.gaebaljip.exceed.common.swagger; | ||
|
||
import com.gaebaljip.exceed.common.exception.EatCeedException; | ||
|
||
public class SwaggerCannotProdException extends EatCeedException { | ||
public static EatCeedException EXCEPTION = new SwaggerCannotProdException(); | ||
|
||
private SwaggerCannotProdException() { | ||
super(SwaggerError.SWAGGER_CANNOT_PROD); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/gaebaljip/exceed/common/swagger/SwaggerError.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,33 @@ | ||
package com.gaebaljip.exceed.common.swagger; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Objects; | ||
|
||
import com.gaebaljip.exceed.common.Error; | ||
import com.gaebaljip.exceed.common.exception.BaseError; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SwaggerError implements BaseError { | ||
SWAGGER_CANNOT_PROD(400, "SWAGGER_400_1", "운영환경에서는 Swagger를 볼 수 없습니다."), | ||
; | ||
|
||
private final Integer status; | ||
private final String code; | ||
private final String reason; | ||
|
||
@Override | ||
public Error getError() { | ||
return Error.builder().reason(reason).code(code).status(status.toString()).build(); | ||
} | ||
|
||
@Override | ||
public String getExplainError() throws NoSuchFieldException { | ||
Field field = this.getClass().getField(this.name()); | ||
ExplainError annotation = field.getAnnotation(ExplainError.class); | ||
return Objects.nonNull(annotation) ? annotation.value() : this.getReason(); | ||
} | ||
} |