2024-12-06 13:24:26 +00:00
|
|
|
require("dotenv").config({ path: "./../.env" });
|
2025-01-13 08:00:21 +00:00
|
|
|
import grabDbSSL from "../utils/backend/grabDbSSL";
|
|
|
|
import mysql from "serverless-mysql";
|
2024-12-06 13:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* # Main DB Handler Function
|
|
|
|
* @async
|
|
|
|
*
|
|
|
|
* @param {object} params
|
|
|
|
* @param {string} params.query
|
|
|
|
* @param {string[] | object} [params.values]
|
|
|
|
* @param {string} [params.database]
|
|
|
|
*
|
|
|
|
* @returns {Promise<object|null>}
|
|
|
|
*/
|
|
|
|
(async () => {
|
2025-01-13 08:00:21 +00:00
|
|
|
const connection = global.DSQL_DB_CONN;
|
|
|
|
|
2024-12-06 13:24:26 +00:00
|
|
|
try {
|
|
|
|
const result = await connection.query(
|
|
|
|
"SELECT user,host,ssl_type FROM mysql.user"
|
|
|
|
);
|
|
|
|
const parsedResults = JSON.parse(JSON.stringify(result));
|
|
|
|
|
|
|
|
for (let i = 0; i < parsedResults.length; i++) {
|
|
|
|
const user = parsedResults[i];
|
|
|
|
|
|
|
|
if (
|
|
|
|
user.User !== process.env.DSQL_DB_READ_ONLY_USERNAME ||
|
|
|
|
user.User !== process.env.DSQL_DB_FULL_ACCESS_USERNAME ||
|
|
|
|
!user.User?.match(/dsql_user_.*/i)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { User, Host, ssl_type } = user;
|
|
|
|
|
|
|
|
if (ssl_type === "ANY") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const addUserSSL = await connection.query(
|
2024-12-08 19:39:44 +00:00
|
|
|
`ALTER USER '${User}'@'${Host}'`
|
2024-12-06 13:24:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
console.log(`addUserSSL => ${User}@${Host}`, addUserSSL);
|
|
|
|
}
|
2025-01-13 08:00:21 +00:00
|
|
|
} catch (error: any) {
|
2024-12-06 13:24:26 +00:00
|
|
|
console.log("Connection query ERROR =>", error.message);
|
|
|
|
} finally {
|
|
|
|
connection.end();
|
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
})();
|