데이터베이스 틀린 비밀번호 입력시 연결거부처리
This commit is contained in:
@@ -81,6 +81,93 @@ export class ExternalDbConnectionService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DB 타입별로 그룹화된 외부 DB 연결 목록 조회
|
||||
*/
|
||||
static async getConnectionsGroupedByType(
|
||||
filter: ExternalDbConnectionFilter = {}
|
||||
): Promise<ApiResponse<Record<string, ExternalDbConnection[]>>> {
|
||||
try {
|
||||
// 기본 연결 목록 조회
|
||||
const connectionsResult = await this.getConnections(filter);
|
||||
|
||||
if (!connectionsResult.success || !connectionsResult.data) {
|
||||
return {
|
||||
success: false,
|
||||
message: "연결 목록 조회에 실패했습니다."
|
||||
};
|
||||
}
|
||||
|
||||
// DB 타입 카테고리 정보 조회
|
||||
const categories = await prisma.db_type_categories.findMany({
|
||||
where: { is_active: true },
|
||||
orderBy: [
|
||||
{ sort_order: 'asc' },
|
||||
{ display_name: 'asc' }
|
||||
]
|
||||
});
|
||||
|
||||
// DB 타입별로 그룹화
|
||||
const groupedConnections: Record<string, any> = {};
|
||||
|
||||
// 카테고리 정보를 포함한 그룹 초기화
|
||||
categories.forEach((category: any) => {
|
||||
groupedConnections[category.type_code] = {
|
||||
category: {
|
||||
type_code: category.type_code,
|
||||
display_name: category.display_name,
|
||||
icon: category.icon,
|
||||
color: category.color,
|
||||
sort_order: category.sort_order
|
||||
},
|
||||
connections: []
|
||||
};
|
||||
});
|
||||
|
||||
// 연결을 해당 타입 그룹에 배치
|
||||
connectionsResult.data.forEach(connection => {
|
||||
if (groupedConnections[connection.db_type]) {
|
||||
groupedConnections[connection.db_type].connections.push(connection);
|
||||
} else {
|
||||
// 카테고리에 없는 DB 타입인 경우 기타 그룹에 추가
|
||||
if (!groupedConnections['other']) {
|
||||
groupedConnections['other'] = {
|
||||
category: {
|
||||
type_code: 'other',
|
||||
display_name: '기타',
|
||||
icon: 'database',
|
||||
color: '#6B7280',
|
||||
sort_order: 999
|
||||
},
|
||||
connections: []
|
||||
};
|
||||
}
|
||||
groupedConnections['other'].connections.push(connection);
|
||||
}
|
||||
});
|
||||
|
||||
// 연결이 없는 빈 그룹 제거
|
||||
Object.keys(groupedConnections).forEach(key => {
|
||||
if (groupedConnections[key].connections.length === 0) {
|
||||
delete groupedConnections[key];
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: groupedConnections,
|
||||
message: `DB 타입별로 그룹화된 연결 목록을 조회했습니다.`
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("그룹화된 연결 목록 조회 실패:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "그룹화된 연결 목록 조회 중 오류가 발생했습니다.",
|
||||
error: error instanceof Error ? error.message : "알 수 없는 오류"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 외부 DB 연결 조회
|
||||
*/
|
||||
@@ -371,8 +458,10 @@ export class ExternalDbConnectionService {
|
||||
let password: string | null;
|
||||
if (testData?.password) {
|
||||
password = testData.password;
|
||||
console.log(`🔍 [연결테스트] 새로 입력된 비밀번호 사용: ${password.substring(0, 3)}***`);
|
||||
} else {
|
||||
password = await this.getDecryptedPassword(id);
|
||||
console.log(`🔍 [연결테스트] 저장된 비밀번호 사용: ${password ? password.substring(0, 3) + '***' : 'null'}`);
|
||||
}
|
||||
|
||||
if (!password) {
|
||||
@@ -398,9 +487,34 @@ export class ExternalDbConnectionService {
|
||||
ssl: connection.ssl_enabled === "Y" ? { rejectUnauthorized: false } : false
|
||||
};
|
||||
|
||||
// DatabaseConnectorFactory를 통한 연결 테스트
|
||||
const connector = await DatabaseConnectorFactory.createConnector(connection.db_type, config, id);
|
||||
// 연결 테스트용 임시 커넥터 생성 (캐시 사용하지 않음)
|
||||
let connector: any;
|
||||
switch (connection.db_type.toLowerCase()) {
|
||||
case 'postgresql':
|
||||
const { PostgreSQLConnector } = await import('../database/PostgreSQLConnector');
|
||||
connector = new PostgreSQLConnector(config);
|
||||
break;
|
||||
case 'oracle':
|
||||
const { OracleConnector } = await import('../database/OracleConnector');
|
||||
connector = new OracleConnector(config);
|
||||
break;
|
||||
case 'mariadb':
|
||||
case 'mysql':
|
||||
const { MariaDBConnector } = await import('../database/MariaDBConnector');
|
||||
connector = new MariaDBConnector(config);
|
||||
break;
|
||||
case 'mssql':
|
||||
const { MSSQLConnector } = await import('../database/MSSQLConnector');
|
||||
connector = new MSSQLConnector(config);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`지원하지 않는 데이터베이스 타입: ${connection.db_type}`);
|
||||
}
|
||||
|
||||
console.log(`🔍 [연결테스트] 새 커넥터로 DB 연결 시도 - Host: ${config.host}, DB: ${config.database}, User: ${config.user}`);
|
||||
|
||||
const testResult = await connector.testConnection();
|
||||
console.log(`🔍 [연결테스트] 결과 - Success: ${testResult.success}, Message: ${testResult.message}`);
|
||||
|
||||
return {
|
||||
success: testResult.success,
|
||||
|
||||
Reference in New Issue
Block a user