chore: move encrypt to connection (#34)

This commit is contained in:
boojack
2023-04-14 14:28:49 +08:00
committed by GitHub
parent f9bd62caa0
commit 70b37211cd
5 changed files with 29 additions and 10 deletions

View File

@ -46,6 +46,7 @@
"@nem035/gpt-3-encoder": "^1.1.7", "@nem035/gpt-3-encoder": "^1.1.7",
"@tailwindcss/typography": "^0.5.9", "@tailwindcss/typography": "^0.5.9",
"@types/lodash-es": "^4.17.7", "@types/lodash-es": "^4.17.7",
"@types/mssql": "^8.1.2",
"@types/node": "^18.11.18", "@types/node": "^18.11.18",
"@types/pg": "^8.6.6", "@types/pg": "^8.6.6",
"@types/react": "^18.0.26", "@types/react": "^18.0.26",

17
pnpm-lock.yaml generated
View File

@ -108,6 +108,9 @@ devDependencies:
'@types/lodash-es': '@types/lodash-es':
specifier: ^4.17.7 specifier: ^4.17.7
version: 4.17.7 version: 4.17.7
'@types/mssql':
specifier: ^8.1.2
version: 8.1.2
'@types/node': '@types/node':
specifier: ^18.11.18 specifier: ^18.11.18
version: 18.15.3 version: 18.15.3
@ -1493,6 +1496,14 @@ packages:
resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==} resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==}
dev: false dev: false
/@types/mssql@8.1.2:
resolution: {integrity: sha512-hoDM+mZUClfXu0J1pyVdbhv2Ve0dl0TdagAE3M5rd1slqoVEEHuNObPD+giwtJgyo99CcS58qbF9ektVKdxSfQ==}
dependencies:
'@types/node': 18.15.3
'@types/tedious': 4.0.9
tarn: 3.0.2
dev: true
/@types/node@18.15.3: /@types/node@18.15.3:
resolution: {integrity: sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==} resolution: {integrity: sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==}
dev: true dev: true
@ -1546,6 +1557,12 @@ packages:
/@types/scheduler@0.16.2: /@types/scheduler@0.16.2:
resolution: {integrity: sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==} resolution: {integrity: sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==}
/@types/tedious@4.0.9:
resolution: {integrity: sha512-ipwFvfy9b2m0gjHsIX0D6NAAwGCKokzf5zJqUZHUGt+7uWVlBIy6n2eyMgiKQ8ChLFVxic/zwQUhjLYNzbHDRA==}
dependencies:
'@types/node': 18.15.3
dev: true
/@types/unist@2.0.6: /@types/unist@2.0.6:
resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==} resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==}

View File

@ -255,7 +255,7 @@ const CreateConnectionModal = (props: Props) => {
<label className="block text-sm font-medium text-gray-700 mb-1">SSL</label> <label className="block text-sm font-medium text-gray-700 mb-1">SSL</label>
<div className="w-full flex flex-row justify-start items-start flex-wrap"> <div className="w-full flex flex-row justify-start items-start flex-wrap">
{SSLTypeOptions.map((option) => ( {SSLTypeOptions.map((option) => (
<label key={option.value} className="w-auto flex flex-row justify-start items-center cursor-pointer mr-3 mb-2"> <label key={option.value} className="w-auto flex flex-row justify-start items-center cursor-pointer mr-3 mb-3">
<input <input
type="radio" type="radio"
className="radio w-4 h-4 mr-1" className="radio w-4 h-4 mr-1"
@ -323,16 +323,16 @@ const CreateConnectionModal = (props: Props) => {
)} )}
{connection.engineType === Engine.MSSQL && ( {connection.engineType === Engine.MSSQL && (
<div className="w-full flex flex-col"> <div className="w-full flex flex-col">
<label className="block text-sm font-medium text-gray-700 mb-1">Encrypt?</label> <label className="block text-sm font-medium text-gray-700 mb-1">Encrypt</label>
<div className="w-full flex flex-row justify-start items-start flex-wrap"> <div className="w-full flex flex-row justify-start items-start flex-wrap">
<label className="flex items-center"> <label className="flex items-center">
<input <input
type="checkbox" type="checkbox"
className="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out" className="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out"
checked={connection.ssl && connection.ssl['encrypt']} checked={connection.encrypt}
onChange={(e) => setPartialConnection({ ssl: { ...connection.ssl, encrypt: e.target.checked } })} onChange={(e) => setPartialConnection({ encrypt: e.target.checked })}
/> />
<span className="ml-2 text-sm">Encrypt connection?</span> <span className="ml-2 text-sm">Encrypt connection</span>
</label> </label>
</div> </div>
</div> </div>

View File

@ -1,18 +1,18 @@
import { ConnectionPool, ConnectionPoolConfig } from "mssql"; import { ConnectionPool } from "mssql";
import { Connection } from "@/types"; import { Connection } from "@/types";
import { Connector } from ".."; import { Connector } from "..";
const systemDatabases = ["master", "tempdb", "model", "msdb"]; const systemDatabases = ["master", "tempdb", "model", "msdb"];
const getMSSQLConnection = async (connection: Connection): Promise<ConnectionPool> => { const getMSSQLConnection = async (connection: Connection): Promise<ConnectionPool> => {
const connectionOptions: ConnectionPoolConfig = { const connectionOptions: any = {
server: connection.host, server: connection.host,
port: parseInt(connection.port), port: parseInt(connection.port),
user: connection.username, user: connection.username,
password: connection.password, password: connection.password,
database: connection.database, database: connection.database,
options: { options: {
encrypt: connection.ssl?.encrypt === true, encrypt: connection.encrypt === true,
}, },
}; };
if (connection.ssl) { if (connection.ssl) {
@ -70,7 +70,7 @@ const getTables = async (connection: Connection, databaseName: string): Promise<
return tableList; return tableList;
}; };
const getTableStructure = async (connection: ConnectionPool, databaseName: string, tableName: string): Promise<string> => { const getTableStructure = async (connection: Connection, databaseName: string, tableName: string): Promise<string> => {
const pool = await getMSSQLConnection(connection); const pool = await getMSSQLConnection(connection);
const request = pool.request(); const request = pool.request();
const { recordset } = await request.query( const { recordset } = await request.query(

View File

@ -10,7 +10,6 @@ export interface SSLOptions {
ca?: string; ca?: string;
cert?: string; cert?: string;
key?: string; key?: string;
encrypt?: boolean;
} }
export interface Connection { export interface Connection {
@ -23,5 +22,7 @@ export interface Connection {
password: string; password: string;
// database is only required for PostgreSQL. // database is only required for PostgreSQL.
database?: string; database?: string;
// encrypt is only required for MSSQL.
encrypt?: boolean;
ssl?: SSLOptions; ssl?: SSLOptions;
} }