Initial
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { db, id, json, now, parseJson, visibleClause } from '../db.js';
|
||||
import { camelHost } from './mappers.js';
|
||||
import { normalizeOsFamily } from '../utils/osFamily.js';
|
||||
|
||||
export function listHosts(userId) {
|
||||
return db.prepare(`
|
||||
@@ -29,7 +30,7 @@ export function createHost(payload, userId) {
|
||||
payload.name,
|
||||
payload.fqdn || '',
|
||||
payload.address,
|
||||
payload.osFamily,
|
||||
normalizeOsFamily(payload.osFamily, 'windows'),
|
||||
payload.transport,
|
||||
payload.port || null,
|
||||
payload.credentialId || null,
|
||||
@@ -80,7 +81,7 @@ export function updateHost(hostId, payload, userId) {
|
||||
payload.name || existing.name,
|
||||
payload.fqdn ?? existing.fqdn,
|
||||
payload.address || existing.address,
|
||||
payload.osFamily || existing.os_family,
|
||||
normalizeOsFamily(payload.osFamily ?? existing.os_family, 'windows'),
|
||||
payload.transport || existing.transport,
|
||||
payload.port ?? existing.port,
|
||||
payload.credentialId ?? existing.credential_id,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { parseJson } from '../db.js';
|
||||
import { normalizeOsFamily } from '../utils/osFamily.js';
|
||||
|
||||
export function camelGroup(row) {
|
||||
return { id: row.id, name: row.name, description: row.description, createdAt: row.created_at };
|
||||
@@ -26,7 +27,7 @@ export function camelHost(row) {
|
||||
name: row.name,
|
||||
fqdn: row.fqdn,
|
||||
address: row.address,
|
||||
osFamily: row.os_family,
|
||||
osFamily: normalizeOsFamily(row.os_family, 'other'),
|
||||
transport: row.transport,
|
||||
port: row.port,
|
||||
credentialId: row.credential_id,
|
||||
@@ -53,6 +54,7 @@ export function camelVCenterConnection(row) {
|
||||
baseUrl: row.base_url,
|
||||
username: row.username,
|
||||
hasPassword: Boolean(row.secret_cipher),
|
||||
targetType: row.target_type || 'vcenter',
|
||||
apiMode: row.api_mode || 'auto',
|
||||
requestTimeoutMs: row.request_timeout_ms || 20000,
|
||||
allowUntrustedTls: Boolean(row.allow_untrusted_tls),
|
||||
|
||||
@@ -9,8 +9,14 @@ function normalizeConnection(body, existing = {}) {
|
||||
...body,
|
||||
password: body.password || ''
|
||||
});
|
||||
const targetType = parsed.targetType || 'vcenter';
|
||||
const apiMode = targetType === 'host'
|
||||
? 'web-services'
|
||||
: (parsed.apiMode === 'web-services' ? 'auto' : parsed.apiMode);
|
||||
return {
|
||||
...parsed,
|
||||
targetType,
|
||||
apiMode,
|
||||
baseUrl: String(parsed.baseUrl || '').trim().replace(/\/+$/, ''),
|
||||
groupId: parsed.visibility === 'group' ? parsed.groupId || null : null
|
||||
};
|
||||
@@ -52,10 +58,10 @@ export function createVCenterConnection(body, userId) {
|
||||
db.prepare(`
|
||||
INSERT INTO vcenter_connections (
|
||||
id, name, base_url, username, secret_cipher, secret_iv, secret_tag,
|
||||
api_mode, request_timeout_ms, allow_untrusted_tls, enabled,
|
||||
target_type, api_mode, request_timeout_ms, allow_untrusted_tls, enabled,
|
||||
visibility, owner_user_id, group_id, created_by, created_at, updated_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(
|
||||
connectionId,
|
||||
payload.name,
|
||||
@@ -64,6 +70,7 @@ export function createVCenterConnection(body, userId) {
|
||||
encrypted.cipher,
|
||||
encrypted.iv,
|
||||
encrypted.tag,
|
||||
payload.targetType,
|
||||
payload.apiMode,
|
||||
payload.requestTimeoutMs,
|
||||
payload.allowUntrustedTls ? 1 : 0,
|
||||
@@ -85,6 +92,7 @@ export function updateVCenterConnection(connectionId, body, userId) {
|
||||
name: existing.name,
|
||||
baseUrl: existing.base_url,
|
||||
username: existing.username,
|
||||
targetType: existing.target_type || 'vcenter',
|
||||
apiMode: existing.api_mode,
|
||||
requestTimeoutMs: existing.request_timeout_ms,
|
||||
allowUntrustedTls: Boolean(existing.allow_untrusted_tls),
|
||||
@@ -100,7 +108,7 @@ export function updateVCenterConnection(connectionId, body, userId) {
|
||||
db.prepare(`
|
||||
UPDATE vcenter_connections
|
||||
SET name = ?, base_url = ?, username = ?, secret_cipher = ?, secret_iv = ?, secret_tag = ?,
|
||||
api_mode = ?, request_timeout_ms = ?, allow_untrusted_tls = ?, enabled = ?,
|
||||
target_type = ?, api_mode = ?, request_timeout_ms = ?, allow_untrusted_tls = ?, enabled = ?,
|
||||
visibility = ?, group_id = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
`).run(
|
||||
@@ -110,6 +118,7 @@ export function updateVCenterConnection(connectionId, body, userId) {
|
||||
encrypted.cipher,
|
||||
encrypted.iv,
|
||||
encrypted.tag,
|
||||
payload.targetType,
|
||||
payload.apiMode,
|
||||
payload.requestTimeoutMs,
|
||||
payload.allowUntrustedTls ? 1 : 0,
|
||||
|
||||
Reference in New Issue
Block a user