change localdb interface
This commit is contained in:
@@ -37,7 +37,7 @@ router.get(`/:node(${nodeRegexP})/pci`, async (req, res) => {
|
||||
if (!auth) {
|
||||
return;
|
||||
}
|
||||
const userNodes = db.getUserConfig(req.cookies.username).nodes;
|
||||
const userNodes = db.getUser(req.cookies.username).nodes;
|
||||
if (!userNodes.includes(params.node)) {
|
||||
res.status(401).send({ auth: false, path: params.node });
|
||||
res.end();
|
||||
@@ -164,7 +164,7 @@ router.post(`${basePath}/create`, async (req, res) => {
|
||||
return;
|
||||
}
|
||||
// get user db config
|
||||
const user = await db.getUserConfig(req.cookies.username);
|
||||
const user = await db.getUser(req.cookies.username);
|
||||
const vmid = Number.parseInt(params.vmid);
|
||||
const vmidMin = user.cluster.vmid.min;
|
||||
const vmidMax = user.cluster.vmid.max;
|
||||
|
@@ -95,7 +95,7 @@ router.post("/:disk/attach", async (req, res) => {
|
||||
}
|
||||
// target disk must be allowed according to source disk's storage options
|
||||
const diskConfig = await getDiskInfo(params.node, config, `unused${params.source}`); // get target disk
|
||||
const resourceConfig = db.getGlobalConfig().resources;
|
||||
const resourceConfig = db.getGlobal().resources;
|
||||
if (!resourceConfig[diskConfig.storage].disks.some(diskPrefix => params.disk.startsWith(diskPrefix))) {
|
||||
res.status(500).send({ error: `Requested target ${params.disk} is not in allowed list [${resourceConfig[diskConfig.storage].disks}].` });
|
||||
res.end();
|
||||
@@ -337,7 +337,7 @@ router.post("/:disk/create", async (req, res) => {
|
||||
return;
|
||||
}
|
||||
// target disk must be allowed according to storage options
|
||||
const resourceConfig = db.getGlobalConfig().resources;
|
||||
const resourceConfig = db.getGlobal().resources;
|
||||
if (!resourceConfig[params.storage].disks.some(diskPrefix => params.disk.startsWith(diskPrefix))) {
|
||||
res.status(500).send({ error: `Requested target ${params.disk} is not in allowed list [${resourceConfig[params.storage].disks}].` });
|
||||
res.end();
|
||||
|
@@ -63,7 +63,7 @@ router.post("/:netid/create", async (req, res) => {
|
||||
return;
|
||||
}
|
||||
// setup action
|
||||
const nc = db.getUserConfig(req.cookies.username).templates.network[params.type];
|
||||
const nc = db.getUser(req.cookies.username).network[params.type];
|
||||
let action = {};
|
||||
if (params.type === "lxc") {
|
||||
action[`net${params.netid}`] = `name=${params.name},bridge=${nc.bridge},ip=${nc.ip},ip6=${nc.ip6},tag=${nc.vlan},type=${nc.type},rate=${params.rate}`;
|
||||
|
@@ -126,7 +126,7 @@ router.post("/:hostpci/modify", async (req, res) => {
|
||||
action[`hostpci${params.hostpci}`] = `${params.device},pcie=${params.pcie}`;
|
||||
action = JSON.stringify(action);
|
||||
// commit action
|
||||
const rootauth = await requestPVE("/access/ticket", "POST", null, JSON.stringify(db.getGlobalConfig().application.pveroot));
|
||||
const rootauth = await requestPVE("/access/ticket", "POST", null, JSON.stringify(db.getGlobal().application.pveroot));
|
||||
if (!(rootauth.status === 200)) {
|
||||
res.status(rootauth.status).send({ auth: false, error: "API could not authenticate as root user." });
|
||||
res.end();
|
||||
@@ -206,7 +206,7 @@ router.post("/create", async (req, res) => {
|
||||
action[`hostpci${hostpci}`] = `${params.device},pcie=${params.pcie}`;
|
||||
action = JSON.stringify(action);
|
||||
// commit action
|
||||
const rootauth = await requestPVE("/access/ticket", "POST", null, JSON.stringify(db.getGlobalConfig().application.pveroot));
|
||||
const rootauth = await requestPVE("/access/ticket", "POST", null, JSON.stringify(db.getGlobal().application.pveroot));
|
||||
if (!(rootauth.status === 200)) {
|
||||
res.status(rootauth.status).send({ auth: false, error: "API could not authenticate as root user." });
|
||||
res.end();
|
||||
@@ -263,7 +263,7 @@ router.delete("/:hostpci/delete", async (req, res) => {
|
||||
// setup action
|
||||
const action = JSON.stringify({ delete: `hostpci${params.hostpci}` });
|
||||
// commit action, need to use root user here because proxmox api only allows root to modify hostpci for whatever reason
|
||||
const rootauth = await requestPVE("/access/ticket", "POST", null, JSON.stringify(db.getGlobalConfig().application.pveroot));
|
||||
const rootauth = await requestPVE("/access/ticket", "POST", null, JSON.stringify(db.getGlobal().application.pveroot));
|
||||
if (!(rootauth.status === 200)) {
|
||||
res.status(rootauth.status).send({ auth: false, error: "API could not authenticate as root user." });
|
||||
res.end();
|
||||
|
@@ -20,7 +20,7 @@ router.get("/config/:key", async (req, res) => {
|
||||
}
|
||||
const allowKeys = ["resources"];
|
||||
if (allowKeys.includes(params.key)) {
|
||||
const config = db.getGlobalConfig();
|
||||
const config = db.getGlobal();
|
||||
res.status(200).send(config[params.key]);
|
||||
}
|
||||
else {
|
||||
|
@@ -24,8 +24,8 @@ let prevState = {};
|
||||
// target ms value
|
||||
let targetMSTime = null;
|
||||
|
||||
const schemes = db.getGlobalConfig().clientsync.schemes;
|
||||
const resourceTypes = db.getGlobalConfig().clientsync.resourcetypes;
|
||||
const schemes = db.getGlobal().clientsync.schemes;
|
||||
const resourceTypes = db.getGlobal().clientsync.resourcetypes;
|
||||
/**
|
||||
* GET - get list of supported synchronization schemes
|
||||
* responses:
|
||||
@@ -164,7 +164,7 @@ if (schemes.interrupt.enabled) {
|
||||
}
|
||||
else {
|
||||
wsServer.handleUpgrade(req, socket, head, (socket) => {
|
||||
const pool = db.getUserConfig(cookies.username).cluster.pool;
|
||||
const pool = db.getUser(cookies.username).cluster.pool;
|
||||
wsServer.emit("connection", socket, cookies.username, pool);
|
||||
});
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ router.get("/config/:key", async (req, res) => {
|
||||
}
|
||||
const allowKeys = ["resources", "cluster", "nodes"];
|
||||
if (allowKeys.includes(params.key)) {
|
||||
const config = db.getUserConfig(req.cookies.username);
|
||||
const config = db.getUser(req.cookies.username);
|
||||
res.status(200).send(config[params.key]);
|
||||
}
|
||||
else {
|
||||
@@ -64,7 +64,7 @@ router.get("/iso", async (req, res) => {
|
||||
return;
|
||||
}
|
||||
// get user iso config
|
||||
const userIsoConfig = db.getGlobalConfig().useriso;
|
||||
const userIsoConfig = db.getGlobal().useriso;
|
||||
// get all isos
|
||||
const isos = (await requestPVE(`/nodes/${userIsoConfig.node}/storage/${userIsoConfig.storage}/content?content=iso`, "GET", { token: pveAPIToken })).data.data;
|
||||
const userIsos = [];
|
||||
|
Reference in New Issue
Block a user