add node restriction

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-04-27 15:39:01 +00:00
parent 116cb14cc5
commit dcef0bb032
2 changed files with 7 additions and 2 deletions

View File

@ -229,6 +229,11 @@ app.post("/api/instance", async (req, res) => {
res.end();
return;
}
if (!user.nodes.includes(req.body.node)) {
res.status(500).send({error: `Requested node ${req.body.node} is not in allowed nodes [${user.nodes}]`});
res.end();
return;
}
let action = {
vmid: req.body.vmid,
cores: req.body.cores,

View File

@ -3,8 +3,8 @@ import { getUserConfig, getResourceConfig } from "./db.js";
export async function getUserData (req, username) {
let resources = await getAllocatedResources(req, username);
let instances = getUserConfig(req.cookies.username).instances;
return {resources: resources, instances: instances};
let user = getUserConfig(req.cookies.username);
return {resources: resources, instances: user.instances, nodes: user.nodes};
}
async function getAllocatedResources (req, username) {