From 4e5fa85501a66b4fea76dd789470d766ff1388ba Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 17 Mar 2023 13:13:48 +0100 Subject: [PATCH] refs #5433 db ini config parsing fixes --- myt.js | 26 ++++++++++++++++---------- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/myt.js b/myt.js index 492a4ea..d3c0268 100755 --- a/myt.js +++ b/myt.js @@ -17,7 +17,6 @@ class Myt { params: { remote: 'Name of remote to use', workspace: 'The base directory of the project', - socket: 'Wether to connect to database via socket', debug: 'Wether to enable debug mode', version: 'Display the version number and exit', help: 'Display this help message' @@ -28,7 +27,6 @@ class Myt { alias: { remote: 'r', workspace: 'w', - socket: 'k', debug: 'd', version: 'v', help: 'h' @@ -205,34 +203,42 @@ class Myt { let dbConfig; 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 = { host: iniConfig.host, port: iniConfig.port, user: iniConfig.user, password: iniConfig.password, - multipleStatements: true, - authPlugins: { + multipleStatements: true + }; + if (iniConfig.enable_cleartext_plugin) { + dbConfig.authPlugins = { mysql_clear_password() { return () => iniConfig.password + '\0'; } - } - }; + }; + } if (iniConfig.ssl_ca) { dbConfig.ssl = { ca: await fs.readFile(`${opts.mytDir}/${iniConfig.ssl_ca}`), rejectUnauthorized: iniConfig.ssl_verify_server_cert != undefined } } + if (iniConfig.socket) { + dbConfig.socketPath = iniConfig.socket; + } } catch(err) { const newErr = Error(`Cannot process the ini file, check that the syntax is correct: ${iniPath}`); newErr.stack += `\nCaused by: ${err.stack}`; throw newErr; } - if (opts.socket) - dbConfig.socketPath = '/var/run/mysqld/mysqld.sock'; - Object.assign(opts, { iniFile, dbConfig diff --git a/package-lock.json b/package-lock.json index 4a92fd2..54d46ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@verdnatura/myt", - "version": "1.5.15", + "version": "1.5.16", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@verdnatura/myt", - "version": "1.5.15", + "version": "1.5.16", "license": "GPL-3.0", "dependencies": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 0f4d99d..e3c2f2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@verdnatura/myt", - "version": "1.5.15", + "version": "1.5.16", "author": "Verdnatura Levante SL", "description": "MySQL version control", "license": "GPL-3.0",