Add Prettier and ESLint tooling (Refs #77)
This commit is contained in:
@@ -1,23 +1,50 @@
|
||||
export const observationKinds = ['host.inspect', 'instance.inspect', 'rcon.status-batch', 'files.read', 'files.list', 'files.stat', 'files.manifest', 'logs.read'];
|
||||
export const observationKinds = [
|
||||
'host.inspect',
|
||||
'instance.inspect',
|
||||
'rcon.status-batch',
|
||||
'files.read',
|
||||
'files.list',
|
||||
'files.stat',
|
||||
'files.manifest',
|
||||
'logs.read'
|
||||
];
|
||||
const commands = ['status', 'getstatus', 'version'];
|
||||
|
||||
export function safeOperationTarget(kind: string, value: string | null): string | null {
|
||||
if (!value || value.length > 1024) return null;
|
||||
const paths = kind === 'files.manifest' ? value.split(', ') : [value];
|
||||
return paths.every(path => path === '.' || !/[\\\x00-\x1f\x7f]/.test(path)
|
||||
&& path.split('/').every(part => part !== '' && part !== '.' && part !== '..')) ? value : null;
|
||||
return paths.every(
|
||||
(path) =>
|
||||
path === '.' ||
|
||||
// eslint-disable-next-line no-control-regex -- Reject control characters in observed paths.
|
||||
(!/[\\\x00-\x1f\x7f]/.test(path) &&
|
||||
path.split('/').every((part) => part !== '' && part !== '.' && part !== '..'))
|
||||
)
|
||||
? value
|
||||
: null;
|
||||
}
|
||||
|
||||
export function successfulObservation(kind: string, payload: Record<string, unknown>, result: unknown): boolean {
|
||||
const routine = observationKinds.includes(kind) || kind === 'rcon.execute' && commands.includes(String(payload.command));
|
||||
const value = result && typeof result === 'object' ? result as Record<string, unknown> : {};
|
||||
export function successfulObservation(
|
||||
kind: string,
|
||||
payload: Record<string, unknown>,
|
||||
result: unknown
|
||||
): boolean {
|
||||
const routine =
|
||||
observationKinds.includes(kind) ||
|
||||
(kind === 'rcon.execute' && commands.includes(String(payload.command)));
|
||||
const value = result && typeof result === 'object' ? (result as Record<string, unknown>) : {};
|
||||
// Older agents set ok=false when any target fails, despite completing the batch.
|
||||
const completedBatch = kind === 'rcon.status-batch' && Array.isArray(value.results);
|
||||
return routine && (completedBatch || value.ok !== false) && value.healthy !== false && (value.error == null || value.error === '');
|
||||
return (
|
||||
routine &&
|
||||
(completedBatch || value.ok !== false) &&
|
||||
value.healthy !== false &&
|
||||
(value.error == null || value.error === '')
|
||||
);
|
||||
}
|
||||
|
||||
/** Uses the operation alias o; serialized payloads may live outside the routing row. */
|
||||
export const routineObservationSql = `(CASE WHEN o.kind IN (${observationKinds.map(kind => `'${kind}'`).join(',')}) THEN 1
|
||||
export const routineObservationSql = `(CASE WHEN o.kind IN (${observationKinds.map((kind) => `'${kind}'`).join(',')}) THEN 1
|
||||
WHEN o.kind='rcon.execute' THEN json_extract(COALESCE(
|
||||
(SELECT p.payload FROM ec_host_operation_payloads p WHERE p.operation_id=o.id),o.payload),'$.command') IN ('status','getstatus','version')
|
||||
ELSE 0 END)`;
|
||||
@@ -32,7 +59,8 @@ export const successfulObservationSql = `(o.state='completed' AND COALESCE(o.err
|
||||
export const importantOperationSql = `(o.routine=0 OR o.state IN ('failed','unknown')
|
||||
OR (o.state='completed' AND o.observation_success=0) OR COALESCE(o.error,'')!='')`;
|
||||
|
||||
const payloadSql = 'COALESCE((SELECT p.payload FROM ec_host_operation_payloads p WHERE p.operation_id=o.id),o.payload)';
|
||||
const payloadSql =
|
||||
'COALESCE((SELECT p.payload FROM ec_host_operation_payloads p WHERE p.operation_id=o.id),o.payload)';
|
||||
/** Deliberately exclude arbitrary RCON commands and all file contents/credentials. */
|
||||
export const operationTargetSql = `CASE
|
||||
WHEN o.kind='plutonium.prepare' THEN CASE
|
||||
|
||||
Reference in New Issue
Block a user