dsql-admin/dsql-app/.local_dist/server/chunks/7192.js

73 lines
3.1 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
exports.id = 7192;
exports.ids = [7192];
exports.modules = {
/***/ 7192:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const generator = __webpack_require__(3785);
const DB_HANDLER = __webpack_require__(2224);
const NO_DB_HANDLER = __webpack_require__(7487);
const encrypt = __webpack_require__(7547);
const addDbEntry = __webpack_require__(5338);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* Add Mariadb User
* ==============================================================================
*
* @description this function adds a Mariadb user to the database server
*
* @param {object} params - parameters object *
* @param {number | string} params.userId - invited user object
*
* @returns {Promise<any>} new user auth object payload
*/ module.exports = async function addMariadbUser({ userId }) {
try {
const defaultMariadbUserHost = process.env.DSQL_DB_HOST || "127.0.0.1";
const username = `dsql_user_${userId}`;
const password = generator.generate({
length: 16,
numbers: true,
symbols: true,
uppercase: true,
exclude: "*#.'`\""
});
const encryptedPassword = encrypt(password);
await NO_DB_HANDLER(`CREATE USER IF NOT EXISTS '${username}'@'127.0.0.1' IDENTIFIED BY '${password}' REQUIRE SSL`);
const updateUser = await DB_HANDLER(`UPDATE users SET mariadb_user = ?, mariadb_host = '127.0.0.1', mariadb_pass = ? WHERE id = ?`, [
username,
encryptedPassword,
userId
]);
const addMariadbUser1 = await addDbEntry({
tableName: "mariadb_users",
data: {
user_id: userId,
username,
host: defaultMariadbUserHost,
password: encryptedPassword,
primary: "1",
grants: '[{"database":"*","table":"*","privileges":["ALL"]}]'
},
dbContext: "Master"
});
console.log("addMariadbUser =>", addMariadbUser1);
console.log(`User ${userId} SQL credentials successfully added.`);
} catch (/** @type {any} */ error) {
console.log(`Error in adding SQL user in 'addMariadbUser' function =>`, error.message);
}
}; ////////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
/***/ })
};
;