Major refactoring: Add user id to API routes
This commit is contained in:
@@ -4,8 +4,9 @@ const fs = require("fs");
|
||||
const decrypt = require("./decrypt");
|
||||
|
||||
/** @type {import("../../types").CheckApiCredentialsFn} */
|
||||
const grabApiCred = ({ key, database, table }) => {
|
||||
const grabApiCred = ({ key, database, table, user_id }) => {
|
||||
if (!key) return null;
|
||||
if (!user_id) return null;
|
||||
|
||||
try {
|
||||
const allowedKeysPath = process.env.DSQL_API_KEYS_PATH;
|
||||
@@ -22,6 +23,8 @@ const grabApiCred = ({ key, database, table }) => {
|
||||
`${allowedKeysPath}/${ApiObject.sign}`
|
||||
);
|
||||
|
||||
if (String(ApiObject.user_id) !== String(user_id)) return null;
|
||||
|
||||
if (!isApiKeyValid) return null;
|
||||
if (!ApiObject.target_database) return ApiObject;
|
||||
if (!database && ApiObject.target_database) return null;
|
||||
|
||||
Vendored
+11
@@ -335,6 +335,7 @@ export interface GetSchemaRequestQuery {
|
||||
database?: string;
|
||||
table?: string;
|
||||
field?: string;
|
||||
user_id?: string | number;
|
||||
}
|
||||
|
||||
export interface GetSchemaAPICredentialsParam {
|
||||
@@ -1095,6 +1096,7 @@ export type CheckApiCredentialsFnParam = {
|
||||
key?: string;
|
||||
database?: string;
|
||||
table?: string;
|
||||
user_id?: string | number;
|
||||
};
|
||||
|
||||
export type FetchApiFn = (
|
||||
@@ -1218,3 +1220,12 @@ export type SqlGeneratorFn = (Param0: {
|
||||
values: string[];
|
||||
}
|
||||
| undefined;
|
||||
|
||||
export type ApiConnectBody = {
|
||||
url: string;
|
||||
key: string;
|
||||
database: DSQL_MYSQL_user_databases_Type;
|
||||
dbSchema: DSQL_DatabaseSchemaType;
|
||||
type: "pull" | "push";
|
||||
user_id?: string | number;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ const http = require("http");
|
||||
* @property {string} host
|
||||
* @property {number | string} port
|
||||
* @property {typeof http | typeof https} scheme
|
||||
* @property {string | number} user_id
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -29,6 +30,7 @@ function grabHostNames() {
|
||||
host: remoteHost || localHost || "datasquirel.com",
|
||||
port: remoteHostPort || localHostPort || 443,
|
||||
scheme: scheme?.match(/^http$/i) ? http : https,
|
||||
user_id: String(process.env.DSQL_API_USER_ID || 0),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user