Skip to content

Commit

Permalink
merge: secret token을 yml에 등록 / 가져오는 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
juno-junho authored Sep 13, 2023
2 parents 46155f7 + ef56a36 commit 1ccd893
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ dependencies {

// validation
implementation 'org.springframework.boot:spring-boot-starter-validation'
// 테스트 환경 lombok 설정
testImplementation 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
}

tasks.named('test') {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/ray/pominowner/global/config/TokenProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ray.pominowner.global.config;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Getter
@Component
public class TokenProvider {

private final String businessNumberServiceKey;
private final String businessNumberHeaderAuthKey;

public TokenProvider(@Value("${api.token.business.query:''}") String businessNumberServiceKey,
@Value("${api.token.business.header:''}") String businessNumberHeaderAuthKey) {
this.businessNumberServiceKey = businessNumberServiceKey;
this.businessNumberHeaderAuthKey = businessNumberHeaderAuthKey;
}

}
5 changes: 3 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ spring:
config:
activate:
on-profile: prod
import: classpath:sub/application-db.yml
import: sub/application-db.yml, sub/application-token.yml

---
spring:
config:
activate:
on-profile: dev
import: classpath:dev/application-dev.yml
import: dev/application-dev.yml, sub/application-token.yml
2 changes: 1 addition & 1 deletion src/main/resources/sub
Submodule sub updated from 9680f7 to 6f9075
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.ray.pominowner.global.config;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import static org.assertj.core.api.Assertions.assertThat;

@Slf4j
@SpringBootTest
class TokenProviderTest {

@Autowired
private TokenProvider tokenProvider;

@Test
@DisplayName("yml에 설정된 올바른 토큰을 가져올 수 있다.")
void successGetCorrectToken() {
String businessNumberServiceKey = tokenProvider.getBusinessNumberServiceKey();
String businessNumberHeaderAuthKey = tokenProvider.getBusinessNumberHeaderAuthKey();
log.info("businessNumberServiceKey: {}, businessNumberHeaderAuthKey: {}", businessNumberServiceKey, businessNumberHeaderAuthKey);

assertThat(businessNumberServiceKey).isNotBlank();
assertThat(businessNumberHeaderAuthKey).isNotBlank();
}

}

0 comments on commit 1ccd893

Please sign in to comment.