Skip to content

Commit 4feb997

Browse files
committed
sync: health check api
1 parent 3711097 commit 4feb997

File tree

2 files changed

+29
-45
lines changed

2 files changed

+29
-45
lines changed

src/main/java/com/catcher/datasource/config/DBConfiguration.java

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
/*
2-
데이터베이스 연결 및 SSH 터널링 설정 파일으로 보임.
3-
*/
4-
51
package com.catcher.datasource.config;
6-
72
import com.catcher.infrastructure.KmsService;
8-
9-
/* for SSH Session */
103
import com.jcraft.jsch.JSch;
114
import com.jcraft.jsch.Session;
12-
13-
/* 생성자 자동 설정 */
145
import lombok.RequiredArgsConstructor;
156
import org.springframework.beans.factory.annotation.Value;
16-
17-
/* DataSource 빌드 (DB 연결 정보 구성 및 DataSource 객체 생성) */
187
import org.springframework.boot.jdbc.DataSourceBuilder;
19-
20-
/* bean(?)을 정의하기 위한 어노테이션 */
218
import org.springframework.context.annotation.Bean;
22-
23-
/* Spring 어플리케이션의 구성 설정 및 구성요소 생성 .. */
249
import org.springframework.context.annotation.Configuration;
2510

26-
/* 데이터베이스 연결 관리 */
2711
import javax.sql.DataSource;
2812

2913
@Configuration
@@ -66,30 +50,30 @@ public class DBConfiguration {
6650
@Value("${ssh.local-port}")
6751
private int localPort;
6852

69-
// @Bean
70-
// public DataSource dataSource() throws Exception {
71-
72-
// JSch jsch = new JSch();
73-
// Session session = jsch.getSession(
74-
// kmsService.decrypt(sshUsername),
75-
// kmsService.decrypt(sshHost),
76-
// sshPort
77-
// );
78-
// session.setPassword(kmsService.decrypt(sshPassword));
79-
// session.setConfig("StrictHostKeyChecking", "no");
80-
// session.connect();
81-
82-
// int assignedPort = session.setPortForwardingL(0,
83-
// kmsService.decrypt(originUrl),
84-
// localPort
85-
// );
86-
87-
// return DataSourceBuilder.create()
88-
// .url(kmsService.decrypt(databaseUrl).replace(Integer.toString(localPort), Integer.toString(assignedPort)))
89-
// .username(kmsService.decrypt(databaseUsername))
90-
// .password(kmsService.decrypt(databasePassword))
91-
// .build();
92-
// }
53+
@Bean
54+
public DataSource dataSource() throws Exception {
55+
56+
JSch jsch = new JSch();
57+
Session session = jsch.getSession(
58+
kmsService.decrypt(sshUsername),
59+
kmsService.decrypt(sshHost),
60+
sshPort
61+
);
62+
session.setPassword(kmsService.decrypt(sshPassword));
63+
session.setConfig("StrictHostKeyChecking", "no");
64+
session.connect();
65+
66+
int assignedPort = session.setPortForwardingL(0,
67+
kmsService.decrypt(originUrl),
68+
localPort
69+
);
70+
71+
return DataSourceBuilder.create()
72+
.url(kmsService.decrypt(databaseUrl).replace(Integer.toString(localPort), Integer.toString(assignedPort)))
73+
.username(kmsService.decrypt(databaseUsername))
74+
.password(kmsService.decrypt(databasePassword))
75+
.build();
76+
}
9377

9478
@Bean
9579
public DataSource dataSource() {

src/main/java/com/catcher/infrastructure/KmsService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class KmsService {
2525
// private static String PROFILE;
2626

2727
public String encrypt(String text) {
28-
// AWSKMS kmsClient = AWSKMSClientBuilder.standard()
29-
// .withCredentials(new ProfileCredentialsProvider(PROFILE))
30-
// .withRegion(Regions.AP_NORTHEAST_2)
31-
// .build();
28+
// AWSKMS kmsClient = AWSKMSClientBuilder.standard()
29+
// .withCredentials(new ProfileCredentialsProvider(PROFILE))
30+
// .withRegion(Regions.AP_NORTHEAST_2)
31+
// .build();
3232
AWSKMS kmsClient = AWSKMSClientBuilder.standard()
3333
.withRegion(Regions.AP_NORTHEAST_2)
3434
.build();
@@ -59,4 +59,4 @@ public String decrypt(String cipherBase64) {
5959
byte[] textBytes = kmsClient.decrypt(request).getPlaintext().array();
6060
return new String(textBytes);
6161
}
62-
}
62+
}

0 commit comments

Comments
 (0)