refs #5433 db ini config parsing fixes
This commit is contained in:
parent
a9d9e208c4
commit
4e5fa85501
26
myt.js
26
myt.js
|
@ -17,7 +17,6 @@ class Myt {
|
||||||
params: {
|
params: {
|
||||||
remote: 'Name of remote to use',
|
remote: 'Name of remote to use',
|
||||||
workspace: 'The base directory of the project',
|
workspace: 'The base directory of the project',
|
||||||
socket: 'Wether to connect to database via socket',
|
|
||||||
debug: 'Wether to enable debug mode',
|
debug: 'Wether to enable debug mode',
|
||||||
version: 'Display the version number and exit',
|
version: 'Display the version number and exit',
|
||||||
help: 'Display this help message'
|
help: 'Display this help message'
|
||||||
|
@ -28,7 +27,6 @@ class Myt {
|
||||||
alias: {
|
alias: {
|
||||||
remote: 'r',
|
remote: 'r',
|
||||||
workspace: 'w',
|
workspace: 'w',
|
||||||
socket: 'k',
|
|
||||||
debug: 'd',
|
debug: 'd',
|
||||||
version: 'v',
|
version: 'v',
|
||||||
help: 'h'
|
help: 'h'
|
||||||
|
@ -205,34 +203,42 @@ class Myt {
|
||||||
|
|
||||||
let dbConfig;
|
let dbConfig;
|
||||||
try {
|
try {
|
||||||
const iniConfig = ini.parse(await fs.readFile(iniPath, 'utf8')).client;
|
const iniData = ini.parse(await fs.readFile(iniPath, 'utf8')).client;
|
||||||
|
const iniConfig = {};
|
||||||
|
for (const key in iniData) {
|
||||||
|
const value = iniData[key];
|
||||||
|
const newKey = key.replace(/-/g, '_');
|
||||||
|
iniConfig[newKey] = value !== undefined ? value : true;
|
||||||
|
}
|
||||||
dbConfig = {
|
dbConfig = {
|
||||||
host: iniConfig.host,
|
host: iniConfig.host,
|
||||||
port: iniConfig.port,
|
port: iniConfig.port,
|
||||||
user: iniConfig.user,
|
user: iniConfig.user,
|
||||||
password: iniConfig.password,
|
password: iniConfig.password,
|
||||||
multipleStatements: true,
|
multipleStatements: true
|
||||||
authPlugins: {
|
};
|
||||||
|
if (iniConfig.enable_cleartext_plugin) {
|
||||||
|
dbConfig.authPlugins = {
|
||||||
mysql_clear_password() {
|
mysql_clear_password() {
|
||||||
return () => iniConfig.password + '\0';
|
return () => iniConfig.password + '\0';
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
if (iniConfig.ssl_ca) {
|
if (iniConfig.ssl_ca) {
|
||||||
dbConfig.ssl = {
|
dbConfig.ssl = {
|
||||||
ca: await fs.readFile(`${opts.mytDir}/${iniConfig.ssl_ca}`),
|
ca: await fs.readFile(`${opts.mytDir}/${iniConfig.ssl_ca}`),
|
||||||
rejectUnauthorized: iniConfig.ssl_verify_server_cert != undefined
|
rejectUnauthorized: iniConfig.ssl_verify_server_cert != undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (iniConfig.socket) {
|
||||||
|
dbConfig.socketPath = iniConfig.socket;
|
||||||
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
const newErr = Error(`Cannot process the ini file, check that the syntax is correct: ${iniPath}`);
|
const newErr = Error(`Cannot process the ini file, check that the syntax is correct: ${iniPath}`);
|
||||||
newErr.stack += `\nCaused by: ${err.stack}`;
|
newErr.stack += `\nCaused by: ${err.stack}`;
|
||||||
throw newErr;
|
throw newErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.socket)
|
|
||||||
dbConfig.socketPath = '/var/run/mysqld/mysqld.sock';
|
|
||||||
|
|
||||||
Object.assign(opts, {
|
Object.assign(opts, {
|
||||||
iniFile,
|
iniFile,
|
||||||
dbConfig
|
dbConfig
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@verdnatura/myt",
|
"name": "@verdnatura/myt",
|
||||||
"version": "1.5.15",
|
"version": "1.5.16",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@verdnatura/myt",
|
"name": "@verdnatura/myt",
|
||||||
"version": "1.5.15",
|
"version": "1.5.16",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sqltools/formatter": "^1.2.5",
|
"@sqltools/formatter": "^1.2.5",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@verdnatura/myt",
|
"name": "@verdnatura/myt",
|
||||||
"version": "1.5.15",
|
"version": "1.5.16",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "MySQL version control",
|
"description": "MySQL version control",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
Loading…
Reference in New Issue