refactor(striker-ui-api): rename print functions

main
Tsu-ba-me 9 months ago
parent 7d6bc9aaaf
commit 4d5d698a9c
  1. 4
      striker-ui-api/src/app.ts
  2. 10
      striker-ui-api/src/index.ts
  3. 42
      striker-ui-api/src/lib/accessModule.ts
  4. 6
      striker-ui-api/src/lib/execManageAlerts.ts
  5. 14
      striker-ui-api/src/lib/getSessionSecret.ts
  6. 8
      striker-ui-api/src/lib/request_handlers/alert-override/createAlertOverride.ts
  7. 4
      striker-ui-api/src/lib/request_handlers/alert-override/deleteAlertOverride.ts
  8. 8
      striker-ui-api/src/lib/request_handlers/alert-override/updateAlertOverride.ts
  9. 6
      striker-ui-api/src/lib/request_handlers/anvil/buildAnvilSummary.ts
  10. 4
      striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts
  11. 6
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilCpu.ts
  12. 6
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilDetail.ts
  13. 6
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilMemory.ts
  14. 8
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilNetwork.ts
  15. 6
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilStore.ts
  16. 6
      striker-ui-api/src/lib/request_handlers/anvil/getAnvilSummary.ts
  17. 4
      striker-ui-api/src/lib/request_handlers/auth/login.ts
  18. 4
      striker-ui-api/src/lib/request_handlers/auth/logout.ts
  19. 6
      striker-ui-api/src/lib/request_handlers/buildBranchRequestHandler.ts
  20. 8
      striker-ui-api/src/lib/request_handlers/buildDeleteRequestHandler.ts
  21. 10
      striker-ui-api/src/lib/request_handlers/buildGetRequestHandler.ts
  22. 8
      striker-ui-api/src/lib/request_handlers/command/buildMembershipHandler.ts
  23. 12
      striker-ui-api/src/lib/request_handlers/command/buildPowerHandler.ts
  24. 6
      striker-ui-api/src/lib/request_handlers/command/getHostSSH.ts
  25. 10
      striker-ui-api/src/lib/request_handlers/command/runManifest.ts
  26. 8
      striker-ui-api/src/lib/request_handlers/command/setMapNetwork.ts
  27. 4
      striker-ui-api/src/lib/request_handlers/command/updateSystem.ts
  28. 8
      striker-ui-api/src/lib/request_handlers/fence/createFence.ts
  29. 4
      striker-ui-api/src/lib/request_handlers/fence/getFence.ts
  30. 4
      striker-ui-api/src/lib/request_handlers/fence/getFenceTemplate.ts
  31. 4
      striker-ui-api/src/lib/request_handlers/file/buildQueryFileDetail.ts
  32. 6
      striker-ui-api/src/lib/request_handlers/file/createFile.ts
  33. 10
      striker-ui-api/src/lib/request_handlers/file/updateFile.ts
  34. 4
      striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts
  35. 10
      striker-ui-api/src/lib/request_handlers/host/configStriker.ts
  36. 30
      striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts
  37. 4
      striker-ui-api/src/lib/request_handlers/host/deleteHostConnection.ts
  38. 6
      striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts
  39. 6
      striker-ui-api/src/lib/request_handlers/host/prepareHost.ts
  40. 10
      striker-ui-api/src/lib/request_handlers/host/prepareNetwork.ts
  41. 6
      striker-ui-api/src/lib/request_handlers/host/setHostInstallTarget.ts
  42. 4
      striker-ui-api/src/lib/request_handlers/job/getJob.ts
  43. 8
      striker-ui-api/src/lib/request_handlers/mail-recipient/createMailRecipient.ts
  44. 6
      striker-ui-api/src/lib/request_handlers/mail-recipient/deleteMailRecipient.ts
  45. 8
      striker-ui-api/src/lib/request_handlers/mail-recipient/updateMailRecipient.ts
  46. 8
      striker-ui-api/src/lib/request_handlers/mail-server/createMailServer.ts
  47. 4
      striker-ui-api/src/lib/request_handlers/mail-server/deleteMailServer.ts
  48. 8
      striker-ui-api/src/lib/request_handlers/mail-server/updateMailServer.ts
  49. 4
      striker-ui-api/src/lib/request_handlers/manifest/buildManifest.ts
  50. 4
      striker-ui-api/src/lib/request_handlers/manifest/createManifest.ts
  51. 6
      striker-ui-api/src/lib/request_handlers/manifest/deleteManifest.ts
  52. 14
      striker-ui-api/src/lib/request_handlers/manifest/getManifestDetail.ts
  53. 6
      striker-ui-api/src/lib/request_handlers/manifest/getManifestTemplate.ts
  54. 6
      striker-ui-api/src/lib/request_handlers/manifest/updateManifest.ts
  55. 10
      striker-ui-api/src/lib/request_handlers/server/createServer.ts
  56. 6
      striker-ui-api/src/lib/request_handlers/server/deleteServer.ts
  57. 4
      striker-ui-api/src/lib/request_handlers/server/getServer.ts
  58. 14
      striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts
  59. 4
      striker-ui-api/src/lib/request_handlers/ssh-key/deleteSSHKeyConflict.ts
  60. 6
      striker-ui-api/src/lib/request_handlers/ups/createUps.ts
  61. 4
      striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts
  62. 8
      striker-ui-api/src/lib/request_handlers/user/createUser.ts
  63. 8
      striker-ui-api/src/lib/request_handlers/user/deleteUser.ts
  64. 12
      striker-ui-api/src/lib/request_handlers/user/updateUser.ts
  65. 4
      striker-ui-api/src/lib/rrouters.ts
  66. 6
      striker-ui-api/src/lib/shell.ts
  67. 6
      striker-ui-api/src/middlewares/assertAuthentication.ts
  68. 8
      striker-ui-api/src/middlewares/assertInit.ts
  69. 10
      striker-ui-api/src/middlewares/file.ts
  70. 8
      striker-ui-api/src/middlewares/passport.ts
  71. 12
      striker-ui-api/src/middlewares/proxyServerVnc.ts
  72. 20
      striker-ui-api/src/middlewares/session.ts
  73. 4
      striker-ui-api/src/routes/echo.ts
  74. 4
      striker-ui-api/src/routes/static.ts

