Updates
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
import { DSQL_DATASQUIREL_MARIADB_USERS } from "../../../types/dsql";
|
||||
import { UserType } from "../../../types";
|
||||
type Params = {
|
||||
user: UserType;
|
||||
existingRecord?: DSQL_DATASQUIREL_MARIADB_USERS | null;
|
||||
updatedRecord: DSQL_DATASQUIREL_MARIADB_USERS;
|
||||
};
|
||||
type Return = {
|
||||
msg?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
export default function handleMariadbUserCreation({ user, existingRecord, updatedRecord, }: Params): Promise<Return>;
|
||||
type CreateNewUserParams = {
|
||||
username?: string;
|
||||
host?: string;
|
||||
password?: string;
|
||||
};
|
||||
export declare function createNewSQLUser({ host, password, username, }: CreateNewUserParams): Promise<object | any[] | null>;
|
||||
export {};
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import dbHandler from "../../backend/dbHandler";
|
||||
import normalizeText from "../../../utils/normalize-text";
|
||||
import decrypt from "../../dsql/decrypt";
|
||||
export default async function handleMariadbUserCreation({ user, existingRecord, updatedRecord, }) {
|
||||
const parsedPassword = decrypt({
|
||||
encryptedString: (updatedRecord === null || updatedRecord === void 0 ? void 0 : updatedRecord.password) || "",
|
||||
});
|
||||
if ((existingRecord === null || existingRecord === void 0 ? void 0 : existingRecord.id) && (updatedRecord === null || updatedRecord === void 0 ? void 0 : updatedRecord.id)) {
|
||||
if (existingRecord.username !== updatedRecord.username ||
|
||||
existingRecord.host !== updatedRecord.host) {
|
||||
const renameSQLUser = await dbHandler({
|
||||
query: normalizeText(`
|
||||
RENAME USER '${existingRecord.username}'@'${existingRecord.host}' \
|
||||
TO '${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`),
|
||||
});
|
||||
if (!renameSQLUser) {
|
||||
await createNewSQLUser({
|
||||
host: updatedRecord.host,
|
||||
password: parsedPassword,
|
||||
username: updatedRecord.username,
|
||||
});
|
||||
}
|
||||
}
|
||||
const updateSQLUser = await dbHandler({
|
||||
query: normalizeText(`
|
||||
ALTER USER '${updatedRecord.username}'@'${updatedRecord.host}' \
|
||||
IDENTIFIED BY '${parsedPassword}'
|
||||
`),
|
||||
});
|
||||
if (!updateSQLUser) {
|
||||
await createNewSQLUser({
|
||||
host: updatedRecord.host,
|
||||
password: parsedPassword,
|
||||
username: updatedRecord.username,
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (!(existingRecord === null || existingRecord === void 0 ? void 0 : existingRecord.id) && (updatedRecord === null || updatedRecord === void 0 ? void 0 : updatedRecord.id)) {
|
||||
await createNewSQLUser({
|
||||
host: updatedRecord.host,
|
||||
password: parsedPassword,
|
||||
username: updatedRecord.username,
|
||||
});
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
export async function createNewSQLUser({ host, password, username, }) {
|
||||
return await dbHandler({
|
||||
query: `CREATE USER IF NOT EXISTS '${username}'@'${host}' IDENTIFIED BY '${password}'`,
|
||||
});
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { DSQL_DATASQUIREL_MARIADB_USERS } from "../../../types/dsql";
|
||||
import { UserType } from "../../../types";
|
||||
type Params = {
|
||||
user: UserType;
|
||||
updatedRecord: DSQL_DATASQUIREL_MARIADB_USERS;
|
||||
};
|
||||
type Return = {
|
||||
msg?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
export default function handleMariadbUserGrantsForDatabasesCleanUpRecords({ user, updatedRecord, }: Params): Promise<Return>;
|
||||
export {};
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import dsqlCrud from "../../../utils/data-fetching/crud";
|
||||
export default async function handleMariadbUserGrantsForDatabasesCleanUpRecords({ user, updatedRecord, }) {
|
||||
/**
|
||||
* # Clean up Records
|
||||
*/
|
||||
await dsqlCrud({
|
||||
action: "delete",
|
||||
table: "mariadb_user_databases",
|
||||
deleteData: {
|
||||
user_id: user.id,
|
||||
mariadb_user_id: updatedRecord.id,
|
||||
},
|
||||
});
|
||||
await dsqlCrud({
|
||||
action: "delete",
|
||||
table: "mariadb_user_privileges",
|
||||
deleteData: {
|
||||
user_id: user.id,
|
||||
mariadb_user_id: updatedRecord.id,
|
||||
},
|
||||
});
|
||||
await dsqlCrud({
|
||||
action: "delete",
|
||||
table: "mariadb_user_tables",
|
||||
deleteData: {
|
||||
user_id: user.id,
|
||||
mariadb_user_id: updatedRecord.id,
|
||||
},
|
||||
});
|
||||
return { success: true };
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { DSQL_DATASQUIREL_MARIADB_USERS } from "../../../types/dsql";
|
||||
import { DatabaseScopedAccessObject, UserType } from "../../../types";
|
||||
type Params = {
|
||||
currentAccessedDatabase: DatabaseScopedAccessObject;
|
||||
user: UserType;
|
||||
updatedRecord: DSQL_DATASQUIREL_MARIADB_USERS;
|
||||
};
|
||||
type Return = {
|
||||
msg?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
export default function handleMariadbUserGrantsForDatabasesRecreateGrants({ currentAccessedDatabase, user, updatedRecord, }: Params): Promise<Return>;
|
||||
export {};
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
import { UserSQLPermissions, } from "../../../types";
|
||||
import grabDbFullName from "../../../utils/grab-db-full-name";
|
||||
import dbHandler from "../../backend/dbHandler";
|
||||
import normalizeText from "../../../utils/normalize-text";
|
||||
export default async function handleMariadbUserGrantsForDatabasesRecreateGrants({ currentAccessedDatabase, user, updatedRecord, }) {
|
||||
const { accessedDatabase, dbSlug, allGrants, allTables, grants, tables } = currentAccessedDatabase;
|
||||
const dbFullName = grabDbFullName({
|
||||
user,
|
||||
dbName: dbSlug,
|
||||
});
|
||||
if (allGrants && allTables) {
|
||||
const grantAllPrivileges = await dbHandler({
|
||||
query: normalizeText(`
|
||||
GRANT ALL PRIVILEGES ON \`${dbFullName}\`.* TO \
|
||||
'${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`),
|
||||
});
|
||||
return { success: true };
|
||||
}
|
||||
if (allGrants && (tables === null || tables === void 0 ? void 0 : tables[0])) {
|
||||
for (let t = 0; t < tables.length; t++) {
|
||||
const table = tables[t];
|
||||
// queries.push(
|
||||
// normalizeText(`
|
||||
// GRANT ALL PRIVILEGES ON \`${dbFullName}\`.\`${table.tableSlug}\` \
|
||||
// TO '${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
// `)
|
||||
// );
|
||||
const grantAllPrivilegesToTables = await dbHandler({
|
||||
query: normalizeText(`
|
||||
GRANT ALL PRIVILEGES ON \`${dbFullName}\`.\`${table.tableSlug}\` \
|
||||
TO '${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`),
|
||||
});
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
if (grants === null || grants === void 0 ? void 0 : grants[0]) {
|
||||
const isGrantsInalid = grants.find((g) => !UserSQLPermissions.includes(g));
|
||||
if (isGrantsInalid) {
|
||||
return { msg: `grants is/are invalid!` };
|
||||
}
|
||||
if (tables === null || tables === void 0 ? void 0 : tables[0]) {
|
||||
for (let t = 0; t < tables.length; t++) {
|
||||
const table = tables[t];
|
||||
const grantSpecificPrivilegesToTables = await dbHandler({
|
||||
query: normalizeText(`
|
||||
GRANT ${grants.join(",")} ON \
|
||||
\`${dbFullName}\`.\`${table.tableSlug}\` TO \
|
||||
'${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`),
|
||||
});
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
else {
|
||||
const grantSecificPrivilegesToAllTables = await dbHandler({
|
||||
query: normalizeText(`
|
||||
GRANT ${grants.join(",")} ON \
|
||||
\`${dbFullName}\`.* TO \
|
||||
'${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`),
|
||||
});
|
||||
return { success: true };
|
||||
}
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { DSQL_DATASQUIREL_MARIADB_USERS } from "../../../types/dsql";
|
||||
import { DatabaseScopedAccessObject, UserType } from "../../../types";
|
||||
type Params = {
|
||||
currentAccessedDatabase: DatabaseScopedAccessObject;
|
||||
user: UserType;
|
||||
updatedRecord: DSQL_DATASQUIREL_MARIADB_USERS;
|
||||
};
|
||||
type Return = {
|
||||
msg?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
export default function handleMariadbUserGrantsForDatabasesRecreateRecordsForDatabase({ currentAccessedDatabase, user, updatedRecord, }: Params): Promise<Return>;
|
||||
export {};
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import { UserSQLPermissions, } from "../../../types";
|
||||
import dsqlCrud from "../../../utils/data-fetching/crud";
|
||||
import _n from "../../../utils/numberfy";
|
||||
export default async function handleMariadbUserGrantsForDatabasesRecreateRecordsForDatabase({ currentAccessedDatabase, user, updatedRecord, }) {
|
||||
const { accessedDatabase, dbSlug, allGrants, allTables, grants, tables } = currentAccessedDatabase;
|
||||
const insertSQLDbRecord = await dsqlCrud({
|
||||
action: "insert",
|
||||
table: "mariadb_user_databases",
|
||||
data: {
|
||||
all_privileges: allGrants ? 1 : 0,
|
||||
all_tables: allTables ? 1 : 0,
|
||||
db_id: _n(accessedDatabase.dbId),
|
||||
db_slug: accessedDatabase.dbSlug,
|
||||
db_schema_id: _n(accessedDatabase.dbSchemaId),
|
||||
user_id: user.id,
|
||||
mariadb_user_id: updatedRecord.id,
|
||||
},
|
||||
});
|
||||
if (tables === null || tables === void 0 ? void 0 : tables[0]) {
|
||||
for (let t = 0; t < tables.length; t++) {
|
||||
const table = tables[t];
|
||||
const insertTable = await dsqlCrud({
|
||||
action: "insert",
|
||||
table: "mariadb_user_tables",
|
||||
data: {
|
||||
all_privileges: allGrants ? 1 : 0,
|
||||
all_fields: 1,
|
||||
user_id: user.id,
|
||||
mariadb_user_id: updatedRecord.id,
|
||||
table_slug: table.tableSlug,
|
||||
db_id: _n(table.dbId),
|
||||
db_slug: table.dbSlug,
|
||||
db_schema_id: _n(table.dbSchemaId),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
if (grants === null || grants === void 0 ? void 0 : grants[0]) {
|
||||
const isGrantsInalid = grants.find((g) => !UserSQLPermissions.includes(g));
|
||||
if (isGrantsInalid) {
|
||||
return { msg: `grants is/are invalid!` };
|
||||
}
|
||||
for (let t = 0; t < grants.length; t++) {
|
||||
const grant = grants[t];
|
||||
await dsqlCrud({
|
||||
action: "insert",
|
||||
table: "mariadb_user_privileges",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
mariadb_user_id: updatedRecord.id,
|
||||
privilege: grant,
|
||||
db_id: _n(accessedDatabase.dbId),
|
||||
db_slug: accessedDatabase.dbSlug,
|
||||
db_schema_id: _n(accessedDatabase.dbSchemaId),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import { DSQL_DATASQUIREL_MARIADB_USERS } from "../../../types/dsql";
|
||||
import { DatabaseScopedAccessObject, UserType } from "../../../types";
|
||||
type Params = {
|
||||
accessedDatabases: DatabaseScopedAccessObject[];
|
||||
user: UserType;
|
||||
updatedRecord: DSQL_DATASQUIREL_MARIADB_USERS;
|
||||
};
|
||||
type Return = {
|
||||
msg?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
export default function handleMariadbUserGrantsForDatabases({ accessedDatabases, user, updatedRecord, }: Params): Promise<Return>;
|
||||
export {};
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import handleMariadbUserGrantsForDatabasesRecreateRecordsForDatabase from "./handle-mariadb-user-grants-for-databases-recreate-records";
|
||||
import handleMariadbUserGrantsForDatabasesRecreateGrants from "./handle-mariadb-user-grants-for-databases-recreate-grants";
|
||||
export default async function handleMariadbUserGrantsForDatabases({ accessedDatabases, user, updatedRecord, }) {
|
||||
/**
|
||||
* # Recreate Records
|
||||
*/
|
||||
for (let i = 0; i < accessedDatabases.length; i++) {
|
||||
await handleMariadbUserGrantsForDatabasesRecreateRecordsForDatabase({
|
||||
currentAccessedDatabase: accessedDatabases[i],
|
||||
updatedRecord,
|
||||
user,
|
||||
});
|
||||
await handleMariadbUserGrantsForDatabasesRecreateGrants({
|
||||
currentAccessedDatabase: accessedDatabases[i],
|
||||
updatedRecord,
|
||||
user,
|
||||
});
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { AddUpdateMariadbUserAPIReqBody, UserType } from "../../../types";
|
||||
import { DSQL_DATASQUIREL_MARIADB_USERS } from "../../../types/dsql";
|
||||
type Params = AddUpdateMariadbUserAPIReqBody & {
|
||||
user: UserType;
|
||||
updatedRecord: DSQL_DATASQUIREL_MARIADB_USERS;
|
||||
};
|
||||
type Return = {
|
||||
msg?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
export default function handleMariadbUserGrants({ accessedDatabases, grants, isAllDbsAccess, isAllGrants, user, updatedRecord, }: Params): Promise<Return>;
|
||||
export {};
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
import { UserSQLPermissions, } from "../../../types";
|
||||
import dsqlCrud from "../../../utils/data-fetching/crud";
|
||||
import grabDbNames from "../../../utils/grab-db-names";
|
||||
import normalizeText from "../../../utils/normalize-text";
|
||||
import dbHandler from "../../backend/dbHandler";
|
||||
import handleMariadbUserGrantsForDatabases from "./handle-mariadb-user-grants-for-databases";
|
||||
import revokeAllExistingGrants from "./revoke-all-existing-grants";
|
||||
export default async function handleMariadbUserGrants({ accessedDatabases, grants, isAllDbsAccess, isAllGrants, user, updatedRecord, }) {
|
||||
const { userDbPrefix } = grabDbNames({ user });
|
||||
/**
|
||||
* # Revoke All Existing Grants
|
||||
*/
|
||||
await revokeAllExistingGrants({ updatedRecord, user });
|
||||
/**
|
||||
* # Recreate Grants
|
||||
*/
|
||||
if (isAllGrants && isAllDbsAccess) {
|
||||
const grantAllPrivileges = await dbHandler({
|
||||
query: normalizeText(`
|
||||
GRANT ALL PRIVILEGES ON \
|
||||
\`${userDbPrefix.replace(/\_/g, "\\_")}%\`.* TO \
|
||||
'${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`),
|
||||
});
|
||||
return { success: true };
|
||||
}
|
||||
if (isAllDbsAccess && grants) {
|
||||
const isGrantsInalid = grants.find((g) => !UserSQLPermissions.includes(g));
|
||||
if (isGrantsInalid) {
|
||||
return { msg: `grants is/are invalid!` };
|
||||
}
|
||||
const grantQuery = normalizeText(`
|
||||
GRANT ${grants.join(",")} ON \`${userDbPrefix}%\`.* TO \
|
||||
'${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`);
|
||||
const grantSpecificPrivilegesToAllDbs = await dbHandler({
|
||||
query: grantQuery,
|
||||
});
|
||||
for (let t = 0; t < grants.length; t++) {
|
||||
const grant = grants[t];
|
||||
const addGrant = await dsqlCrud({
|
||||
action: "insert",
|
||||
table: "mariadb_user_privileges",
|
||||
data: {
|
||||
user_id: user.id,
|
||||
mariadb_user_id: updatedRecord.id,
|
||||
privilege: grant,
|
||||
},
|
||||
});
|
||||
}
|
||||
return { success: true };
|
||||
}
|
||||
if (accessedDatabases === null || accessedDatabases === void 0 ? void 0 : accessedDatabases[0]) {
|
||||
const res = await handleMariadbUserGrantsForDatabases({
|
||||
accessedDatabases,
|
||||
updatedRecord,
|
||||
user,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { AddUpdateMariadbUserAPIReqBody, UserType } from "../../../types";
|
||||
import { DSQL_DATASQUIREL_MARIADB_USERS } from "../../../types/dsql";
|
||||
type Params = AddUpdateMariadbUserAPIReqBody & {
|
||||
user: UserType;
|
||||
};
|
||||
type Return = {
|
||||
existingRecord?: DSQL_DATASQUIREL_MARIADB_USERS | null;
|
||||
updatedRecord?: DSQL_DATASQUIREL_MARIADB_USERS | null;
|
||||
msg?: string;
|
||||
};
|
||||
export default function handleMariadbUserRecord({ mariadbUser, accessedDatabases, grants, isAllDbsAccess, isAllGrants, user, }: Params): Promise<Return>;
|
||||
export {};
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import grabSQLUserName from "../../../utils/grab-sql-user-name";
|
||||
import addDbEntry from "../../backend/db/addDbEntry";
|
||||
import encrypt from "../../dsql/encrypt";
|
||||
import dbGrabUserResource from "../db/grab-user-resource";
|
||||
export default async function handleMariadbUserRecord({ mariadbUser, accessedDatabases, grants, isAllDbsAccess, isAllGrants, user, }) {
|
||||
var _a, _b, _c;
|
||||
const { name: finalMariadbUserName } = grabSQLUserName({
|
||||
name: mariadbUser.username,
|
||||
user,
|
||||
});
|
||||
const finalPassword = (_a = mariadbUser.password) === null || _a === void 0 ? void 0 : _a.replace(/ /g, "");
|
||||
if (!finalPassword)
|
||||
return { msg: `Couldn't get password` };
|
||||
const encryptedFinalPassword = encrypt({ data: finalPassword });
|
||||
const finalHost = (_b = mariadbUser.host) === null || _b === void 0 ? void 0 : _b.replace(/ /g, "");
|
||||
const newMariadbUser = {
|
||||
password: encryptedFinalPassword || undefined,
|
||||
username: finalMariadbUserName,
|
||||
all_databases: isAllDbsAccess ? 1 : 0,
|
||||
all_grants: isAllGrants ? 1 : 0,
|
||||
host: finalHost,
|
||||
user_id: user.id,
|
||||
};
|
||||
let { single: existingRecord } = await dbGrabUserResource({
|
||||
tableName: "mariadb_users",
|
||||
userId: user.id,
|
||||
query: {
|
||||
query: {
|
||||
id: {
|
||||
value: String(mariadbUser.id || 0),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const record = await addDbEntry({
|
||||
tableName: "mariadb_users",
|
||||
data: newMariadbUser,
|
||||
update: true,
|
||||
duplicateColumnName: "id",
|
||||
duplicateColumnValue: ((existingRecord === null || existingRecord === void 0 ? void 0 : existingRecord.id) || 0).toString(),
|
||||
});
|
||||
let { single: updatedRecord } = await dbGrabUserResource({
|
||||
tableName: "mariadb_users",
|
||||
userId: user.id,
|
||||
query: {
|
||||
query: {
|
||||
id: {
|
||||
value: String((existingRecord === null || existingRecord === void 0 ? void 0 : existingRecord.id) || ((_c = record === null || record === void 0 ? void 0 : record.payload) === null || _c === void 0 ? void 0 : _c.insertId) || 0),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
return { existingRecord, updatedRecord };
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { UserType } from "../../../types";
|
||||
import { DSQL_DATASQUIREL_MARIADB_USERS } from "../../../types/dsql";
|
||||
type Params = {
|
||||
user: UserType;
|
||||
updatedRecord: DSQL_DATASQUIREL_MARIADB_USERS;
|
||||
};
|
||||
type Return = {
|
||||
msg?: string;
|
||||
success?: boolean;
|
||||
};
|
||||
export default function revokeAllExistingGrants({ user, updatedRecord, }: Params): Promise<Return>;
|
||||
export {};
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import grabDbNames from "../../../utils/grab-db-names";
|
||||
import normalizeText from "../../../utils/normalize-text";
|
||||
import dbHandler from "../../backend/dbHandler";
|
||||
import decrypt from "../../dsql/decrypt";
|
||||
import { createNewSQLUser } from "./handle-mariadb-user-creation";
|
||||
export default async function revokeAllExistingGrants({ user, updatedRecord, }) {
|
||||
const { userDbPrefix } = grabDbNames({ user });
|
||||
const parsedPassword = decrypt({
|
||||
encryptedString: (updatedRecord === null || updatedRecord === void 0 ? void 0 : updatedRecord.password) || "",
|
||||
});
|
||||
const revokeAllPrivileges = await dbHandler({
|
||||
query: normalizeText(`
|
||||
REVOKE ALL PRIVILEGES ON *.* FROM '${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`),
|
||||
});
|
||||
if (!revokeAllPrivileges) {
|
||||
await createNewSQLUser({
|
||||
host: updatedRecord.host,
|
||||
password: parsedPassword,
|
||||
username: updatedRecord.username,
|
||||
});
|
||||
}
|
||||
const revokeGrantOption = await dbHandler({
|
||||
query: normalizeText(`
|
||||
REVOKE GRANT OPTION ON *.* FROM '${updatedRecord.username}'@'${updatedRecord.host}'
|
||||
`),
|
||||
});
|
||||
const userGrants = (await dbHandler({
|
||||
query: `SHOW GRANTS FOR '${updatedRecord.username}'@'${updatedRecord.host}'`,
|
||||
}));
|
||||
for (let i = 0; i < userGrants.length; i++) {
|
||||
const grantObject = userGrants[i];
|
||||
const grant = grantObject === null || grantObject === void 0 ? void 0 : grantObject[Object.keys(grantObject)[0]];
|
||||
if (!(grant === null || grant === void 0 ? void 0 : grant.match(/GRANT USAGE .* IDENTIFIED BY PASSWORD/))) {
|
||||
const revokeGrantText = grant
|
||||
.replace(/GRANT/, "REVOKE")
|
||||
.replace(/ TO /, " FROM ");
|
||||
const revokePrivilege = await dbHandler({ query: revokeGrantText });
|
||||
}
|
||||
}
|
||||
const flushPrivileges = await dbHandler({
|
||||
query: `FLUSH PRIVILEGES`,
|
||||
});
|
||||
return { success: true };
|
||||
}
|
||||
Reference in New Issue
Block a user