fix possible bug when access-manager-api resource name is mismatched with api config
tronnet/workflows: Code Style -- Web Components / style-web (push) Successful in 15s

This commit is contained in:
alu
2026-08-11 23:49:59 +00:00
parent 44b5c2b121
commit 54c1fe846e
+10 -2
View File
@@ -4,6 +4,7 @@ import url from "url";
import * as fs from "fs"; import * as fs from "fs";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import { exit } from "process"; import { exit } from "process";
import { log } from "console";
/** /**
* Check if a user is authorized to access a specified vm, or the cluster in general. * Check if a user is authorized to access a specified vm, or the cluster in general.
@@ -76,7 +77,7 @@ export async function getPoolResources (req, pool) {
// setup the pool resource object with used and avail for each resource and each resource pool // setup the pool resource object with used and avail for each resource and each resource pool
// also add a total counter for each resource (only used for display, not used to check requests) // also add a total counter for each resource (only used for display, not used to check requests)
for (const resourceName of Object.keys(poolConfigResources)) { for (const resourceName of Object.keys(poolConfigResources)) {
if (configResources[resourceName].type === "list") { if (resourceName in configResources && configResources[resourceName].type === "list") {
poolConfigResources[resourceName].total = []; poolConfigResources[resourceName].total = [];
poolConfigResources[resourceName].global.forEach((e) => { poolConfigResources[resourceName].global.forEach((e) => {
e.used = 0; e.used = 0;
@@ -105,7 +106,7 @@ export async function getPoolResources (req, pool) {
}); });
} }
} }
else { else if (resourceName in configResources){ // numeric or storage
const total = { const total = {
max: 0, max: 0,
used: 0, used: 0,
@@ -123,6 +124,13 @@ export async function getPoolResources (req, pool) {
} }
poolConfigResources[resourceName].total = total; poolConfigResources[resourceName].total = total;
} }
else {
// pool's resource config included a resource which was not in the metadata config
// delete it from the config
// remeber that a resource requested with no config limit is default deny
delete poolConfigResources[resourceName]
console.log(`utils: pool had resource key ${resourceName} which is not in the config.json`)
}
} }
const resources = await global.pve.getPoolResources(req.cookies, pool); const resources = await global.pve.getPoolResources(req.cookies, pool);