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 (value == null || value == undefined) continue;
if (
targetFieldSchema?.dataType?.match(/int$/i) &&
typeof value == "string" &&
!value?.match(/./)
)
continue;
if (targetFieldSchema?.encrypted) { if (targetFieldSchema?.encrypted) {
value = encrypt(value, encryptionKey, encryptionSalt); value = encrypt(value, encryptionKey, encryptionSalt);
console.log("DSQL: Encrypted value =>", value); console.log("DSQL: Encrypted value =>", value);

View File

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

View File

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

View File

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

View File

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

View File

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

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", "name": "datasquirel",
"version": "2.4.1", "version": "2.4.2",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "index.js", "main": "index.js",
"bin": { "bin": {