This commit is contained in:
Benjamin Toby
2024-11-06 10:37:01 +01:00
parent d2d599dae3
commit c160c550e5
221 changed files with 382 additions and 377 deletions
+6 -2
View File
@@ -78,10 +78,11 @@ const dbHandler = require("../utils/dbHandler");
* @param {string} params.username - Username
* @param {string} params.host - Host
* @param {GrantType[]} params.grants - Grants
* @param {string} params.userId
*
* @returns {Promise<boolean>} success
*/
async function handleGrants({ username, host, grants }) {
async function handleGrants({ username, host, grants, userId }) {
let success = false;
console.log(`Handling Grants for User =>`, username, host);
@@ -140,7 +141,10 @@ async function handleGrants({ username, host, grants }) {
const { database, table, privileges } = grantObject;
const tableText = table == "*" ? "*" : `\`${table}\``;
const databaseText = database == "*" ? "*" : `\`${database}\``;
const databaseText =
database == "*"
? `\`${process.env.DSQL_USER_DB_PREFIX}${userId}_%\``
: `\`${database}\``;
const privilegesText = privileges.includes("ALL")
? "ALL PRIVILEGES"
@@ -139,10 +139,12 @@ async function refreshUsersAndGrants() {
!mariadbUserHostArg &&
!mariadbUserArg
) {
await noDatabaseDbHandler(
const createNewUser = await noDatabaseDbHandler(
`CREATE USER IF NOT EXISTS '${dslUsername}'@'${defaultMariadbUserHost}' IDENTIFIED BY '${dsqlPassword}' REQUIRE SSL`
);
console.log("createNewUser", createNewUser);
console.log(
`User ${user.id}: ${user.first_name} ${user.last_name} SQL credentials successfully updated.`
);
@@ -259,6 +261,7 @@ async function refreshUsersAndGrants() {
grants && typeof grants == "string"
? JSON.parse(grants)
: [],
userId: String(userId),
});
if (!isGrantHandled) {