Add encrypt option to MS SQL questions (#6746)

This commit is contained in:
Rijk van Zanten
2021-07-14 00:02:00 +02:00
committed by GitHub
parent 5abfd96a99
commit ea19390f11
2 changed files with 27 additions and 19 deletions

View File

@@ -50,6 +50,13 @@ const password = (): Record<string, string> => ({
mask: '*',
});
const encrypt = (): Record<string, string | boolean> => ({
type: 'confirm',
name: 'options__encrypt',
message: 'Encrypt Connection:',
default: false,
});
const ssl = (): Record<string, string | boolean> => ({
type: 'confirm',
name: 'ssl',
@@ -62,5 +69,5 @@ export const databaseQuestions = {
mysql: [host, port, database, user, password],
pg: [host, port, database, user, password, ssl],
oracledb: [host, port, database, user, password],
mssql: [host, port, database, user, password],
mssql: [host, port, database, user, password, encrypt],
};

View File

@@ -9,6 +9,7 @@ export type Credentials = {
user?: string;
password?: string;
ssl?: boolean;
options__encrypt?: boolean;
};
export default function createDBConnection(
client: 'sqlite3' | 'mysql' | 'pg' | 'oracledb' | 'mssql',
@@ -23,26 +24,26 @@ export default function createDBConnection(
filename: filename as string,
};
} else {
if (client !== 'pg') {
const { host, port, database, user, password } = credentials as Credentials;
const { host, port, database, user, password } = credentials as Credentials;
connection = {
host: host,
port: Number(port),
database: database,
user: user,
password: password,
};
} else {
const { host, port, database, user, password, ssl } = credentials as Credentials;
connection = {
host: host,
port: Number(port),
database: database,
user: user,
password: password,
};
connection = {
host: host,
port: Number(port),
database: database,
user: user,
password: password,
ssl: ssl,
if (client === 'pg') {
const { ssl } = credentials as Credentials;
connection['ssl'] = ssl;
}
if (client === 'mssql') {
const { options__encrypt } = credentials as Credentials;
(connection as Knex.MsSqlConnectionConfig)['options'] = {
encrypt: options__encrypt,
};
}
}