Initial
This commit is contained in:
@@ -82,7 +82,7 @@ export async function previewVCenterImport(req, res) {
|
||||
if (!parsed.success) return res.status(400).json({ error: 'Invalid vCenter preview payload' });
|
||||
try {
|
||||
const connection = parsed.data.connectionId ? getVCenterConnection(parsed.data.connectionId, req.user.id, true) : null;
|
||||
if (parsed.data.connectionId && !connection) return res.status(404).json({ error: 'vCenter connection not found' });
|
||||
if (parsed.data.connectionId && !connection) return res.status(404).json({ error: 'VMware connection not found' });
|
||||
res.json(await previewVCenterHosts({ ...parsed.data, connection }));
|
||||
} catch (err) {
|
||||
res.status(err.statusCode || 502).json({ error: err.message, trace: err.trace || [] });
|
||||
@@ -94,7 +94,7 @@ export async function importVCenterHosts(req, res) {
|
||||
if (!parsed.success) return res.status(400).json({ error: 'Invalid vCenter import payload' });
|
||||
try {
|
||||
const connection = parsed.data.connectionId ? getVCenterConnection(parsed.data.connectionId, req.user.id, true) : null;
|
||||
if (parsed.data.connectionId && !connection) return res.status(404).json({ error: 'vCenter connection not found' });
|
||||
if (parsed.data.connectionId && !connection) return res.status(404).json({ error: 'VMware connection not found' });
|
||||
const preview = await previewVCenterHosts({ ...parsed.data, connection });
|
||||
const selected = new Set(parsed.data.vmIds || []);
|
||||
const candidates = selected.size
|
||||
@@ -125,16 +125,16 @@ export function listVCenterConnectionRecords(req, res) {
|
||||
|
||||
export function createVCenterConnectionRecord(req, res) {
|
||||
const parsed = vcenterConnectionSchema.safeParse(req.body);
|
||||
if (!parsed.success) return res.status(400).json({ error: 'Invalid vCenter connection payload' });
|
||||
if (!parsed.data.password) return res.status(400).json({ error: 'A vCenter password is required when creating a connection' });
|
||||
if (!parsed.success) return res.status(400).json({ error: 'Invalid VMware connection payload' });
|
||||
if (!parsed.data.password) return res.status(400).json({ error: 'A VMware password is required when creating a connection' });
|
||||
res.status(201).json(createVCenterConnection(parsed.data, req.user.id));
|
||||
}
|
||||
|
||||
export function updateVCenterConnectionRecord(req, res) {
|
||||
const parsed = vcenterConnectionSchema.safeParse(req.body);
|
||||
if (!parsed.success) return res.status(400).json({ error: 'Invalid vCenter connection payload' });
|
||||
if (!parsed.success) return res.status(400).json({ error: 'Invalid VMware connection payload' });
|
||||
const connection = updateVCenterConnection(req.params.connectionId, parsed.data, req.user.id);
|
||||
if (!connection) return res.status(404).json({ error: 'vCenter connection not found' });
|
||||
if (!connection) return res.status(404).json({ error: 'VMware connection not found' });
|
||||
res.json(connection);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ export function deleteVCenterConnectionRecord(req, res) {
|
||||
|
||||
export async function testVCenterConnectionRecord(req, res) {
|
||||
const connection = getVCenterConnection(req.params.connectionId, req.user.id, true);
|
||||
if (!connection) return res.status(404).json({ error: 'vCenter connection not found' });
|
||||
if (!connection) return res.status(404).json({ error: 'VMware connection not found' });
|
||||
try {
|
||||
const result = await testVCenterConnection(connection);
|
||||
recordVCenterConnectionTest(req.params.connectionId, 'success', result.message);
|
||||
|
||||
Reference in New Issue
Block a user