From b337e5748ff018db1343ed69c23b2cba1ffc60d8 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Fri, 8 Nov 2024 20:15:37 +0100 Subject: [PATCH] Remove SSL directory --- .gitignore | 4 ++++ engine/engine/utils/dbHandler.js | 19 ++----------------- engine/engine/utils/noDatabaseDbHandler.js | 7 ++----- package-shared/utils/backend/grabDbSSL.js | 9 +++++++-- package.json | 4 ++-- ssl/ca-cert.pem | 22 ---------------------- 6 files changed, 17 insertions(+), 48 deletions(-) delete mode 100644 ssl/ca-cert.pem diff --git a/.gitignore b/.gitignore index c228638..0a18bd6 100644 --- a/.gitignore +++ b/.gitignore @@ -143,3 +143,7 @@ test/ # .npmrc /dump +ssl +ssl* +*ssl +/ssl diff --git a/engine/engine/utils/dbHandler.js b/engine/engine/utils/dbHandler.js index 222ecd7..95f387c 100644 --- a/engine/engine/utils/dbHandler.js +++ b/engine/engine/utils/dbHandler.js @@ -21,8 +21,7 @@ const fs = require("fs"); const mysql = require("mysql"); const path = require("path"); - -const SSL_PATH = path.resolve(__dirname, "../../../ssl"); +const grabDbSSL = require("../../../package-shared/utils/backend/grabDbSSL"); const connection = mysql.createConnection({ host: process.env.DSQL_HOST, @@ -34,21 +33,7 @@ const connection = mysql.createConnection({ ? parseInt(process.env.DSQL_PORT) : undefined, timeout: 5000, - ssl: { - ca: fs.readFileSync(`${SSL_PATH}/ca-cert.pem`), - }, - // ssl: { - // ca: (() => { - // try { - // if (process.env.DSQL_SSL_CA_PATH) { - // return fs.readFileSync(process.env.DSQL_SSL_CA_PATH); - // } - // return undefined; - // } catch (error) { - // return undefined; - // } - // })(), - // }, + ssl: grabDbSSL(), }); ////////////////////////////////////////////////////////////////////////////////// diff --git a/engine/engine/utils/noDatabaseDbHandler.js b/engine/engine/utils/noDatabaseDbHandler.js index 833466c..30a9faa 100644 --- a/engine/engine/utils/noDatabaseDbHandler.js +++ b/engine/engine/utils/noDatabaseDbHandler.js @@ -3,8 +3,7 @@ const fs = require("fs"); const mysql = require("mysql"); const path = require("path"); - -const SSL_PATH = path.resolve(__dirname, "../../../ssl"); +const grabDbSSL = require("../../../package-shared/utils/backend/grabDbSSL"); const connection = mysql.createConnection({ host: process.env.DSQL_HOST, @@ -15,9 +14,7 @@ const connection = mysql.createConnection({ ? parseInt(process.env.DSQL_PORT) : undefined, timeout: 5000, - ssl: { - ca: fs.readFileSync(`${SSL_PATH}/ca-cert.pem`), - }, + ssl: grabDbSSL(), }); /** diff --git a/package-shared/utils/backend/grabDbSSL.js b/package-shared/utils/backend/grabDbSSL.js index 9768bd4..1a79911 100644 --- a/package-shared/utils/backend/grabDbSSL.js +++ b/package-shared/utils/backend/grabDbSSL.js @@ -7,12 +7,17 @@ const fs = require("fs"); */ module.exports = function grabDbSSL() { const SSL_DIR = process.env.DSQL_SSL_DIR; - if (!SSL_DIR?.match(/./)) return undefined; + if (!SSL_DIR?.match(/./)) { + console.log( + "No SSL certificate provided. Query will run in normal mode. To add SSL add an env path dir `DSQL_SSL_DIR` with a file named `ca-cert.pem`" + ); + return undefined; + } const caFilePath = `${SSL_DIR}/ca-cert.pem`; + if (!fs.existsSync(caFilePath)) { console.log(`${caFilePath} does not exist`); - return undefined; } diff --git a/package.json b/package.json index 649f185..d50a273 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "2.5.0", + "version": "2.5.1", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": { @@ -9,7 +9,7 @@ }, "scripts": { "compile": "tsc --declaration --allowJs --emitDeclarationOnly --resolveJsonModule index.js", - "compile-tsc": "rm -rf dist && tsc --declaration --allowJs --outDir dist --emitDeclarationOnly --resolveJsonModule index.js && cat ./dist/index.d.ts > ./index.d.ts" + "compile:full": "rm -rf dist && tsc --declaration --allowJs --outDir dist --emitDeclarationOnly --resolveJsonModule index.js && cat ./dist/index.d.ts > ./index.d.ts" }, "repository": { "type": "git", diff --git a/ssl/ca-cert.pem b/ssl/ca-cert.pem deleted file mode 100644 index d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