@ -4,7 +4,7 @@ import express, { json } from 'express';
import { guardApi, passport, session } from './middlewares';
import routes from './routes';
import { rrouters } from './lib/rrouters';
import { stdout } from './lib/shell';
import { pout } from './lib/shell';
export default (async () => {
const app = express();
@ -26,7 +26,7 @@ export default (async () => {
app.use(passport.authenticate('session'));
app.use(({ originalUrl, method }, response, next) => {
stdout(`Received ${method} ${originalUrl}`);
pout(`Received ${method} ${originalUrl}`);
next();
});

@ -3,7 +3,7 @@ import { getgid, getuid, setgid, setuid } from 'process';
import { PGID, PUID, PORT, ECODE_DROP_PRIVILEGES } from './lib/consts';
import { access } from './lib/accessModule';
import { stderr, stdout } from './lib/shell';
import { perr, pout } from './lib/shell';
/**
* Wait until the anvil-access-module daemon finishes its setup before doing
@ -20,7 +20,7 @@ access.once('active', async () => {
/* webpackMode: "eager" */ './middlewares'
);
stdout(`Starting main process with ownership ${getuid()}:${getgid()}`);
pout(`Starting main process with ownership ${getuid()}:${getgid()}`);
const server = (await app).listen(PORT, () => {
try {
@ -28,14 +28,14 @@ access.once('active', async () => {
setgid(PGID);
setuid(PUID);
stdout(`Main process ownership changed to ${getuid()}:${getgid()}.`);
pout(`Main process ownership changed to ${getuid()}:${getgid()}.`);
} catch (error) {
stderr(`Failed to change main process ownership; CAUSE: ${error}`);
perr(`Failed to change main process ownership; CAUSE: ${error}`);
process.exit(ECODE_DROP_PRIVILEGES);
}
stdout(`Listening on localhost:${PORT}.`);
pout(`Listening on localhost:${PORT}.`);
});
server.on('upgrade', proxyServerVncUpgrade);

@ -13,13 +13,7 @@ import {
import { formatSql } from './formatSql';
import { repeat } from './repeat';
import {
date,
stderr as sherr,
stdout as shout,
stdoutVar as shvar,
uuid,
} from './shell';
import { date, perr, pout, poutvar, uuid } from './shell';
/**
* Notes:
@ -37,7 +31,7 @@ class Access extends EventEmitter {
(args: { options: AccessStartOptions; ps: ChildProcess }) => void
> = {
connected: ({ options, ps }) => {
shvar(
poutvar(
options,
`Successfully started anvil-access-module daemon (pid=${ps.pid}): `,
);
@ -81,7 +75,7 @@ class Access extends EventEmitter {
...restSpawnOptions,
};
shvar(options, `Starting anvil-access-module daemon with: `);
poutvar(options, `Starting anvil-access-module daemon with: `);
const ps = spawn(SERVER_PATHS.usr.sbin['anvil-access-module'].self, args, {
gid,
@ -91,21 +85,21 @@ class Access extends EventEmitter {
});
ps.once('error', (error) => {
sherr(
perr(
`anvil-access-module daemon (pid=${ps.pid}) error: ${error.message}`,
error,
);
});
ps.once('close', (code, signal) => {
shvar(
poutvar(
{ code, options, signal },
`anvil-access-module daemon (pid=${ps.pid}) closed: `,
);
this.emit('inactive', ps.pid);
shout(`Waiting ${restartInterval} before restarting.`);
pout(`Waiting ${restartInterval} before restarting.`);
setTimeout(() => {
this.ps = this.start(options);
@ -113,14 +107,14 @@ class Access extends EventEmitter {
});
ps.stderr?.setEncoding('utf-8').on('data', (chunk: string) => {
sherr(`anvil-access-module daemon stderr: ${chunk}`);
perr(`anvil-access-module daemon stderr: ${chunk}`);
});
let stdout = '';
ps.stdout?.setEncoding('utf-8').on('data', (chunk: string) => {
const eventless = chunk.replace(/(\n)?event=([^\n]*)\n/g, (...parts) => {
shvar(parts, 'In replacer, args: ');
poutvar(parts, 'In replacer, args: ');
const { 1: n = '', 2: event } = parts;
@ -142,7 +136,7 @@ class Access extends EventEmitter {
if (REP_UUID.test(scriptId)) {
this.emit(scriptId, output);
} else {
shout(`Access stdout: ${stdout}`);
pout(`Access stdout: ${stdout}`);
}
stdout = stdout.substring(nindex + 1);
@ -184,13 +178,13 @@ class Access extends EventEmitter {
return reject(`Failed to parse line ${scriptId}; got [${data}]`);
}
shvar({ result }, `Access interact ${scriptId} returns: `);
poutvar({ result }, `Access interact ${scriptId} returns: `);
return resolve(result);
});
});
shvar({ script }, 'Access interact: ');
poutvar({ script }, 'Access interact: ');
stdin?.write(script);
@ -301,9 +295,9 @@ const refreshTimestamp = () => {
try {
result = date('--rfc-3339', 'ns').trim();
} catch (shError) {
} catch (error) {
throw new Error(
`Failed to get timestamp for database use; CAUSE: ${shError}`,
`Failed to get timestamp for database use; CAUSE: ${error}`,
);
}
@ -326,7 +320,7 @@ const getData = async <T>(...keys: string[]) => {
sub_results: [data],
} = await access.interact<{ sub_results: [T] }>('x', chain);
shvar(data, `${chain} data: `);
poutvar(data, `${chain} data: `);
return data;
};
@ -344,7 +338,7 @@ const mutateData = async <T>(args: {
sub_results: [data],
} = await access.interact<{ sub_results: [T] }>('x', chain, operator, value);
shvar(data, `${chain} data: `);
poutvar(data, `${chain} data: `);
return data;
};
@ -391,7 +385,7 @@ const getLocalHostName = () => {
throw new Error(`Failed to get local host name; CAUSE: ${subError}`);
}
shout(`localHostName=${result}`);
pout(`localHostName=${result}`);
return result;
};
@ -407,7 +401,7 @@ const getLocalHostUuid = () => {
throw new Error(`Failed to get local host UUID; CAUSE: ${subError}`);
}
shout(`localHostUUID=[${result}]`);
pout(`localHostUUID=[${result}]`);
return result;
};
@ -498,7 +492,7 @@ const getVncinfo = async (serverUuid: string): Promise<ServerDetailVncInfo> => {
protocol,
};
shvar(result, `VNC info for server [${serverUuid}]: `);
poutvar(result, `VNC info for server [${serverUuid}]: `);
return result;
};

@ -3,7 +3,7 @@ import { SpawnSyncReturns, spawnSync } from 'child_process';
import { P_UUID, SERVER_PATHS } from './consts';
import { stdoutVar } from './shell';
import { poutvar } from './shell';
const MAP_TO_FLAG_BUNDLE: {
'alert-overrides': Record<keyof AlertOverrideRequestBody | 'uuid', string>;
@ -67,7 +67,7 @@ export const execManageAlerts = (
[`--${entities}`, `--${operation}`, '--yes'],
);
stdoutVar({ commandArgs }, 'Manage alerts with args: ');
poutvar({ commandArgs }, 'Manage alerts with args: ');
let result: SpawnSyncReturns<string>;
@ -80,7 +80,7 @@ export const execManageAlerts = (
const { error, signal, status, stderr, stdout } = result;
stdoutVar(
poutvar(
{ error, signal, status, stderr, stdout },
'Manage alerts returned: ',
);

@ -3,7 +3,7 @@ import assert from 'assert';
import { ECODE_SESSION_SECRET, VNAME_SESSION_SECRET } from './consts';
import { query, variable } from './accessModule';
import { openssl, stderr, stdout } from './shell';
import { openssl, perr, pout } from './shell';
export const getSessionSecret = async (): Promise<string> => {
let sessionSecret: string;
@ -21,19 +21,19 @@ export const getSessionSecret = async (): Promise<string> => {
0: [sessionSecret],
} = rows);
stdout('Found an existing session secret.');
pout('Found an existing session secret.');
return sessionSecret;
} catch (queryError) {
stderr(`Failed to get session secret from database; CAUSE: ${queryError}`);
perr(`Failed to get session secret from database; CAUSE: ${queryError}`);
}
try {
sessionSecret = openssl('rand', '-base64', '32').trim();
stdout('Generated a new session secret.');
pout('Generated a new session secret.');
} catch (sysError) {
stderr(`Failed to generate session secret; CAUSE: ${sysError}`);
perr(`Failed to generate session secret; CAUSE: ${sysError}`);
process.exit(ECODE_SESSION_SECRET);
}
@ -45,9 +45,9 @@ export const getSessionSecret = async (): Promise<string> => {
variable_value: sessionSecret,
});
stdout(`Recorded session secret as variable identified by ${vuuid}.`);
pout(`Recorded session secret as variable identified by ${vuuid}.`);
} catch (subError) {
stderr(`Failed to record session secret; CAUSE: ${subError}`);
perr(`Failed to record session secret; CAUSE: ${subError}`);
process.exit(ECODE_SESSION_SECRET);
}

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { getAlertOverrideRequestBody } from './getAlertOverrideRequestBody';
import { stderr, stdout } from '../../shell';
import { perr, pout } from '../../shell';
export const createAlertOverride: RequestHandler<
undefined,
@ -11,14 +11,14 @@ export const createAlertOverride: RequestHandler<
> = (request, response) => {
const { body: rBody = {} } = request;
stdout(`Begin creating alert override.`);
pout(`Begin creating alert override.`);
let body: AlertOverrideRequestBody;
try {
body = getAlertOverrideRequestBody(rBody);
} catch (error) {
stderr(`Failed to process alert override input; CAUSE: ${error}`);
perr(`Failed to process alert override input; CAUSE: ${error}`);
return response.status(400).send();
}
@ -26,7 +26,7 @@ export const createAlertOverride: RequestHandler<
try {
execManageAlerts('alert-overrides', 'add', { body });
} catch (error) {
stderr(`Failed to create alert override; CAUSE: ${error}`);
perr(`Failed to create alert override; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,7 +1,7 @@
import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const deleteAlertOverride: RequestHandler<AlertOverrideReqParams> = (
request,
@ -14,7 +14,7 @@ export const deleteAlertOverride: RequestHandler<AlertOverrideReqParams> = (
try {
execManageAlerts('alert-overrides', 'delete', { uuid });
} catch (error) {
stderr(`Failed to delete alert override: CAUSE: ${error}`);
perr(`Failed to delete alert override: CAUSE: ${error}`);
return response.status(500).send();
}

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { getAlertOverrideRequestBody } from './getAlertOverrideRequestBody';
import { stderr, stdout } from '../../shell';
import { perr, pout } from '../../shell';
export const updateAlertOverride: RequestHandler<
AlertOverrideReqParams,
@ -14,14 +14,14 @@ export const updateAlertOverride: RequestHandler<
params: { uuid },
} = request;
stdout('Begin updating alert override.');
pout('Begin updating alert override.');
let body: AlertOverrideRequestBody;
try {
body = getAlertOverrideRequestBody(rBody, uuid);
} catch (error) {
stderr(`Failed to process alert override input; CAUSE: ${error}`);
perr(`Failed to process alert override input; CAUSE: ${error}`);
return response.status(400).send();
}
@ -29,7 +29,7 @@ export const updateAlertOverride: RequestHandler<
try {
execManageAlerts('alert-overrides', 'edit', { body, uuid });
} catch (error) {
stderr(`Failed to update alert override; CAUSE: ${error}`);
perr(`Failed to update alert override; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,7 +1,7 @@
import assert from 'assert';
import { query } from '../../accessModule';
import { stderr } from '../../shell';
import { perr } from '../../shell';
const buildHostStateMessage = (postfix = 2) => `message_022${postfix}`;
@ -55,7 +55,7 @@ export const buildAnvilSummary = async ({
ORDER BY b.host_name;`,
);
} catch (error) {
stderr(`Failed to get subnodes' server count; CAUSE: ${error}`);
perr(`Failed to get subnodes' server count; CAUSE: ${error}`);
throw error;
}
@ -113,7 +113,7 @@ export const buildAnvilSummary = async ({
assert.ok(rows.length, 'No node cluster info');
} catch (error) {
stderr(`Failed to get node ${huuid} cluster status; CAUSE: ${error}`);
perr(`Failed to get node ${huuid} cluster status; CAUSE: ${error}`);
continue;
}

@ -7,7 +7,7 @@ import {
} from '../../consts';
import join from '../../join';
import { stdoutVar } from '../../shell';
import { poutvar } from '../../shell';
const buildQueryAnvilDetail = ({
anvilUUIDs = ['*'],
@ -25,7 +25,7 @@ const buildQueryAnvilDetail = ({
separator: ', ',
});
stdoutVar({ condAnvilsUUID });
poutvar({ condAnvilsUUID });
const buildHostQuery = ({
isSummary = false,

@ -4,7 +4,7 @@ import { DELETED } from '../../consts';
import { query } from '../../accessModule';
import { getShortHostName } from '../../disassembleHostName';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async (
request,
@ -52,7 +52,7 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async (
ORDER BY b.host_name;`,
);
} catch (error) {
stderr(`Failed to get anvil ${anvilUuid} cpu info; CAUSE: ${error}`);
perr(`Failed to get anvil ${anvilUuid} cpu info; CAUSE: ${error}`);
return response.status(500).send();
}
@ -78,7 +78,7 @@ export const getAnvilCpu: RequestHandler<AnvilDetailParamsDictionary> = async (
AND a.server_anvil_uuid = '${anvilUuid}';`,
);
} catch (error) {
stderr(`Failed to get anvil ${anvilUuid} server cpu info; CAUSE: ${error}`);
perr(`Failed to get anvil ${anvilUuid} server cpu info; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,7 +1,7 @@
import { RequestHandler } from 'express';
import { getAnvilData, getHostData } from '../../accessModule';
import { stderr } from '../../shell';
import { perr } from '../../shell';
import { buildAnvilSummary } from './buildAnvilSummary';
export const getAnvilDetail: RequestHandler<
@ -20,7 +20,7 @@ export const getAnvilDetail: RequestHandler<
anvils = await getAnvilData();
hosts = await getHostData();
} catch (error) {
stderr(`Failed to get anvil and/or host data; CAUSE: ${error}`);
perr(`Failed to get anvil and/or host data; CAUSE: ${error}`);
return response.status(500).send();
}
@ -34,7 +34,7 @@ export const getAnvilDetail: RequestHandler<
hosts,
});
} catch (error) {
stderr(`Failed to get summary of anvil node ${anvilUuid}; CAUSE: ${error}`);
perr(`Failed to get summary of anvil node ${anvilUuid}; CAUSE: ${error}`);
return response.status(500).send();
}

@ -4,7 +4,7 @@ import { DataSizeUnit, dSize } from 'format-data-size';
import { DELETED, NODE_AND_DR_RESERVED_MEMORY_SIZE } from '../../consts';
import { query } from '../../accessModule';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const getAnvilMemory: RequestHandler<
AnvilDetailParamsDictionary
@ -50,7 +50,7 @@ export const getAnvilMemory: RequestHandler<
ORDER BY b.host_name;`,
);
} catch (error) {
stderr(`Failed to get anvil ${anvilUuid} memory info; CAUSE: ${error}`);
perr(`Failed to get anvil ${anvilUuid} memory info; CAUSE: ${error}`);
return response.status(500).send();
}
@ -92,7 +92,7 @@ export const getAnvilMemory: RequestHandler<
AND b.server_anvil_uuid = '${anvilUuid}';`,
);
} catch (error) {
stderr(`Failed to get anvil ${anvilUuid} server info; CAUSE: ${error}`);
perr(`Failed to get anvil ${anvilUuid} server info; CAUSE: ${error}`);
return response.status(500).send();
}

@ -5,7 +5,7 @@ import { REP_UUID } from '../../consts';
import { getAnvilData, getHostData, getNetworkData } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
import { perr } from '../../shell';
const degrade = (current: string) =>
current === 'optimal' ? 'degraded' : current;
@ -100,7 +100,7 @@ export const getAnvilNetwork: RequestHandler<
`Param UUID must be a valid UUIDv4; got [${anUuid}]`,
);
} catch (error) {
stderr(`Failed to assert value during get anvil network; CAUSE: ${error}`);
perr(`Failed to assert value during get anvil network; CAUSE: ${error}`);
return response.status(400).send();
}
@ -112,7 +112,7 @@ export const getAnvilNetwork: RequestHandler<
ans = await getAnvilData();
hosts = await getHostData();
} catch (error) {
stderr(`Failed to get anvil and host data; CAUSE: ${error}`);
perr(`Failed to get anvil and host data; CAUSE: ${error}`);
return response.status(500).send();
}
@ -149,7 +149,7 @@ export const getAnvilNetwork: RequestHandler<
host_uuid: hostUuid,
});
} catch (error) {
stderr(`Failed to get host ${hostUuid} network data; CAUSE: ${error}`);
perr(`Failed to get host ${hostUuid} network data; CAUSE: ${error}`);
return response.status(500).send();
}

@ -5,7 +5,7 @@ import { REP_UUID } from '../../consts';
import { query } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const getAnvilStore: RequestHandler<
AnvilDetailParamsDictionary
@ -22,7 +22,7 @@ export const getAnvilStore: RequestHandler<
`Param UUID must be a valid UUIDv4; got [${anUuid}]`,
);
} catch (error) {
stderr(`Failed to assert value during get anvil storage; CAUSE: ${error}`);
perr(`Failed to assert value during get anvil storage; CAUSE: ${error}`);
return response.status(400).send();
}
@ -61,7 +61,7 @@ export const getAnvilStore: RequestHandler<
ORDER BY b.storage_group_uuid, d.scan_lvm_vg_free;`,
);
} catch (error) {
stderr(`Failed to get anvil storage summary; CAUSE: ${error}`);
perr(`Failed to get anvil storage summary; CAUSE: ${error}`);
return response.status(500).send();
}

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { getAnvilData, getHostData } from '../../accessModule';
import { buildAnvilSummary } from './buildAnvilSummary';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async (
request,
@ -15,7 +15,7 @@ export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async (
anvils = await getAnvilData();
hosts = await getHostData();
} catch (error) {
stderr(`Failed to get anvil and/or host data; CAUSE: ${error}`);
perr(`Failed to get anvil and/or host data; CAUSE: ${error}`);
return response.status(500).send();
}
@ -30,7 +30,7 @@ export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async (
);
}
} catch (error) {
stderr(`Failed to get summary of anvil nodes; CAUSE: ${error}`);
perr(`Failed to get summary of anvil nodes; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,6 +1,6 @@
import { RequestHandler } from 'express';
import { stdout } from '../../shell';
import { pout } from '../../shell';
import { cname } from '../../cname';
export const login: RequestHandler<unknown, unknown, AuthLoginRequestBody> = (
@ -12,7 +12,7 @@ export const login: RequestHandler<unknown, unknown, AuthLoginRequestBody> = (
if (user) {
const { name: userName } = user;
stdout(`Successfully authenticated user [${userName}]`);
pout(`Successfully authenticated user [${userName}]`);
response.cookie(cname('session'), {
expires: session?.cookie?.expires,

@ -1,12 +1,12 @@
import { RequestHandler } from 'express';
import { cname } from '../../cname';
import { stdout } from '../../shell';
import { pout } from '../../shell';
export const logout: RequestHandler = (request, response) => {
request.session.destroy((error) => {
if (error) {
stdout(`Failed to destroy session upon logout; CAUSE: ${error}`);
pout(`Failed to destroy session upon logout; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,7 +1,7 @@
import { RequestHandler } from 'express';
import { sanitize } from '../sanitize';
import { stderr, stdout } from '../shell';
import { perr, pout } from '../shell';
export const buildBranchRequestHandler: (map: {
[handler: string]: RequestHandler | undefined;
@ -17,7 +17,7 @@ export const buildBranchRequestHandler: (map: {
const handlerKey = sanitize(rawHandler, 'string');
stdout(`Create host handler: ${handlerKey}`);
pout(`Create host handler: ${handlerKey}`);
// Ensure each handler sends a response at the end of any branch.
const handler = map[handlerKey];
@ -25,7 +25,7 @@ export const buildBranchRequestHandler: (map: {
if (handler) {
handler(...args);
} else {
stderr(`Handler is not registered; got [${handlerKey}]`);
perr(`Handler is not registered; got [${handlerKey}]`);
response.status(400).send();

@ -2,7 +2,7 @@ import { AssertionError } from 'assert';
import { RequestHandler } from 'express';
import { sanitize } from '../sanitize';
import { stderr, stdoutVar } from '../shell';
import { perr, poutvar } from '../shell';
export const buildDeleteRequestHandler =
<
@ -41,7 +41,7 @@ export const buildDeleteRequestHandler =
list.push(rId);
}
stdoutVar(list, `Process delete request with list: `);
poutvar(list, `Process delete request with list: `);
try {
await handleDelete(list, ...handlerArgs);
@ -51,11 +51,11 @@ export const buildDeleteRequestHandler =
if (error instanceof AssertionError) {
scode = 400;
stderr(`Failed to assert value during delete request; CAUSE: ${error}`);
perr(`Failed to assert value during delete request; CAUSE: ${error}`);
} else {
scode = 500;
stderr(`Failed to complete delete request; CAUSE: ${error}`);
perr(`Failed to complete delete request; CAUSE: ${error}`);
}
return response.status(scode).send();

@ -2,7 +2,7 @@ import { Request, Response } from 'express';
import { query } from '../accessModule';
import call from '../call';
import { stderr, stdout, stdoutVar } from '../shell';
import { perr, pout, poutvar } from '../shell';
const buildGetRequestHandler =
(
@ -10,7 +10,7 @@ const buildGetRequestHandler =
{ beforeRespond }: BuildGetRequestHandlerOptions = {},
) =>
async (request: Request, response: Response) => {
stdout('Calling CLI script to get data.');
pout('Calling CLI script to get data.');
const buildQueryOptions: BuildQueryOptions = {};
@ -24,12 +24,12 @@ const buildGetRequestHandler =
result = await query(sqlscript);
} catch (queryError) {
stderr(`Failed to execute query; CAUSE: ${queryError}`);
perr(`Failed to execute query; CAUSE: ${queryError}`);
return response.status(500).send();
}
stdoutVar(result, `Query stdout pre-hooks (type=[${typeof result}]): `);
poutvar(result, `Query stdout pre-hooks (type=[${typeof result}]): `);
const { afterQueryReturn } = buildQueryOptions;
@ -43,7 +43,7 @@ const buildGetRequestHandler =
notCallableReturn: result,
});
stdoutVar(result, `Query stdout post-hooks (type=[${typeof result}]): `);
poutvar(result, `Query stdout post-hooks (type=[${typeof result}]): `);
response.json(result);
};

@ -5,7 +5,7 @@ import { REP_UUID, SERVER_PATHS } from '../../consts';
import { job, query } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
import { perr } from '../../shell';
const MAP_TO_MEMBERSHIP_JOB_PARAMS_BUILDER: Record<
MembershipTask,
@ -66,7 +66,7 @@ export const buildMembershipHandler: (
`Param UUID must be a valid UUIDv4; got: [${hostUuid}]`,
);
} catch (error) {
stderr(
perr(
`Failed to assert value when changing host membership; CAUSE: ${error}`,
);
@ -93,7 +93,7 @@ export const buildMembershipHandler: (
assert.ok(rows.length, `No entry found`);
} catch (error) {
stderr(`Failed to get cluster status of host ${hostUuid}; CAUSE: ${error}`);
perr(`Failed to get cluster status of host ${hostUuid}; CAUSE: ${error}`);
return response.status(500).send();
}
@ -112,7 +112,7 @@ export const buildMembershipHandler: (
await job({ file: __filename, ...restParams });
}
} catch (error) {
stderr(
perr(
`Failed to initiate ${task} cluster for host ${hostUuid}; CAUSE: ${error}`,
);

@ -5,7 +5,7 @@ import { DELETED, LOCAL, REP_UUID, SERVER_PATHS } from '../../consts';
import { job, query } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
import { perr } from '../../shell';
/**
* Notes on power functions:
@ -103,7 +103,7 @@ export const buildPowerHandler: (
);
}
} catch (error) {
stderr(`Failed to ${task}; CAUSE: ${error}`);
perr(`Failed to ${task}; CAUSE: ${error}`);
return response.status(400).send();
}
@ -113,7 +113,7 @@ export const buildPowerHandler: (
await queuePowerJob(task, { force, runOn, uuid });
} catch (error) {
stderr(`Failed to ${task} ${uuid ?? LOCAL}; CAUSE: ${error}`);
perr(`Failed to ${task} ${uuid ?? LOCAL}; CAUSE: ${error}`);
return response.status(500).send();
}
@ -136,7 +136,7 @@ export const buildAnPowerHandler: (
`Param UUID must be a valid UUIDv4; got: [${anUuid}]`,
);
} catch (error) {
stderr(`Failed to assert value during power operation on anvil subnode`);
perr(`Failed to assert value during power operation on anvil subnode`);
return response.status(400).send();
}
@ -151,7 +151,7 @@ export const buildAnPowerHandler: (
assert.ok(rows.length, 'No entry found');
} catch (error) {
stderr(`Failed to get anvil subnodes' UUID; CAUSE: ${error}`);
perr(`Failed to get anvil subnodes' UUID; CAUSE: ${error}`);
return response.status(500).send();
}
@ -160,7 +160,7 @@ export const buildAnPowerHandler: (
try {
await queuePowerJob(task, { isStopServers: true, uuid: hostUuid });
} catch (error) {
stderr(`Failed to ${task} host ${hostUuid}; CAUSE: ${error}`);
perr(`Failed to ${task} host ${hostUuid}; CAUSE: ${error}`);
return response.status(500).send();
}

@ -6,7 +6,7 @@ import { HOST_KEY_CHANGED_PREFIX } from '../../consts/HOST_KEY_CHANGED_PREFIX';
import { getLocalHostUUID, getPeerData, query } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const getHostSSH: RequestHandler<
unknown,
@ -37,7 +37,7 @@ export const getHostSSH: RequestHandler<
`IP address must be a valid IPv4 address; got [${target}]`,
);
} catch (assertError) {
stderr(`Assert failed when getting host SSH data; CAUSE: ${assertError}`);
perr(`Assert failed when getting host SSH data; CAUSE: ${assertError}`);
return response.status(400).send();
}
@ -49,7 +49,7 @@ export const getHostSSH: RequestHandler<
try {
rsbody = await getPeerData(target, { password, port });
} catch (subError) {
stderr(`Failed to get peer data; CAUSE: ${subError}`);
perr(`Failed to get peer data; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -12,7 +12,7 @@ import {
sub,
} from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const runManifest: RequestHandler<
{ manifestUuid: string },
@ -35,7 +35,7 @@ export const runManifest: RequestHandler<
const hostList: ManifestExecutionHostList = {};
const handleAssertError = (assertError: unknown) => {
stderr(
perr(
`Failed to assert value when trying to run manifest ${manifestUuid}; CAUSE: ${assertError}`,
);
@ -93,9 +93,7 @@ export const runManifest: RequestHandler<
rawManifestListData = await getManifestData(manifestUuid);
rawSysData = await getData('sys');
} catch (subError) {
stderr(
`Failed to get install manifest ${manifestUuid}; CAUSE: ${subError}`,
);
perr(`Failed to get install manifest ${manifestUuid}; CAUSE: ${subError}`);
return response.status(500).send();
}
@ -169,7 +167,7 @@ export const runManifest: RequestHandler<
await job(jobParams);
}
} catch (subError) {
stderr(`Failed to record new anvil node entry; CAUSE: ${subError}`);
perr(`Failed to record new anvil node entry; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -6,7 +6,7 @@ import { LOCAL, REP_UUID } from '../../consts';
import { variable } from '../../accessModule';
import { toHostUUID } from '../../convertHostUUID';
import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell';
import { perr, poutvar } from '../../shell';
export const setMapNetwork: RequestHandler<
{ uuid: string },
@ -24,7 +24,7 @@ export const setMapNetwork: RequestHandler<
hostUuid = toHostUUID(hostUuid);
stdoutVar({ hostUuid, value }, `Set map network variable with: `);
poutvar({ hostUuid, value }, `Set map network variable with: `);
try {
assert(
@ -37,7 +37,7 @@ export const setMapNetwork: RequestHandler<
`Host UUID must be a valid UUIDv4; got [${hostUuid}]`,
);
} catch (error) {
stderr(`Assert failed when set map network variable; CAUSE: ${error}`);
perr(`Assert failed when set map network variable; CAUSE: ${error}`);
return response.status(400).send();
}
@ -59,7 +59,7 @@ export const setMapNetwork: RequestHandler<
`Result must be UUID of modified record; got: [${result}]`,
);
} catch (error) {
stderr(
perr(
`Failed to set map network variable for host ${hostUuid}; CAUSE: ${error}`,
);

@ -3,7 +3,7 @@ import { RequestHandler } from 'express';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const updateSystem: RequestHandler = async (request, response) => {
try {
@ -15,7 +15,7 @@ export const updateSystem: RequestHandler = async (request, response) => {
job_title: 'job_0003',
});
} catch (subError) {
stderr(`Failed to initiate system update; CAUSE: ${subError}`);
perr(`Failed to initiate system update; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -5,7 +5,7 @@ import { REP_PEACEFUL_STRING } from '../../consts';
import { getFenceSpec, timestamp, write } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr, stdoutVar, uuid } from '../../shell';
import { perr, poutvar, uuid } from '../../shell';
const handleNumberType = (v: unknown) =>
String(sanitize(v, 'number', { modifierType: 'sql' }));
@ -43,7 +43,7 @@ export const createFence: RequestHandler<
try {
fenceSpec = await getFenceSpec();
} catch (error) {
stderr(`Failed to get fence devices specification; CAUSE: ${error}`);
perr(`Failed to get fence devices specification; CAUSE: ${error}`);
return response.status(500).send();
}
@ -100,7 +100,7 @@ export const createFence: RequestHandler<
}, [])
.join(' ');
stdoutVar(
poutvar(
{ agent, args, name },
`Proceed to record fence device (${fenceUuid}): `,
);
@ -132,7 +132,7 @@ export const createFence: RequestHandler<
assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (error) {
stderr(`Failed to write fence record; CAUSE: ${error}`);
perr(`Failed to write fence record; CAUSE: ${error}`);
return response.status(500).send();
}

@ -4,7 +4,7 @@ import { DELETED } from '../../consts';
import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import { stdout } from '../../shell';
import { pout } from '../../shell';
export const getFence: RequestHandler = buildGetRequestHandler(
(request, buildQueryOptions) => {
@ -48,7 +48,7 @@ export const getFence: RequestHandler = buildGetRequestHandler(
{},
);
stdout(
pout(
`${fenceAgent}: ${fenceName} (${fenceUUID})\n${JSON.stringify(
fenceParameters,
null,

@ -1,7 +1,7 @@
import { RequestHandler } from 'express';
import { getFenceSpec } from '../../accessModule';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const getFenceTemplate: RequestHandler = async (request, response) => {
let rFenceData: AnvilDataFenceHash;
@ -9,7 +9,7 @@ export const getFenceTemplate: RequestHandler = async (request, response) => {
try {
rFenceData = await getFenceSpec();
} catch (subError) {
stderr(`Failed to get fence device template; CAUSE: ${subError}`);
perr(`Failed to get fence device template; CAUSE: ${subError}`);
response.status(500).send();

@ -1,7 +1,7 @@
import { DELETED } from '../../consts';
import join from '../../join';
import { stdoutVar } from '../../shell';
import { poutvar } from '../../shell';
export const buildQueryFileDetail = ({
fileUUIDs = ['*'],
@ -17,7 +17,7 @@ export const buildQueryFileDetail = ({
separator: ', ',
});
stdoutVar({ condFileUUIDs });
poutvar({ condFileUUIDs });
return `
SELECT

@ -1,14 +1,14 @@
import { RequestHandler } from 'express';
import { anvilSyncShared } from '../../accessModule';
import { stdout, stdoutVar } from '../../shell';
import { pout, poutvar } from '../../shell';
export const createFile: RequestHandler = async ({ files, body }, response) => {
stdout('Received shared file(s).');
pout('Received shared file(s).');
if (!files) return response.status(400).send();
stdoutVar({ body, files });
poutvar({ body, files });
for (const file of files) {
await anvilSyncShared('move_incoming', `file=${file.path}`, '0132', '0133');

@ -2,12 +2,12 @@ import assert from 'assert';
import { RequestHandler } from 'express';
import { anvilSyncShared, query, timestamp, write } from '../../accessModule';
import { stderr, stdoutVar } from '../../shell';
import { perr, poutvar } from '../../shell';
export const updateFile: RequestHandler = async (request, response) => {
const { body = {}, params } = request;
stdoutVar(body, 'Begin edit single file. body=');
poutvar(body, 'Begin edit single file. body=');
const { fileUUID } = params;
const { fileName, fileLocations, fileType } = body;
@ -20,7 +20,7 @@ export const updateFile: RequestHandler = async (request, response) => {
`SELECT file_name FROM files WHERE file_uuid = '${fileUUID}';`,
);
stdoutVar({ oldFileName, fileName });
poutvar({ oldFileName, fileName });
if (fileName !== oldFileName) {
sqlscript += `
@ -116,13 +116,13 @@ export const updateFile: RequestHandler = async (request, response) => {
assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (queryError) {
stderr(`Failed to execute query; CAUSE: ${queryError}`);
perr(`Failed to execute query; CAUSE: ${queryError}`);
return response.status(500).send();
}
anvilSyncSharedFunctions.forEach(async (fn, index) =>
stdoutVar(await fn(), `Anvil sync shared [${index}] output: `),
poutvar(await fn(), `Anvil sync shared [${index}] output: `),
);
response.status(200).send();

@ -2,7 +2,7 @@ import { buildKnownIDCondition } from '../../buildCondition';
import { buildQueryResultModifier } from '../../buildQueryResultModifier';
import { camel } from '../../camel';
import { getShortHostName } from '../../disassembleHostName';
import { stdout } from '../../shell';
import { pout } from '../../shell';
const CVAR_PREFIX = 'form::config_step';
const CVAR_PREFIX_PATTERN = `^${CVAR_PREFIX}\\d+::`;
@ -44,7 +44,7 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
} = {}) => {
const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'WHERE a.host_uuid');
stdout(`condHostUUIDs=[${condHostUUIDs}]`);
pout(`condHostUUIDs=[${condHostUUIDs}]`);
const query = `
SELECT

@ -14,7 +14,7 @@ import { getLocalHostUUID, job, variable } from '../../accessModule';
import { buildJobData } from '../../buildJobData';
import { buildNetworkConfig } from '../../fconfig';
import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell';
import { perr, poutvar } from '../../shell';
import { cvar } from '../../varn';
export const configStriker: RequestHandler<
@ -24,7 +24,7 @@ export const configStriker: RequestHandler<
> = async (request, response) => {
const { body = {} } = request;
stdoutVar(body, 'Begin initialize Striker; body=');
poutvar(body, 'Begin initialize Striker; body=');
const {
adminPassword: rAdminPassword,
@ -95,7 +95,7 @@ export const configStriker: RequestHandler<
`Data organization prefix can only contain 1 to 5 lowercase alphanumeric characters; got [${organizationPrefix}]`,
);
} catch (assertError) {
stderr(
perr(
`Failed to assert value when trying to initialize striker; CAUSE: ${assertError}.`,
);
@ -116,7 +116,7 @@ export const configStriker: RequestHandler<
...buildNetworkConfig(networks),
};
stdoutVar(configData, `Config data before initiating striker config: `);
poutvar(configData, `Config data before initiating striker config: `);
const configEntries = Object.entries(configData);
@ -155,7 +155,7 @@ export const configStriker: RequestHandler<
job_description: 'job_0071',
});
} catch (subError) {
stderr(`Failed to queue striker initialization; CAUSE: ${subError}`);
perr(`Failed to queue striker initialization; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -12,7 +12,7 @@ import {
} from '../../accessModule';
import { buildJobDataFromObject } from '../../buildJobData';
import { sanitize } from '../../sanitize';
import { rm, stderr, stdoutVar, systemCall, uuid } from '../../shell';
import { rm, perr, poutvar, systemCall, uuid } from '../../shell';
export const createHostConnection: RequestHandler<
unknown,
@ -46,15 +46,15 @@ export const createHostConnection: RequestHandler<
port: peerSSHPort,
}));
} catch (subError) {
stderr(`Failed to get peer data; CAUSE: ${subError}`);
perr(`Failed to get peer data; CAUSE: ${subError}`);
return response.status(500).send();
}
stdoutVar({ peerHostUUID, isPeerReachable });
poutvar({ peerHostUUID, isPeerReachable });
if (!isPeerReachable) {
stderr(
perr(
`Cannot connect to peer; please verify credentials and SSH keys validity.`,
);
@ -67,12 +67,12 @@ export const createHostConnection: RequestHandler<
pre: ['System'],
});
} catch (subError) {
stderr(`Failed to get matching IP address; CAUSE: ${subError}`);
perr(`Failed to get matching IP address; CAUSE: ${subError}`);
return response.status(500).send();
}
stdoutVar({ localIPAddress });
poutvar({ localIPAddress });
const pgpassFilePath = `/tmp/.pgpass-${uuid()}`;
const pgpassFileBody = `${peerIPAddress}:${commonDBPort}:${commonDBName}:${commonDBUser}:${commonPassword.replace(
@ -80,7 +80,7 @@ export const createHostConnection: RequestHandler<
'\\:',
)}`;
stdoutVar({ pgpassFilePath, pgpassFileBody });
poutvar({ pgpassFilePath, pgpassFileBody });
try {
writeFileSync(pgpassFilePath, pgpassFileBody, {
@ -88,7 +88,7 @@ export const createHostConnection: RequestHandler<
mode: 0o600,
});
} catch (subError) {
stderr(`Failed to write ${pgpassFilePath}; CAUSE: ${subError}`);
perr(`Failed to write ${pgpassFilePath}; CAUSE: ${subError}`);
return response.status(500).send();
}
@ -116,28 +116,28 @@ export const createHostConnection: RequestHandler<
{ env: { PGPASSFILE: pgpassFilePath } },
).trim();
stdoutVar(
poutvar(
{ timestamp, echo },
'Ask the peer database to echo the current timestamp: ',
);
isPeerDBReachable = echo === timestamp;
} catch (subError) {
stderr(`Failed to test connection to peer database; CAUSE: ${subError}`);
perr(`Failed to test connection to peer database; CAUSE: ${subError}`);
}
try {
rm(pgpassFilePath);
} catch (fsError) {
stderr(`Failed to remove ${pgpassFilePath}; CAUSE: ${fsError}`);
perr(`Failed to remove ${pgpassFilePath}; CAUSE: ${fsError}`);
return response.status(500).send();
}
stdoutVar({ isPeerDBReachable });
poutvar({ isPeerDBReachable });
if (!isPeerDBReachable) {
stderr(
perr(
`Cannot connect to peer database; please verify database credentials.`,
);
@ -153,7 +153,7 @@ export const createHostConnection: RequestHandler<
localDBPort = sanitize(rawLocalDBPort, 'number');
} catch (subError) {
stderr(`Failed to get local database data from hash; CAUSE: ${subError}`);
perr(`Failed to get local database data from hash; CAUSE: ${subError}`);
return response.status(500).send();
}
@ -176,7 +176,7 @@ export const createHostConnection: RequestHandler<
job_title: 'job_0011',
});
} catch (subError) {
stderr(`Failed to add peer ${peerHostUUID}; CAUSE: ${subError}`);
perr(`Failed to add peer ${peerHostUUID}; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -4,7 +4,7 @@ import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule';
import { toHostUUID } from '../../convertHostUUID';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const deleteHostConnection: RequestHandler<
unknown,
@ -38,7 +38,7 @@ export const deleteHostConnection: RequestHandler<
job_title: 'job_0013',
});
} catch (subError) {
stderr(`Failed to delete peer ${peerHostUuid}; CAUSE: ${subError}`);
perr(`Failed to delete peer ${peerHostUuid}; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -3,7 +3,7 @@ import { buildUnknownIDCondition } from '../../buildCondition';
import buildGetRequestHandler from '../buildGetRequestHandler';
import { toLocal } from '../../convertHostUUID';
import { match } from '../../match';
import { stdout } from '../../shell';
import { pout } from '../../shell';
const buildHostConnections = (
fromHostUUID: string,
@ -67,7 +67,7 @@ export const getHostConnection = buildGetRequestHandler(
const getConnectionKey = (hostUUID: string) =>
toLocal(hostUUID, localHostUUID);
stdout(`condHostUUIDs=[${condHostUUIDs}]`);
pout(`condHostUUIDs=[${condHostUUIDs}]`);
try {
rawDatabaseData = await getDatabaseConfigData();
@ -85,7 +85,7 @@ export const getHostConnection = buildGetRequestHandler(
return previous;
}, {});
stdout(`connections=[${JSON.stringify(connections, null, 2)}]`);
pout(`connections=[${JSON.stringify(connections, null, 2)}]`);
if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => {

@ -12,7 +12,7 @@ import {
import { job, variable } from '../../accessModule';
import { buildJobDataFromObject } from '../../buildJobData';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const prepareHost: RequestHandler<
unknown,
@ -103,7 +103,7 @@ export const prepareHost: RequestHandler<
);
}
} catch (assertError) {
stderr(
perr(
`Failed to assert value when trying to prepare host; CAUSE: ${assertError}`,
);
@ -142,7 +142,7 @@ export const prepareHost: RequestHandler<
job_title: `job_002${dataHostType === 'dr' ? '1' : '0'}`,
});
} catch (subError) {
stderr(`Failed to init host; CAUSE: ${subError}`);
perr(`Failed to init host; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -13,7 +13,7 @@ import { job, query, variable } from '../../accessModule';
import { buildJobData } from '../../buildJobData';
import { buildNetworkConfig } from '../../fconfig';
import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell';
import { perr, poutvar } from '../../shell';
import { cvar } from '../../varn';
export const prepareNetwork: RequestHandler<
@ -63,7 +63,7 @@ export const prepareNetwork: RequestHandler<
`Gateway interface must be a peaceful string; got [${gatewayInterface}]`,
);
} catch (error) {
stderr(`Failed to assert value when prepare network; CAUSE: ${error}`);
perr(`Failed to assert value when prepare network; CAUSE: ${error}`);
return response.status(400).send();
}
@ -79,7 +79,7 @@ export const prepareNetwork: RequestHandler<
[[hostType]] = rows;
} catch (error) {
stderr(`Failed to get host type with ${hostUUID}; CAUSE: ${error}`);
perr(`Failed to get host type with ${hostUUID}; CAUSE: ${error}`);
return response.status(500).send();
}
@ -105,7 +105,7 @@ export const prepareNetwork: RequestHandler<
...buildNetworkConfig(networks),
};
stdoutVar(
poutvar(
configData,
`Config data before prepare network on host ${hostUUID}: `,
);
@ -146,7 +146,7 @@ export const prepareNetwork: RequestHandler<
job_description: 'job_0071',
});
} catch (error) {
stderr(`Failed to queue prepare network; CAUSE: ${error}`);
perr(`Failed to queue prepare network; CAUSE: ${error}`);
return response.status(500).send();
}

@ -4,7 +4,7 @@ import { LOCAL } from '../../consts/LOCAL';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule';
import { stderr, stdoutVar } from '../../shell';
import { perr, poutvar } from '../../shell';
export const setHostInstallTarget: RequestHandler<
UpdateHostParams,
@ -13,7 +13,7 @@ export const setHostInstallTarget: RequestHandler<
> = async (request, response) => {
const { body, params } = request;
stdoutVar(body, `Begin set host install target; body=`);
poutvar(body, `Begin set host install target; body=`);
const { isEnableInstallTarget } = body;
const { hostUUID: rHostUuid } = params;
@ -32,7 +32,7 @@ export const setHostInstallTarget: RequestHandler<
job_title: 'job_0015',
});
} catch (subError) {
stderr(`Failed to ${task} install target; CAUSE: ${subError}`);
perr(`Failed to ${task} install target; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -2,7 +2,7 @@ import { REP_PEACEFUL_STRING } from '../../consts';
import buildGetRequestHandler from '../buildGetRequestHandler';
import { sanitize } from '../../sanitize';
import { date, stdout } from '../../shell';
import { date, pout } from '../../shell';
export const getJob = buildGetRequestHandler((request, buildQueryOptions) => {
const { start: rStart, command: rCommand } = request.query;
@ -28,7 +28,7 @@ export const getJob = buildGetRequestHandler((request, buildQueryOptions) => {
condJobCommand = `AND job.job_command LIKE '%${jcmd}%'`;
}
stdout(`condModifiedDate=[${condModifiedDate}]`);
pout(`condModifiedDate=[${condModifiedDate}]`);
if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => {

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { getMailRecipientRequestBody } from './getMailRecipientRequestBody';
import { stderr, stdout } from '../../shell';
import { perr, pout } from '../../shell';
export const createMailRecipient: RequestHandler<
undefined,
@ -11,14 +11,14 @@ export const createMailRecipient: RequestHandler<
> = (request, response) => {
const { body: rBody = {} } = request;
stdout('Begin creating mail recipient.');
pout('Begin creating mail recipient.');
let reqBody: MailRecipientRequestBody;
try {
reqBody = getMailRecipientRequestBody(rBody);
} catch (error) {
stderr(`Failed to process mail recipient input; CAUSE: ${error}`);
perr(`Failed to process mail recipient input; CAUSE: ${error}`);
return response.status(400).send();
}
@ -32,7 +32,7 @@ export const createMailRecipient: RequestHandler<
resBody = { uuid };
} catch (error) {
stderr(`Failed to create mail recipient; CAUSE: ${error}`);
perr(`Failed to create mail recipient; CAUSE: ${error}`);
return response.status(500).send();
}

@ -3,7 +3,7 @@ import { RequestHandler } from 'express';
import { query } from '../../accessModule';
import { execManageAlerts } from '../../execManageAlerts';
import { sanitize } from '../../sanitize';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const deleteMailRecipient: RequestHandler<
MailRecipientParamsDictionary
@ -26,7 +26,7 @@ export const deleteMailRecipient: RequestHandler<
execManageAlerts('alert-overrides', 'delete', { uuid: u }),
);
} catch (error) {
stderr(`Failed to delete related alert override records; CAUSE ${error}`);
perr(`Failed to delete related alert override records; CAUSE ${error}`);
return response.status(500).send();
}
@ -34,7 +34,7 @@ export const deleteMailRecipient: RequestHandler<
try {
execManageAlerts('recipients', 'delete', { uuid });
} catch (error) {
stderr(`Failed to delete alert recipient; CAUSE: ${error}`);
perr(`Failed to delete alert recipient; CAUSE: ${error}`);
return response.status(500).send();
}

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { getMailRecipientRequestBody } from './getMailRecipientRequestBody';
import { stderr, stdout } from '../../shell';
import { perr, pout } from '../../shell';
export const updateMailRecipient: RequestHandler<
MailRecipientParamsDictionary,
@ -14,14 +14,14 @@ export const updateMailRecipient: RequestHandler<
params: { uuid },
} = request;
stdout('Begin updating mail recipient.');
pout('Begin updating mail recipient.');
let body: MailRecipientRequestBody;
try {
body = getMailRecipientRequestBody(rBody, uuid);
} catch (error) {
stderr(`Failed to process mail recipient input; CAUSE: ${error}`);
perr(`Failed to process mail recipient input; CAUSE: ${error}`);
return response.status(400).send();
}
@ -29,7 +29,7 @@ export const updateMailRecipient: RequestHandler<
try {
execManageAlerts('recipients', 'edit', { body, uuid });
} catch (error) {
stderr(`Failed to update mail recipient; CAUSE: ${error}`);
perr(`Failed to update mail recipient; CAUSE: ${error}`);
return response.status(500).send();
}

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { getMailServerRequestBody } from './getMailServerRequestBody';
import { stderr, stdout } from '../../shell';
import { perr, pout } from '../../shell';
export const createMailServer: RequestHandler<
undefined,
@ -11,14 +11,14 @@ export const createMailServer: RequestHandler<
> = (request, response) => {
const { body: rBody = {} } = request;
stdout('Begin creating mail server.');
pout('Begin creating mail server.');
let body: MailServerRequestBody;
try {
body = getMailServerRequestBody(rBody);
} catch (error) {
stderr(`Failed to process mail server input; CAUSE: ${error}`);
perr(`Failed to process mail server input; CAUSE: ${error}`);
return response.status(400).send();
}
@ -26,7 +26,7 @@ export const createMailServer: RequestHandler<
try {
execManageAlerts('mail-servers', 'add', { body });
} catch (error) {
stderr(`Failed to create mail server; CAUSE: ${error}`);
perr(`Failed to create mail server; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,7 +1,7 @@
import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const deleteMailServer: RequestHandler<MailServerParamsDictionary> = (
request,
@ -14,7 +14,7 @@ export const deleteMailServer: RequestHandler<MailServerParamsDictionary> = (
try {
execManageAlerts('mail-servers', 'delete', { uuid });
} catch (error) {
stderr(`Failed to delete mail server; CAUSE: ${error}`);
perr(`Failed to delete mail server; CAUSE: ${error}`);
return response.status(500).send();
}

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { execManageAlerts } from '../../execManageAlerts';
import { getMailServerRequestBody } from './getMailServerRequestBody';
import { stderr, stdout } from '../../shell';
import { perr, pout } from '../../shell';
export const updateMailServer: RequestHandler<
MailServerParamsDictionary,
@ -14,14 +14,14 @@ export const updateMailServer: RequestHandler<
params: { uuid },
} = request;
stdout('Begin updating mail server.');
pout('Begin updating mail server.');
let body: MailServerRequestBody;
try {
body = getMailServerRequestBody(rBody, uuid);
} catch (error) {
stderr(`Failed to process mail server input; CAUSE: ${error}`);
perr(`Failed to process mail server input; CAUSE: ${error}`);
return response.status(400).send();
}
@ -29,7 +29,7 @@ export const updateMailServer: RequestHandler<
try {
execManageAlerts('mail-servers', 'edit', { body, uuid });
} catch (error) {
stderr(`Failed to update mail server; CAUSE: ${error}`);
perr(`Failed to update mail server; CAUSE: ${error}`);
return response.status(500).send();
}

@ -10,7 +10,7 @@ import {
import { sub } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stdout } from '../../shell';
import { pout } from '../../shell';
export const buildManifest = async (
...[request]: Parameters<
@ -37,7 +37,7 @@ export const buildManifest = async (
params: { manifestUuid: rawManifestUuid = 'new' },
} = request;
stdout('Begin building install manifest.');
pout('Begin building install manifest.');
const dns = sanitize(rawDns, 'string');
const domain = sanitize(rawDomain, 'string');

@ -2,7 +2,7 @@ import { AssertionError } from 'assert';
import { RequestHandler } from 'express';
import { buildManifest } from './buildManifest';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const createManifest: RequestHandler = async (...handlerArgs) => {
const [, response] = handlerArgs;
@ -12,7 +12,7 @@ export const createManifest: RequestHandler = async (...handlerArgs) => {
try {
result = await buildManifest(...handlerArgs);
} catch (error) {
stderr(`Failed to create new install manifest; CAUSE ${error}`);
perr(`Failed to create new install manifest; CAUSE ${error}`);
let code = 500;

@ -1,7 +1,7 @@
import { RequestHandler } from 'express';
import { sub } from '../../accessModule';
import { stderr, stdout } from '../../shell';
import { perr, pout } from '../../shell';
export const deleteManifest: RequestHandler<
{ manifestUuid: string },
@ -18,14 +18,14 @@ export const deleteManifest: RequestHandler<
: [rawManifestUuid];
for (const uuid of manifestUuidList) {
stdout(`Begin delete manifest ${uuid}.`);
pout(`Begin delete manifest ${uuid}.`);
try {
await sub('insert_or_update_manifests', {
params: [{ delete: 1, manifest_uuid: uuid }],
});
} catch (subError) {
stderr(`Failed to delete manifest ${uuid}; CAUSE: ${subError}`);
perr(`Failed to delete manifest ${uuid}; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { getManifestData } from '../../accessModule';
import { getEntityParts } from '../../disassembleEntityId';
import { stderr, stdout } from '../../shell';
import { perr, pout } from '../../shell';
const handleSortEntries = <T extends [string, unknown]>(
[aId]: T,
@ -77,16 +77,14 @@ export const getManifestDetail: RequestHandler = async (request, response) => {
try {
rawManifestListData = await getManifestData(manifestUuid);
} catch (subError) {
stderr(
`Failed to get install manifest ${manifestUuid}; CAUSE: ${subError}`,
);
perr(`Failed to get install manifest ${manifestUuid}; CAUSE: ${subError}`);
response.status(500).send();
return;
}
stdout(
pout(
`Raw install manifest list:\n${JSON.stringify(
rawManifestListData,
null,
@ -139,7 +137,7 @@ export const getManifestDetail: RequestHandler = async (request, response) => {
const { name: hostType, number: hostNumber } =
getEntityParts(hostId);
stdout(`host=${hostType},n=${hostNumber}`);
pout(`host=${hostType},n=${hostNumber}`);
// Only include node-type host(s).
if (hostType !== 'node') {
@ -178,7 +176,7 @@ export const getManifestDetail: RequestHandler = async (request, response) => {
const { name: networkType, number: networkNumber } =
getEntityParts(networkId);
stdout(`hostnetwork=${networkType},n=${networkNumber}`);
pout(`hostnetwork=${networkType},n=${networkNumber}`);
hostNetworks[networkId] = {
networkIp,
@ -235,7 +233,7 @@ export const getManifestDetail: RequestHandler = async (request, response) => {
const { name: networkType, number: networkNumber } =
getEntityParts(networkId);
stdout(`network=${networkType},n=${networkNumber}`);
pout(`network=${networkType},n=${networkNumber}`);
networks[networkId] = {
networkGateway,

@ -8,7 +8,7 @@ import {
getHostNamePrefix,
getShortHostName,
} from '../../disassembleHostName';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const getManifestTemplate: RequestHandler = async (
request,
@ -19,7 +19,7 @@ export const getManifestTemplate: RequestHandler = async (
try {
localHostName = getLocalHostName();
} catch (subError) {
stderr(String(subError));
perr(String(subError));
return response.status(500).send();
}
@ -79,7 +79,7 @@ export const getManifestTemplate: RequestHandler = async (
) AS c ON a.row_number = c.row_number;`,
);
} catch (queryError) {
stderr(`Failed to execute query; CAUSE: ${queryError}`);
perr(`Failed to execute query; CAUSE: ${queryError}`);
return response.status(500).send();
}

@ -2,7 +2,7 @@ import { AssertionError } from 'assert';
import { RequestHandler } from 'express';
import { buildManifest } from './buildManifest';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const updateManifest: RequestHandler = async (...args) => {
const [request, response] = args;
@ -15,9 +15,7 @@ export const updateManifest: RequestHandler = async (...args) => {
try {
result = await buildManifest(...args);
} catch (error) {
stderr(
`Failed to update install manifest ${manifestUuid}; CAUSE: ${error}`,
);
perr(`Failed to update install manifest ${manifestUuid}; CAUSE: ${error}`);
let code = 500;

@ -7,12 +7,12 @@ import { OS_LIST_MAP } from '../../consts/OS_LIST';
import { job, query } from '../../accessModule';
import { buildJobDataFromObject } from '../../buildJobData';
import { sanitize } from '../../sanitize';
import { stderr, stdout, stdoutVar } from '../../shell';
import { perr, pout, poutvar } from '../../shell';
export const createServer: RequestHandler = async (request, response) => {
const { body = {} } = request;
stdoutVar(body, 'Creating server; body=');
poutvar(body, 'Creating server; body=');
const {
serverName: rServerName,
@ -101,7 +101,7 @@ export const createServer: RequestHandler = async (request, response) => {
`Data anvil UUID must be a valid UUID; got [${anvilUuid}]`,
);
} catch (assertError) {
stdout(
pout(
`Failed to assert value when trying to provision a server; CAUSE: ${assertError}`,
);
@ -141,7 +141,7 @@ export const createServer: RequestHandler = async (request, response) => {
ON pri_hos.phl = nod_1.phr;`,
);
stdout(`provisionServerJobHostUuid=[${provisionServerJobHostUuid}]`);
pout(`provisionServerJobHostUuid=[${provisionServerJobHostUuid}]`);
try {
await job({
@ -165,7 +165,7 @@ export const createServer: RequestHandler = async (request, response) => {
job_host_uuid: provisionServerJobHostUuid,
});
} catch (subError) {
stderr(`Failed to provision server; CAUSE: ${subError}`);
perr(`Failed to provision server; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -5,7 +5,7 @@ import { DELETED, REP_UUID, SERVER_PATHS } from '../../consts';
import { job, query } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell';
import { perr, poutvar } from '../../shell';
export const deleteServer: RequestHandler<
{ serverUuid?: string },
@ -29,7 +29,7 @@ export const deleteServer: RequestHandler<
);
}
stdoutVar(serverUuids, `Delete servers with: `);
poutvar(serverUuids, `Delete servers with: `);
for (const serverUuid of serverUuids) {
try {
@ -60,7 +60,7 @@ export const deleteServer: RequestHandler<
job_title: 'job_0208',
});
} catch (error) {
stderr(`Failed to initiate delete server ${serverUuid}; CAUSE: ${error}`);
perr(`Failed to initiate delete server ${serverUuid}; CAUSE: ${error}`);
return response.status(500).send();
}

@ -4,7 +4,7 @@ import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import join from '../../join';
import { sanitize } from '../../sanitize';
import { stdoutVar } from '../../shell';
import { poutvar } from '../../shell';
export const getServer = buildGetRequestHandler(
(request, buildQueryOptions) => {
@ -17,7 +17,7 @@ export const getServer = buildGetRequestHandler(
separator: ', ',
});
stdoutVar({ condAnvilUUIDs });
poutvar({ condAnvilUUIDs });
if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = buildQueryResultReducer<

@ -7,7 +7,7 @@ import { P_UUID, REP_UUID, SERVER_PATHS } from '../../consts';
import { getVncinfo } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr, stdout, stdoutVar } from '../../shell';
import { perr, pout, poutvar } from '../../shell';
type ServerSsMeta = {
name: string;
@ -41,7 +41,7 @@ export const getServerDetail: RequestHandler<
const ss = sanitize(rSs, 'boolean');
const vnc = sanitize(rVnc, 'boolean');
stdout(`serverUUID=[${serverUuid}],isScreenshot=[${ss}]`);
pout(`serverUUID=[${serverUuid}],isScreenshot=[${ss}]`);
try {
assert(
@ -49,7 +49,7 @@ export const getServerDetail: RequestHandler<
`Server UUID must be a valid UUID; got [${serverUuid}]`,
);
} catch (assertError) {
stderr(
perr(
`Failed to assert value when trying to get server detail; CAUSE: ${assertError}.`,
);
@ -67,9 +67,7 @@ export const getServerDetail: RequestHandler<
encoding: 'utf-8',
});
} catch (error) {
stderr(
`Failed to list server ${serverUuid} screenshots; CAUSE: ${error}`,
);
perr(`Failed to list server ${serverUuid} screenshots; CAUSE: ${error}`);
return response.status(500).send();
}
@ -92,7 +90,7 @@ export const getServerDetail: RequestHandler<
const ssMetaLatest = ssMetas.pop();
stdoutVar(ssMetaLatest, `Latest server screenshot: `);
poutvar(ssMetaLatest, `Latest server screenshot: `);
if (ssMetaLatest) {
const { name, timestamp } = ssMetaLatest;
@ -112,7 +110,7 @@ export const getServerDetail: RequestHandler<
try {
rsbody = await getVncinfo(serverUuid);
} catch (error) {
stderr(`Failed to get server ${serverUuid} VNC info; CAUSE: ${error}`);
perr(`Failed to get server ${serverUuid} VNC info; CAUSE: ${error}`);
return response.status(500).send();
}

@ -4,7 +4,7 @@ import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule';
import { toHostUUID } from '../../convertHostUUID';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const deleteSSHKeyConflict: RequestHandler<
unknown,
@ -29,7 +29,7 @@ export const deleteSSHKeyConflict: RequestHandler<
job_title: 'job_0056',
});
} catch (subError) {
stderr(`Failed to delete bad SSH keys; CAUSE: ${subError}`);
perr(`Failed to delete bad SSH keys; CAUSE: ${subError}`);
return response.status(500).send();
}

@ -5,7 +5,7 @@ import { REP_IPV4, REP_PEACEFUL_STRING, REP_UUID } from '../../consts';
import { timestamp, write } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr, uuid } from '../../shell';
import { perr, uuid } from '../../shell';
export const createUps: RequestHandler<
{ uuid?: string },
@ -43,7 +43,7 @@ export const createUps: RequestHandler<
`UPS UUID must be a valid UUIDv4; got [${upsUuid}]`,
);
} catch (error) {
stderr(`Assert value failed when working with UPS; CAUSE: ${error}`);
perr(`Assert value failed when working with UPS; CAUSE: ${error}`);
return response.status(400).send();
}
@ -75,7 +75,7 @@ export const createUps: RequestHandler<
assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (error) {
stderr(`Failed to write UPS record; CAUSE: ${error}`);
perr(`Failed to write UPS record; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,7 +1,7 @@
import { RequestHandler } from 'express';
import { getUpsSpec } from '../../accessModule';
import { stderr } from '../../shell';
import { perr } from '../../shell';
export const getUPSTemplate: RequestHandler = async (request, response) => {
let rawUPSData: AnvilDataUPSHash;
@ -9,7 +9,7 @@ export const getUPSTemplate: RequestHandler = async (request, response) => {
try {
rawUPSData = await getUpsSpec();
} catch (subError) {
stderr(`Failed to get ups template; CAUSE: ${subError}`);
perr(`Failed to get ups template; CAUSE: ${subError}`);
response.status(500).send();

@ -5,7 +5,7 @@ import { DELETED, REP_PEACEFUL_STRING, REP_UUID } from '../../consts';
import { insertOrUpdateUser, query } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { openssl, stderr, stdoutVar } from '../../shell';
import { openssl, perr, poutvar } from '../../shell';
export const createUser: RequestHandler<
unknown,
@ -24,7 +24,7 @@ export const createUser: RequestHandler<
});
const userName = sanitize(rUserName, 'string', { modifierType: 'sql' });
stdoutVar({ password, userName }, 'Create user with params: ');
poutvar({ password, userName }, 'Create user with params: ');
try {
assert(
@ -45,7 +45,7 @@ export const createUser: RequestHandler<
assert(userCount === 0, `User name [${userName}] already used`);
} catch (error) {
stderr(`Failed to assert value when creating user; CAUSE: ${error}`);
perr(`Failed to assert value when creating user; CAUSE: ${error}`);
return response.status(400).send();
}
@ -62,7 +62,7 @@ export const createUser: RequestHandler<
`Insert or update failed with result [${result}]`,
);
} catch (error) {
stderr(`Failed to record user to database; CAUSE: ${error}`);
perr(`Failed to record user to database; CAUSE: ${error}`);
return response.status(500).send();
}

@ -6,7 +6,7 @@ import { DELETED, REP_UUID } from '../../consts';
import { write } from '../../accessModule';
import join from '../../join';
import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell';
import { perr, poutvar } from '../../shell';
export const deleteUser: RequestHandler<
UserParamsDictionary,
@ -25,7 +25,7 @@ export const deleteUser: RequestHandler<
const ulist = userUuidList.length > 0 ? userUuidList : [userUuid];
stdoutVar({ ulist });
poutvar({ ulist });
try {
let failedIndex = 0;
@ -39,7 +39,7 @@ export const deleteUser: RequestHandler<
`All UUIDs must be valid UUIDv4; failed at ${failedIndex}, got [${ulist[failedIndex]}]`,
);
} catch (assertError) {
stderr(`Failed to assert value during delete user; CAUSE: ${assertError}`);
perr(`Failed to assert value during delete user; CAUSE: ${assertError}`);
return response.status(400).send();
}
@ -56,7 +56,7 @@ export const deleteUser: RequestHandler<
assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (error) {
stderr(`Failed to delete user(s); CAUSE: ${error}`);
perr(`Failed to delete user(s); CAUSE: ${error}`);
return response.status(500).send();
}

@ -5,7 +5,7 @@ import { REP_PEACEFUL_STRING, REP_UUID } from '../../consts';
import { encrypt, query, write } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell';
import { perr, poutvar } from '../../shell';
export const updateUser: RequestHandler<
UserParamsDictionary,
@ -24,7 +24,7 @@ export const updateUser: RequestHandler<
const password = sanitize(rPassword, 'string');
const userName = sanitize(rUserName, 'string', { modifierType: 'sql' });
stdoutVar({ password, userName }, `Update user ${userUuid} with params: `);
poutvar({ password, userName }, `Update user ${userUuid} with params: `);
try {
if (password.length) {
@ -52,7 +52,7 @@ export const updateUser: RequestHandler<
assert(existingUserName !== 'admin' || userName, 'Cannot ');
} catch (error) {
stderr(`Assert failed when update user; CAUSE: ${error}`);
perr(`Assert failed when update user; CAUSE: ${error}`);
return response.status(400).send();
}
@ -81,7 +81,7 @@ export const updateUser: RequestHandler<
LIMIT 1;`,
);
} catch (error) {
stderr(`Failed to find existing user ${userUuid}; CAUSE: ${error}`);
perr(`Failed to find existing user ${userUuid}; CAUSE: ${error}`);
return response.status(500).send();
}
@ -106,7 +106,7 @@ export const updateUser: RequestHandler<
salt: xSalt,
}));
} catch (error) {
stderr(`Encrypt failed when update user; CAUSE ${error}`);
perr(`Encrypt failed when update user; CAUSE ${error}`);
return response.status(500).send();
}
@ -130,7 +130,7 @@ export const updateUser: RequestHandler<
assert(wcode === 0, `Update users failed with code: ${wcode}`);
} catch (error) {
stderr(`Failed to record user changes to database; CAUSE: ${error}`);
perr(`Failed to record user changes to database; CAUSE: ${error}`);
return response.status(500).send();
}

@ -1,7 +1,7 @@
import { Application, Handler, Router } from 'express';
import path from 'path';
import { stdout } from './shell';
import { pout } from './shell';
export const rrouters = <
A extends Application,
@ -25,7 +25,7 @@ export const rrouters = <
const handlers = assign(union as R);
const { length: hcount } = handlers;
stdout(`Set up route ${route} with ${hcount} handler(s)`);
pout(`Set up route ${route} with ${hcount} handler(s)`);
app.use(route, ...handlers);
} else if (key) {

@ -54,7 +54,7 @@ export const resolveGid = (id: number | string) => resolveId(id, 'group');
export const resolveUid = (id: number | string) => resolveId(id, 'passwd');
export const stderr = (message: string, error?: unknown) => {
export const perr = (message: string, error?: unknown) => {
let msg = message;
if (error instanceof Error) {
@ -64,9 +64,9 @@ export const stderr = (message: string, error?: unknown) => {
print(msg, { stream: 'stderr' });
};
export const stdout = (message: string) => print(message);
export const pout = (message: string) => print(message);
export const stdoutVar = (variable: unknown, label = 'Variables: ') =>
export const poutvar = (variable: unknown, label = 'Variables: ') =>
print(`${label}${JSON.stringify(variable, null, 2)}`);
export const uuid = () => uuidgen('--random').trim();

@ -1,6 +1,6 @@
import { Handler } from 'express';
import { stdout } from '../lib/shell';
import { pout } from '../lib/shell';
type HandlerParameters = Parameters<Handler>;
@ -54,10 +54,10 @@ export const assertAuthentication: AssertAuthenticationFunction = ({
const rt = getReturnTo?.call(null, ...args);
stdout(`Unauthenticated access to ${originalUrl}`);
pout(`Unauthenticated access to ${originalUrl}`);
if (rt) {
stdout(`Set session.returnTo=${rt}`);
pout(`Set session.returnTo=${rt}`);
session.returnTo = rt;
}

@ -4,7 +4,7 @@ import { LOCAL } from '../lib/consts';
import { query } from '../lib/accessModule';
import { toHostUUID } from '../lib/convertHostUUID';
import { stderr, stdoutVar } from '../lib/shell';
import { perr, poutvar } from '../lib/shell';
export const assertInit =
({
@ -34,19 +34,19 @@ export const assertInit =
LIMIT 1;`,
);
} catch (error) {
stderr(`Failed to get system configured flag; CAUSE: ${error}`);
perr(`Failed to get system configured flag; CAUSE: ${error}`);
return response.status(500).send();
}
stdoutVar(rows, `Configured variable of host ${hostUuid}: `);
poutvar(rows, `Configured variable of host ${hostUuid}: `);
let condition = rows.length === 1 && rows[0][0] === '1';
if (invert) condition = !condition;
if (condition) {
stderr(`Assert init failed; invert=${invert}`);
perr(`Assert init failed; invert=${invert}`);
return fail(...args);
}

@ -5,19 +5,19 @@ import path from 'path';
import SERVER_PATHS from '../lib/consts/SERVER_PATHS';
import { stdout, stdoutVar } from '../lib/shell';
import { pout, poutvar } from '../lib/shell';
const file =
({ dir }: { dir: string }): RequestHandler =>
(request, response, next) => {
stdout(`Begin receiving file(s)`);
pout(`Begin receiving file(s)`);
const { headers } = request;
const bb = busboy({ headers });
const files: FileInfoAppend[] = [];
bb.on('file', (name, file, info) => {
stdout(`On busboy file event`);
pout(`On busboy file event`);
const { filename } = info;
const fInfoAppend: FileInfoAppend = {
@ -25,14 +25,14 @@ const file =
path: path.join(dir, filename),
};
stdoutVar({ fInfoAppend }, 'Received file: ');
poutvar({ fInfoAppend }, 'Received file: ');
file.pipe(fs.createWriteStream(fInfoAppend.path));
files.push(fInfoAppend);
});
bb.on('close', () => {
stdoutVar(files, `On busboy close event; files=`);
poutvar(files, `On busboy close event; files=`);
request.files = files;

@ -5,12 +5,12 @@ import { DELETED } from '../lib/consts';
import { encrypt, query } from '../lib/accessModule';
import { sanitize } from '../lib/sanitize';
import { stdout } from '../lib/shell';
import { pout } from '../lib/shell';
passport.use(
'login',
new LocalStrategy(async (username, password, done) => {
stdout(`Attempting passport local strategy "login" for user [${username}]`);
pout(`Attempting passport local strategy "login" for user [${username}]`);
let rows: [
userUuid: string,
@ -79,7 +79,7 @@ passport.use(
passport.serializeUser((user, done) => {
const { name, uuid } = user;
stdout(`Serialize user [${name}]`);
pout(`Serialize user [${name}]`);
return done(null, uuid);
});
@ -87,7 +87,7 @@ passport.serializeUser((user, done) => {
passport.deserializeUser(async (id, done) => {
const uuid = sanitize(id, 'string', { modifierType: 'sql' });
stdout(`Deserialize user identified by ${uuid}`);
pout(`Deserialize user identified by ${uuid}`);
let rows: [userName: string][];

@ -2,7 +2,7 @@ import { createProxyMiddleware } from 'http-proxy-middleware';
import { P_UUID } from '../lib/consts';
import { stderr, stdout } from '../lib/shell';
import { perr, pout } from '../lib/shell';
import { getVncinfo } from '../lib/accessModule';
const WS_SVR_VNC_URL_PREFIX = '/ws/server/vnc';
@ -18,7 +18,7 @@ export const proxyServerVnc = createProxyMiddleware({
'$1',
);
stdout(`Got param [${serverUuid}] from [${url}]`);
pout(`Got param [${serverUuid}] from [${url}]`);
let domain: string;
let port: number;
@ -27,7 +27,7 @@ export const proxyServerVnc = createProxyMiddleware({
try {
({ domain, port, protocol } = await getVncinfo(serverUuid));
} catch (error) {
stderr(`Failed to get server ${serverUuid} VNC info; CAUSE: ${error}`);
perr(`Failed to get server ${serverUuid} VNC info; CAUSE: ${error}`);
return;
}
@ -36,7 +36,7 @@ export const proxyServerVnc = createProxyMiddleware({
},
on: {
error: (error, request, response) => {
stderr(`VNC proxy error: ${error}`);
perr(`VNC proxy error: ${error}`);
let resType: string;
@ -48,7 +48,7 @@ export const proxyServerVnc = createProxyMiddleware({
resType = 'Socket';
}
stdout(`Response type = ${resType}`);
pout(`Response type = ${resType}`);
},
},
ws: true,
@ -57,5 +57,5 @@ export const proxyServerVnc = createProxyMiddleware({
export const proxyServerVncUpgrade =
proxyServerVnc.upgrade ??
(() => {
stdout('No upgrade handler for server VNC connection(s).');
pout('No upgrade handler for server VNC connection(s).');
});

@ -9,7 +9,7 @@ import { COOKIE_ORIGINAL_MAX_AGE, DELETED } from '../lib/consts';
import { getLocalHostUUID, query, timestamp, write } from '../lib/accessModule';
import { cname } from '../lib/cname';
import { getSessionSecret } from '../lib/getSessionSecret';
import { stderr, stdout, stdoutVar, uuid } from '../lib/shell';
import { perr, pout, poutvar, uuid } from '../lib/shell';
export class SessionStore extends BaseSessionStore {
constructor(options = {}) {
@ -20,7 +20,7 @@ export class SessionStore extends BaseSessionStore {
sid: string,
done?: ((err?: unknown) => void) | undefined,
): Promise<void> {
stdout(`Destroy session ${sid}`);
pout(`Destroy session ${sid}`);
try {
const wcode = await write(
@ -31,7 +31,7 @@ export class SessionStore extends BaseSessionStore {
assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (error) {
stderr(
perr(
`Failed to complete DB write in destroy session ${sid}; CAUSE: ${error}`,
);
@ -45,7 +45,7 @@ export class SessionStore extends BaseSessionStore {
sid: string,
done: (err: unknown, session?: SessionData | null | undefined) => void,
): Promise<void> {
stdout(`Get session ${sid}`);
pout(`Get session ${sid}`);
let rows: [
sessionUuid: string,
@ -96,7 +96,7 @@ export class SessionStore extends BaseSessionStore {
session: SessionData,
done?: ((err?: unknown) => void) | undefined,
): Promise<void> {
stdoutVar({ session }, `Set session ${sid}: `);
poutvar({ session }, `Set session ${sid}: `);
const { passport: { user: userUuid } = {} } = session;
@ -129,7 +129,7 @@ export class SessionStore extends BaseSessionStore {
assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (error) {
stderr(
perr(
`Failed to complete DB write in set session ${sid}; CAUSE: ${error}`,
);
@ -144,7 +144,7 @@ export class SessionStore extends BaseSessionStore {
session: SessionData,
done?: ((err?: unknown) => void) | undefined,
): Promise<void> {
stdoutVar({ session }, `Touch session ${sid}: `);
poutvar({ session }, `Touch session ${sid}: `);
// The intent of updating the session modified date is to avoid expiring the
// session when it's actively used by the user. But since the updates are
@ -159,7 +159,7 @@ export class SessionStore extends BaseSessionStore {
// assert(wcode === 0, `Write exited with code ${wcode}`);
// } catch (error) {
// stderr(
// perr(
// `Failed to complete DB write in touch session ${sid}; CAUSE: ${error}`,
// );
@ -177,7 +177,7 @@ export class SessionStore extends BaseSessionStore {
const sessionDeadlineEpoch = sessionModifiedEpoch + cookieOriginalMaxAge;
const cookieMaxAge = sessionDeadlineEpoch - Date.now();
stdoutVar({ sessionModifiedDate, sessionDeadlineEpoch, cookieMaxAge });
poutvar({ sessionModifiedDate, sessionDeadlineEpoch, cookieMaxAge });
return cookieMaxAge;
}
@ -193,7 +193,7 @@ export default (async () =>
genid: ({ originalUrl }) => {
const sid = uuid();
stdout(`Generated session identifier ${sid}; access to ${originalUrl}`);
pout(`Generated session identifier ${sid}; access to ${originalUrl}`);
return sid;
},

@ -1,6 +1,6 @@
import express from 'express';
import { stdoutVar } from '../lib/shell';
import { poutvar } from '../lib/shell';
const router = express.Router();
@ -11,7 +11,7 @@ router
.post('/', (request, response) => {
const { body = {} } = request;
stdoutVar(body, 'echo:post\n');
poutvar(body, 'echo:post\n');
const { message = 'No message.' } = body;

@ -4,7 +4,7 @@ import { existsSync } from 'fs';
import { SERVER_PATHS } from '../lib/consts';
import { assertAuthentication, assertInit } from '../middlewares';
import { stdout } from '../lib/shell';
import { pout } from '../lib/shell';
const router = express.Router();
@ -36,7 +36,7 @@ router.use((...args) => {
const fpath = `${htmlDir}${exted}`;
const htmlExists = existsSync(fpath);
stdout(`static:[${path}] requested; html=${htmlExists}`);
pout(`static:[${path}] requested; html=${htmlExists}`);
// Request for asset, i.e., image, script.
if (!htmlExists) return next();

Loading…
Cancel
Save