drapcode-utility 2.5.6 → 2.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/utils/rest-client.js +17 -1
- package/build/utils/util.js +36 -8
- package/package.json +1 -1
|
@@ -330,15 +330,31 @@ const makeMySqlCall = async (projectId, data, extDbSetting) => {
|
|
|
330
330
|
values.push(fileData);
|
|
331
331
|
});
|
|
332
332
|
}
|
|
333
|
-
const { mysqlDbHostUrl, mysqlDbUser, mysqlDbPassword, mysqlDbName, mysqlDbPort } = extDbSetting || {};
|
|
333
|
+
const { mysqlDbHostUrl, mysqlDbUser, mysqlDbPassword, mysqlDbName, mysqlDbPort, mysqlDbSslEnabled, mysqlDbSslCa, mysqlDbSslCert, mysqlDbSslKey } = extDbSetting || {};
|
|
334
334
|
const mysqlDBConfig = {
|
|
335
335
|
host: mysqlDbHostUrl,
|
|
336
336
|
user: mysqlDbUser,
|
|
337
337
|
password: mysqlDbPassword,
|
|
338
338
|
database: mysqlDbName,
|
|
339
339
|
port: mysqlDbPort,
|
|
340
|
+
sslEnabled: mysqlDbSslEnabled,
|
|
341
|
+
sslCa: '',
|
|
342
|
+
sslCert: '',
|
|
343
|
+
sslKey: ''
|
|
340
344
|
};
|
|
345
|
+
if (mysqlDbSslEnabled) {
|
|
346
|
+
if (mysqlDbSslCa) {
|
|
347
|
+
mysqlDBConfig.sslCa = mysqlDbSslCa;
|
|
348
|
+
}
|
|
349
|
+
if (mysqlDbSslCert) {
|
|
350
|
+
mysqlDBConfig.sslCert = mysqlDbSslCert;
|
|
351
|
+
}
|
|
352
|
+
if (mysqlDbSslKey) {
|
|
353
|
+
mysqlDBConfig.sslKey = mysqlDbSslKey;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
341
356
|
console.log(`==> Final MySQL projectID: ${projectId} ~ data:>> `, data, " ~ query type :>> ", operation, " ~ finalSql:>> ", finalSql, " ~ values:>> ", values);
|
|
357
|
+
console.log("🚀 ~ makeMySqlCall ~ process.env.MYSQL_SSL_CERT_PATH:", process.env.MYSQL_SSL_CERT_PATH);
|
|
342
358
|
const connection = await (0, util_1.createMySqlConnection)(mysqlDBConfig);
|
|
343
359
|
try {
|
|
344
360
|
const [rows] = await connection.execute(finalSql, values);
|
package/build/utils/util.js
CHANGED
|
@@ -17,6 +17,7 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
17
17
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
18
18
|
const uuid_2 = require("uuid");
|
|
19
19
|
const aws4_1 = require("aws4");
|
|
20
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
21
|
const mysql = require("mysql2/promise");
|
|
21
22
|
exports.nonFindQuery = ["COUNT", "SUM", "AVG", "MIN", "MAX"];
|
|
22
23
|
// Constants
|
|
@@ -1275,14 +1276,41 @@ exports.getAwsSignature = getAwsSignature;
|
|
|
1275
1276
|
*/
|
|
1276
1277
|
const createMySqlConnection = async (config) => {
|
|
1277
1278
|
try {
|
|
1278
|
-
const { host, user, password, database, port } = config || {};
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1279
|
+
const { host, user, password, database, port, sslEnabled, sslCa, sslCert, sslKey } = config || {};
|
|
1280
|
+
console.log("🚀 ~ createMySqlConnection ~ sslEnabled:", sslEnabled);
|
|
1281
|
+
console.log("🚀 ~ createMySqlConnection ~ process.env.MYSQL_SSL_CERT_PATH:", process.env.MYSQL_SSL_CERT_PATH);
|
|
1282
|
+
const sslCertsPath = process.env.MYSQL_SSL_CERT_PATH || './';
|
|
1283
|
+
console.log("🚀 ~ createMySqlConnection ~ sslCertsPath:", sslCertsPath);
|
|
1284
|
+
let connection = null;
|
|
1285
|
+
if (sslEnabled) {
|
|
1286
|
+
const connectionOptions = {
|
|
1287
|
+
host,
|
|
1288
|
+
user,
|
|
1289
|
+
password,
|
|
1290
|
+
database,
|
|
1291
|
+
port,
|
|
1292
|
+
ssl: {}
|
|
1293
|
+
};
|
|
1294
|
+
if (sslCa) {
|
|
1295
|
+
connectionOptions.ssl.ca = fs_1.default.readFileSync(`${sslCertsPath}${sslCa}`);
|
|
1296
|
+
}
|
|
1297
|
+
if (sslCert) {
|
|
1298
|
+
connectionOptions.ssl.cert = fs_1.default.readFileSync(`${sslCertsPath}${sslCert}`);
|
|
1299
|
+
}
|
|
1300
|
+
if (sslKey) {
|
|
1301
|
+
connectionOptions.ssl.key = fs_1.default.readFileSync(`${sslCertsPath}${sslKey}`);
|
|
1302
|
+
}
|
|
1303
|
+
connection = await mysql.createConnection(connectionOptions);
|
|
1304
|
+
}
|
|
1305
|
+
else {
|
|
1306
|
+
connection = await mysql.createConnection({
|
|
1307
|
+
host,
|
|
1308
|
+
user,
|
|
1309
|
+
password,
|
|
1310
|
+
database,
|
|
1311
|
+
port,
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1286
1314
|
const [rows] = await connection.execute("select ?+? as sum", [2, 2]);
|
|
1287
1315
|
console.log("==> MySQL createMySqlConnection ~ Testing connection...", rows);
|
|
1288
1316
|
return connection;
|