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

41 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
exports.id = 1007;
exports.ids = [1007];
exports.modules = {
/***/ 1007:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const fs = __webpack_require__(7147);
const decrypt = __webpack_require__(5425);
/** @type {import("@/package-shared/types").CheckApiCredentialsFn} */ const grabApiCred = ({ key , database , table })=>{
2024-11-06 11:13:31 +00:00
if (!key) return undefined;
2024-11-05 11:12:42 +00:00
try {
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;
if (!allowedKeysPath) throw new Error("process.env.DSQL_API_KEYS_PATH variable not found");
const ApiJSON = decrypt(key);
/** @type {import("@/package-shared/types").ApiKeyObject} */ const ApiObject = JSON.parse(ApiJSON || "");
const isApiKeyValid = fs.existsSync(`${allowedKeysPath}/${ApiObject.sign}`);
if (!isApiKeyValid) return null;
if (!ApiObject.target_database) return ApiObject;
if (!database && ApiObject.target_database) return null;
const isDatabaseAllowed = ApiObject.target_database?.split(",").includes(String(database));
if (isDatabaseAllowed && !ApiObject.target_table) return ApiObject;
if (isDatabaseAllowed && !table && ApiObject.target_table) return null;
const isTableAllowed = ApiObject.target_table?.split(",").includes(String(table));
if (isTableAllowed) return ApiObject;
return null;
2024-11-05 14:18:40 +00:00
} catch (/** @type {any} */ error) {
console.log(`api-cred ERROR: ${error.message}`);
2024-11-05 11:12:42 +00:00
return null;
}
};
module.exports = grabApiCred;
/***/ })
};
;