512 lines
15 KiB
JavaScript
512 lines
15 KiB
JavaScript
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 };
|
|
}
|
|
|
|
export function camelCredential(row) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
kind: row.kind,
|
|
username: row.username,
|
|
hasSecret: Boolean(row.secret_cipher),
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelHost(row) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
fqdn: row.fqdn,
|
|
address: row.address,
|
|
osFamily: normalizeOsFamily(row.os_family, 'other'),
|
|
transport: row.transport,
|
|
port: row.port,
|
|
credentialId: row.credential_id,
|
|
credentialName: row.credential_name || null,
|
|
tags: parseJson(row.tags),
|
|
notes: row.notes,
|
|
visibility: row.visibility || 'shared',
|
|
ownerUserId: row.owner_user_id || null,
|
|
groupId: row.group_id || null,
|
|
groupName: row.group_name || null,
|
|
sourceType: row.source_type || 'manual',
|
|
sourceConnectionId: row.source_connection_id || null,
|
|
sourceConnectionName: row.source_connection_name || null,
|
|
sourceRef: row.source_ref || '',
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelVCenterConnection(row) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
baseUrl: row.base_url,
|
|
username: row.credential_username || row.username || '',
|
|
credentialId: row.credential_id || null,
|
|
credentialName: row.credential_name || null,
|
|
hasPassword: Boolean(row.credential_id || row.secret_cipher),
|
|
hasLegacySecret: Boolean(row.secret_cipher && !row.credential_id),
|
|
targetType: row.target_type || 'vcenter',
|
|
apiMode: row.api_mode || 'auto',
|
|
requestTimeoutMs: row.request_timeout_ms || 20000,
|
|
allowUntrustedTls: Boolean(row.allow_untrusted_tls),
|
|
enabled: Boolean(row.enabled),
|
|
lastTestStatus: row.last_test_status || '',
|
|
lastTestMessage: row.last_test_message || '',
|
|
lastTestAt: row.last_test_at || '',
|
|
visibility: row.visibility || 'shared',
|
|
ownerUserId: row.owner_user_id || null,
|
|
groupId: row.group_id || null,
|
|
groupName: row.group_name || null,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelHostGroup(row) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
description: row.description || '',
|
|
mode: row.mode || 'manual',
|
|
matchMode: row.match_mode || 'all',
|
|
rules: parseJson(row.rules, []),
|
|
hostIds: parseJson(row.host_ids, []),
|
|
memberCount: row.member_count || 0,
|
|
visibility: row.visibility || 'shared',
|
|
ownerUserId: row.owner_user_id || null,
|
|
groupId: row.group_id || null,
|
|
groupName: row.group_name || null,
|
|
lastSyncedAt: row.last_synced_at || '',
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelFolder(row) {
|
|
return {
|
|
id: row.id,
|
|
parentId: row.parent_id,
|
|
name: row.name,
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelScript(row) {
|
|
return {
|
|
id: row.id,
|
|
folderId: row.folder_id,
|
|
folderName: row.folder_name || null,
|
|
name: row.name,
|
|
description: row.description,
|
|
content: row.content,
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
version: row.version,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelAssetFolder(row) {
|
|
return {
|
|
id: row.id,
|
|
parentId: row.parent_id,
|
|
name: row.name,
|
|
description: row.description || '',
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
createdBy: row.created_by,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelAsset(row) {
|
|
return {
|
|
id: row.id,
|
|
folderId: row.folder_id,
|
|
folderName: row.folder_name || null,
|
|
name: row.name,
|
|
originalName: row.original_name,
|
|
description: row.description || '',
|
|
kind: row.kind || 'generic',
|
|
mimeType: row.mime_type || 'application/octet-stream',
|
|
sizeBytes: row.size_bytes || 0,
|
|
checksum: row.checksum,
|
|
packagePath: row.package_path || '',
|
|
referenceToken: `{{asset:${row.id}}}`,
|
|
downloadUrl: `/api/assets/${row.id}/download`,
|
|
viewUrl: `/api/assets/${row.id}/view`,
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
createdBy: row.created_by,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelAssetLink(row) {
|
|
return {
|
|
id: row.id,
|
|
assetId: row.asset_id,
|
|
assetName: row.asset_name || null,
|
|
targetType: row.target_type,
|
|
targetId: row.target_id,
|
|
linkRole: row.link_role,
|
|
packagePath: row.package_path || '',
|
|
createdBy: row.created_by,
|
|
createdAt: row.created_at
|
|
};
|
|
}
|
|
|
|
export function camelRunPlan(row) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
description: row.description,
|
|
scriptId: row.script_id,
|
|
scriptName: row.script_name,
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
parallel: Boolean(row.parallel),
|
|
hostCount: row.host_count || 0,
|
|
hostGroupCount: row.host_group_count || 0,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelRunPlanSchedule(row) {
|
|
const occurrences = parseJson(row.preview_json, []);
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
description: row.description || '',
|
|
runplanId: row.runplan_id,
|
|
runplanName: row.runplan_name || null,
|
|
scriptId: row.script_id || null,
|
|
scriptName: row.script_name || null,
|
|
enabled: Boolean(row.enabled),
|
|
scheduleType: row.schedule_type || 'once',
|
|
startAt: row.start_at,
|
|
endAt: row.end_at || '',
|
|
timeOfDay: row.time_of_day || '',
|
|
intervalValue: row.interval_value || 1,
|
|
intervalUnit: row.interval_unit || 'hours',
|
|
daysOfWeek: parseJson(row.days_of_week, []),
|
|
dayOfMonth: row.day_of_month || null,
|
|
monthOfYear: row.month_of_year || null,
|
|
nextRunAt: row.next_run_at || '',
|
|
lastRunAt: row.last_run_at || '',
|
|
lastJobId: row.last_job_id || '',
|
|
visibility: row.visibility || 'personal',
|
|
ownerUserId: row.owner_user_id || null,
|
|
groupId: row.group_id || null,
|
|
groupName: row.group_name || null,
|
|
preview: occurrences,
|
|
createdBy: row.created_by || null,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelRunPlanScheduleRun(row) {
|
|
return {
|
|
id: row.id,
|
|
scheduleId: row.schedule_id,
|
|
runplanId: row.runplan_id,
|
|
runplanName: row.runplan_name || null,
|
|
jobId: row.job_id || '',
|
|
jobStatus: row.job_status || '',
|
|
plannedFor: row.planned_for,
|
|
status: row.status,
|
|
message: row.message || '',
|
|
createdAt: row.created_at
|
|
};
|
|
}
|
|
|
|
export function camelCustomVariable(row, includeValue = false) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
syntax: `$${row.name}`,
|
|
token: `{{${row.name}}}`,
|
|
description: row.description || '',
|
|
category: row.category || 'Custom',
|
|
valueType: row.value_type || 'string',
|
|
value: includeValue ? row.value : undefined,
|
|
hasValue: Boolean(row.secret_cipher),
|
|
sensitive: Boolean(row.sensitive),
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
source: 'custom',
|
|
readOnly: false,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelPsadtProfile(row) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
appVendor: row.app_vendor || '',
|
|
appName: row.app_name || '',
|
|
appVersion: row.app_version || '',
|
|
appArch: row.app_arch || 'x64',
|
|
appLang: row.app_lang || 'EN',
|
|
appRevision: row.app_revision || '01',
|
|
toolkitVersion: row.toolkit_version || 'v4',
|
|
templateVersion: row.template_version || 'v4',
|
|
deploymentType: row.deployment_type || 'Install',
|
|
deployMode: row.deploy_mode || 'Interactive',
|
|
requireAdmin: Boolean(row.require_admin),
|
|
zeroConfig: Boolean(row.zero_config),
|
|
suppressReboot: Boolean(row.suppress_reboot),
|
|
closeProcesses: parseJson(row.close_processes),
|
|
installTasks: parseJson(row.install_tasks),
|
|
uiPlan: parseJson(row.ui_plan, {}),
|
|
configPlan: parseJson(row.config_plan, {}),
|
|
admxPlan: parseJson(row.admx_plan, {}),
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelIntuneDeployment(row) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
profileId: row.profile_id || null,
|
|
profileName: row.profile_name || null,
|
|
scriptId: row.script_id || null,
|
|
scriptName: row.script_name || null,
|
|
applicationId: row.application_id || null,
|
|
sourceFolder: row.source_folder || '',
|
|
intunewinFile: row.intunewin_file || '',
|
|
appType: row.app_type,
|
|
commandStyle: row.command_style || 'v4',
|
|
installBehavior: row.install_behavior || 'system',
|
|
restartBehavior: row.restart_behavior || 'return-code',
|
|
uiMode: row.ui_mode || 'native-v4',
|
|
requirements: parseJson(row.requirements, {}),
|
|
installCommand: row.install_command,
|
|
uninstallCommand: row.uninstall_command,
|
|
detectionType: row.detection_type,
|
|
detectionRule: row.detection_rule || '',
|
|
returnCodes: parseJson(row.return_codes),
|
|
assignments: parseJson(row.assignments),
|
|
relationships: parseJson(row.relationships),
|
|
status: row.status,
|
|
autoPromoteAfterHours: row.auto_promote_after_hours || 0,
|
|
autoPromoteRing: row.auto_promote_ring || '',
|
|
autoPromoteIntent: row.auto_promote_intent || 'required',
|
|
soakStartedAt: row.soak_started_at || '',
|
|
promotedAt: row.promoted_at || '',
|
|
graphAppId: row.graph_app_id || '',
|
|
graphConnectionId: row.graph_connection_id || '',
|
|
notes: row.notes || '',
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelGraphConnection(row) {
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
tenantId: row.tenant_id,
|
|
clientId: row.client_id,
|
|
hasClientSecret: Boolean(row.secret_cipher),
|
|
cloud: row.cloud || 'global',
|
|
graphBaseUrl: row.graph_base_url || 'https://graph.microsoft.com',
|
|
authorityHost: row.authority_host || 'https://login.microsoftonline.com',
|
|
defaultApiVersion: row.default_api_version || 'v1.0',
|
|
enabled: Boolean(row.enabled),
|
|
allowWrite: Boolean(row.allow_write),
|
|
requireApproval: Boolean(row.require_approval),
|
|
publisherIds: parseJson(row.publisher_ids, []),
|
|
approverIds: parseJson(row.approver_ids, []),
|
|
lastTestStatus: row.last_test_status || '',
|
|
lastTestMessage: row.last_test_message || '',
|
|
lastTestAt: row.last_test_at || '',
|
|
visibility: row.visibility,
|
|
ownerUserId: row.owner_user_id,
|
|
groupId: row.group_id,
|
|
groupName: row.group_name || null,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelIntuneDeploymentStatus(row) {
|
|
return {
|
|
id: row.id,
|
|
deploymentId: row.deployment_id,
|
|
connectionId: row.connection_id,
|
|
graphAppId: row.graph_app_id,
|
|
scope: row.scope,
|
|
principalId: row.principal_id || '',
|
|
principalName: row.principal_name || '',
|
|
deviceId: row.device_id || '',
|
|
deviceName: row.device_name || '',
|
|
userId: row.user_id || '',
|
|
userPrincipalName: row.user_principal_name || '',
|
|
installState: row.install_state || 'unknown',
|
|
installStateDetail: row.install_state_detail || '',
|
|
errorCode: row.error_code || '',
|
|
errorDescription: row.error_description || '',
|
|
lastSyncDateTime: row.last_sync_datetime || '',
|
|
raw: parseJson(row.raw_json, {}),
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at
|
|
};
|
|
}
|
|
|
|
export function camelIntuneDeploymentSyncRun(row) {
|
|
return {
|
|
id: row.id,
|
|
deploymentId: row.deployment_id,
|
|
connectionId: row.connection_id,
|
|
graphAppId: row.graph_app_id,
|
|
status: row.status,
|
|
message: row.message || '',
|
|
summary: parseJson(row.summary, {}),
|
|
startedAt: row.started_at,
|
|
endedAt: row.ended_at
|
|
};
|
|
}
|
|
|
|
export function camelJob(row) {
|
|
return {
|
|
id: row.id,
|
|
runplanId: row.runplan_id,
|
|
runplanName: row.runplan_name || null,
|
|
scriptId: row.script_id,
|
|
scriptName: row.script_name || null,
|
|
status: row.status,
|
|
triggeredBy: row.triggered_by,
|
|
startedAt: row.started_at,
|
|
endedAt: row.ended_at,
|
|
createdAt: row.created_at
|
|
};
|
|
}
|
|
|
|
export function camelJobHost(row) {
|
|
return {
|
|
id: row.id,
|
|
jobId: row.job_id,
|
|
hostId: row.host_id,
|
|
hostName: row.host_name,
|
|
hostAddress: row.host_address,
|
|
status: row.status,
|
|
exitCode: row.exit_code,
|
|
startedAt: row.started_at,
|
|
endedAt: row.ended_at
|
|
};
|
|
}
|
|
|
|
export function camelJobLog(row) {
|
|
return {
|
|
id: row.id,
|
|
jobId: row.job_id,
|
|
hostId: row.host_id,
|
|
hostName: row.host_name,
|
|
stream: row.stream,
|
|
line: row.line,
|
|
createdAt: row.created_at
|
|
};
|
|
}
|
|
|
|
export function camelJobOutput(row) {
|
|
const hostSuccessCount = row.host_success_count || 0;
|
|
const hostFailedCount = row.host_failed_count || 0;
|
|
const hostSkippedCount = row.host_skipped_count || 0;
|
|
const hostCanceledCount = row.host_canceled_count || 0;
|
|
const outputStatus = hostSuccessCount > 0
|
|
? 'completed'
|
|
: hostFailedCount > 0
|
|
? 'failed'
|
|
: hostCanceledCount > 0
|
|
? 'canceled'
|
|
: hostSkippedCount > 0
|
|
? 'skipped'
|
|
: row.job_status || row.status || '';
|
|
return {
|
|
id: row.id,
|
|
jobId: row.job_id,
|
|
kind: row.kind,
|
|
name: row.name,
|
|
mimeType: row.mime_type,
|
|
sizeBytes: row.size_bytes || 0,
|
|
checksum: row.checksum,
|
|
metadata: parseJson(row.metadata_json, {}),
|
|
runplanId: row.runplan_id || null,
|
|
runplanName: row.runplan_name || null,
|
|
scriptId: row.script_id || null,
|
|
scriptName: row.script_name || null,
|
|
jobStatus: row.job_status || row.status || '',
|
|
outputStatus,
|
|
hostTotalCount: row.host_total_count || 0,
|
|
hostSuccessCount,
|
|
hostFailedCount,
|
|
hostSkippedCount,
|
|
hostCanceledCount,
|
|
triggeredBy: row.triggered_by || null,
|
|
createdAt: row.created_at,
|
|
updatedAt: row.updated_at,
|
|
downloadUrl: `/api/job-output/${row.id}/download`,
|
|
viewUrl: `/api/job-output/${row.id}/view`
|
|
};
|
|
}
|
|
|
|
export function camelSystemJobAction(row) {
|
|
return {
|
|
id: row.id,
|
|
jobId: row.job_id || null,
|
|
targetType: row.target_type,
|
|
targetId: row.target_id,
|
|
action: row.action,
|
|
status: row.status,
|
|
message: row.message || '',
|
|
actorUserId: row.actor_user_id || null,
|
|
actorName: row.actor_name || null,
|
|
metadata: parseJson(row.metadata_json, {}),
|
|
createdAt: row.created_at
|
|
};
|
|
}
|