Minor Updates

This commit is contained in:
Benjamin Toby 2024-11-07 15:28:28 +01:00
parent 880a74dbcb
commit 8fd6c28461
9 changed files with 42 additions and 95 deletions

View File

@ -138,6 +138,13 @@ async function addDbEntry({
if (value == null || value == undefined) continue;
if (
targetFieldSchema?.dataType?.match(/int$/i) &&
typeof value == "string" &&
!value?.match(/./)
)
continue;
if (targetFieldSchema?.encrypted) {
value = encrypt(value, encryptionKey, encryptionSalt);
console.log("DSQL: Encrypted value =>", value);

View File

@ -4,10 +4,7 @@ const fs = require("fs");
const serverError = require("./serverError");
const mysql = require("serverless-mysql");
const path = require("path");
const SSL_DIR =
process.env.DSQL_SSL_DIR || path.resolve(__dirname, "../../../ssl");
const grabDbSSL = require("../../utils/backend/grabDbSSL");
const connection = mysql({
config: {
@ -16,9 +13,7 @@ const connection = mysql({
password: process.env.DSQL_DB_PASSWORD,
database: process.env.DSQL_DB_NAME,
charset: "utf8mb4",
ssl: {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
},
ssl: grabDbSSL(),
},
});

View File

@ -1,11 +1,7 @@
// @ts-check
const fs = require("fs");
const path = require("path");
const mysql = require("serverless-mysql");
const SSL_DIR =
process.env.DSQL_SSL_DIR || path.resolve(__dirname, "../../../../ssl");
const grabDbSSL = require("../grabDbSSL");
const MASTER = mysql({
config: {
@ -17,9 +13,7 @@ const MASTER = mysql({
? Number(process.env.DSQL_DB_PORT)
: undefined,
charset: "utf8mb4",
ssl: {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
},
ssl: grabDbSSL(),
},
});

View File

@ -4,9 +4,7 @@ const fs = require("fs");
const path = require("path");
const mysql = require("serverless-mysql");
const SSL_DIR =
process.env.DSQL_SSL_DIR || path.resolve(__dirname, "../../../../ssl");
const grabDbSSL = require("../grabDbSSL");
let DSQL_USER = mysql({
config: {
@ -14,9 +12,7 @@ let DSQL_USER = mysql({
user: process.env.DSQL_DB_READ_ONLY_USERNAME,
password: process.env.DSQL_DB_READ_ONLY_PASSWORD,
charset: "utf8mb4",
ssl: {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
},
ssl: grabDbSSL(),
},
});
@ -48,9 +44,7 @@ function DSQL_USER_DB_HANDLER({
user: process.env.DSQL_DB_FULL_ACCESS_USERNAME,
password: process.env.DSQL_DB_FULL_ACCESS_PASSWORD,
database: database,
ssl: {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
},
ssl: grabDbSSL(),
},
});
} else {
@ -60,9 +54,7 @@ function DSQL_USER_DB_HANDLER({
user: process.env.DSQL_DB_READ_ONLY_USERNAME,
password: process.env.DSQL_DB_READ_ONLY_PASSWORD,
database: database,
ssl: {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
},
ssl: grabDbSSL(),
},
});
}

View File

@ -1,12 +1,7 @@
// @ts-check
const fs = require("fs");
const path = require("path");
const mysql = require("serverless-mysql");
const SSL_DIR =
process.env.DSQL_SSL_DIR || path.resolve(__dirname, "../../../../ssl");
const grabDbSSL = require("../grabDbSSL");
let NO_DB = mysql({
config: {
@ -14,9 +9,7 @@ let NO_DB = mysql({
user: process.env.DSQL_DB_USERNAME,
password: process.env.DSQL_DB_PASSWORD,
charset: "utf8mb4",
ssl: {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
},
ssl: grabDbSSL(),
},
});

View File

@ -1,12 +1,7 @@
// @ts-check
const fs = require("fs");
const path = require("path");
const mysql = require("serverless-mysql");
const SSL_DIR =
process.env.DSQL_SSL_DIR || path.resolve(__dirname, "../../../../ssl");
const grabDbSSL = require("../grabDbSSL");
let NO_DB = mysql({
config: {
@ -14,9 +9,7 @@ let NO_DB = mysql({
user: process.env.DSQL_DB_USERNAME,
password: process.env.DSQL_DB_PASSWORD,
charset: "utf8mb4",
ssl: {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
},
ssl: grabDbSSL(),
},
});

View File

@ -1,49 +0,0 @@
// @ts-check
const fs = require("fs");
const DSQL_USER_DB_HANDLER = require("./DSQL_USER_DB_HANDLER");
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
process.addListener("exit", async (code) => {
console.log("PROCESS EXITING ...");
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Global function
* ================================================
* @description this sets all require global variables. This only runs once.
*/
module.exports = function globalFunction() {
/**
* Main Db Handler
*/
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Main Db Handler
*/
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* DSQL user read-only DB handler
* @param {object} params
* @param {string} params.paradigm
* @param {string} params.database
* @param {string} params.queryString
* @param {string[]} [params.queryValues]
*/
DSQL_USER_DB_HANDLER;
};

View File

@ -0,0 +1,22 @@
// @ts-check
const fs = require("fs");
/**
* @returns {string | (import("tls").SecureContextOptions & { rejectUnauthorized?: boolean | undefined;}) | undefined}
*/
module.exports = function grabDbSSL() {
const SSL_DIR = process.env.DSQL_SSL_DIR;
if (!SSL_DIR?.match(/./)) return undefined;
const caFilePath = `${SSL_DIR}/ca-cert.pem`;
if (!fs.existsSync(caFilePath)) {
console.log(`${caFilePath} does not exist`);
return undefined;
}
return {
ca: fs.readFileSync(`${SSL_DIR}/ca-cert.pem`),
};
};

View File

@ -1,6 +1,6 @@
{
"name": "datasquirel",
"version": "2.4.1",
"version": "2.4.2",
"description": "Cloud-based SQL data management tool",
"main": "index.js",
"bin": {