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

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

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

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

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

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

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

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

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

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

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

@ -1,7 +1,7 @@
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { getAnvilData, getHostData } from '../../accessModule'; import { getAnvilData, getHostData } from '../../accessModule';
import { stderr } from '../../shell'; import { perr } from '../../shell';
import { buildAnvilSummary } from './buildAnvilSummary'; import { buildAnvilSummary } from './buildAnvilSummary';
export const getAnvilDetail: RequestHandler< export const getAnvilDetail: RequestHandler<
@ -20,7 +20,7 @@ export const getAnvilDetail: RequestHandler<
anvils = await getAnvilData(); anvils = await getAnvilData();
hosts = await getHostData(); hosts = await getHostData();
} catch (error) { } 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(); return response.status(500).send();
} }
@ -34,7 +34,7 @@ export const getAnvilDetail: RequestHandler<
hosts, hosts,
}); });
} catch (error) { } 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(); 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 { DELETED, NODE_AND_DR_RESERVED_MEMORY_SIZE } from '../../consts';
import { query } from '../../accessModule'; import { query } from '../../accessModule';
import { stderr } from '../../shell'; import { perr } from '../../shell';
export const getAnvilMemory: RequestHandler< export const getAnvilMemory: RequestHandler<
AnvilDetailParamsDictionary AnvilDetailParamsDictionary
@ -50,7 +50,7 @@ export const getAnvilMemory: RequestHandler<
ORDER BY b.host_name;`, ORDER BY b.host_name;`,
); );
} catch (error) { } 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(); return response.status(500).send();
} }
@ -92,7 +92,7 @@ export const getAnvilMemory: RequestHandler<
AND b.server_anvil_uuid = '${anvilUuid}';`, AND b.server_anvil_uuid = '${anvilUuid}';`,
); );
} catch (error) { } 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(); return response.status(500).send();
} }

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

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

@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { getAnvilData, getHostData } from '../../accessModule'; import { getAnvilData, getHostData } from '../../accessModule';
import { buildAnvilSummary } from './buildAnvilSummary'; import { buildAnvilSummary } from './buildAnvilSummary';
import { stderr } from '../../shell'; import { perr } from '../../shell';
export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async ( export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async (
request, request,
@ -15,7 +15,7 @@ export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async (
anvils = await getAnvilData(); anvils = await getAnvilData();
hosts = await getHostData(); hosts = await getHostData();
} catch (error) { } 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(); return response.status(500).send();
} }
@ -30,7 +30,7 @@ export const getAnvilSummary: RequestHandler<unknown, AnvilSummary> = async (
); );
} }
} catch (error) { } 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(); return response.status(500).send();
} }

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

@ -1,12 +1,12 @@
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { cname } from '../../cname'; import { cname } from '../../cname';
import { stdout } from '../../shell'; import { pout } from '../../shell';
export const logout: RequestHandler = (request, response) => { export const logout: RequestHandler = (request, response) => {
request.session.destroy((error) => { request.session.destroy((error) => {
if (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(); return response.status(500).send();
} }

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

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

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

@ -5,7 +5,7 @@ import { REP_UUID, SERVER_PATHS } from '../../consts';
import { job, query } from '../../accessModule'; import { job, query } from '../../accessModule';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stderr } from '../../shell'; import { perr } from '../../shell';
const MAP_TO_MEMBERSHIP_JOB_PARAMS_BUILDER: Record< const MAP_TO_MEMBERSHIP_JOB_PARAMS_BUILDER: Record<
MembershipTask, MembershipTask,
@ -66,7 +66,7 @@ export const buildMembershipHandler: (
`Param UUID must be a valid UUIDv4; got: [${hostUuid}]`, `Param UUID must be a valid UUIDv4; got: [${hostUuid}]`,
); );
} catch (error) { } catch (error) {
stderr( perr(
`Failed to assert value when changing host membership; CAUSE: ${error}`, `Failed to assert value when changing host membership; CAUSE: ${error}`,
); );
@ -93,7 +93,7 @@ export const buildMembershipHandler: (
assert.ok(rows.length, `No entry found`); assert.ok(rows.length, `No entry found`);
} catch (error) { } 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(); return response.status(500).send();
} }
@ -112,7 +112,7 @@ export const buildMembershipHandler: (
await job({ file: __filename, ...restParams }); await job({ file: __filename, ...restParams });
} }
} catch (error) { } catch (error) {
stderr( perr(
`Failed to initiate ${task} cluster for host ${hostUuid}; CAUSE: ${error}`, `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 { job, query } from '../../accessModule';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stderr } from '../../shell'; import { perr } from '../../shell';
/** /**
* Notes on power functions: * Notes on power functions:
@ -103,7 +103,7 @@ export const buildPowerHandler: (
); );
} }
} catch (error) { } catch (error) {
stderr(`Failed to ${task}; CAUSE: ${error}`); perr(`Failed to ${task}; CAUSE: ${error}`);
return response.status(400).send(); return response.status(400).send();
} }
@ -113,7 +113,7 @@ export const buildPowerHandler: (
await queuePowerJob(task, { force, runOn, uuid }); await queuePowerJob(task, { force, runOn, uuid });
} catch (error) { } catch (error) {
stderr(`Failed to ${task} ${uuid ?? LOCAL}; CAUSE: ${error}`); perr(`Failed to ${task} ${uuid ?? LOCAL}; CAUSE: ${error}`);
return response.status(500).send(); return response.status(500).send();
} }
@ -136,7 +136,7 @@ export const buildAnPowerHandler: (
`Param UUID must be a valid UUIDv4; got: [${anUuid}]`, `Param UUID must be a valid UUIDv4; got: [${anUuid}]`,
); );
} catch (error) { } 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(); return response.status(400).send();
} }
@ -151,7 +151,7 @@ export const buildAnPowerHandler: (
assert.ok(rows.length, 'No entry found'); assert.ok(rows.length, 'No entry found');
} catch (error) { } 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(); return response.status(500).send();
} }
@ -160,7 +160,7 @@ export const buildAnPowerHandler: (
try { try {
await queuePowerJob(task, { isStopServers: true, uuid: hostUuid }); await queuePowerJob(task, { isStopServers: true, uuid: hostUuid });
} catch (error) { } catch (error) {
stderr(`Failed to ${task} host ${hostUuid}; CAUSE: ${error}`); perr(`Failed to ${task} host ${hostUuid}; CAUSE: ${error}`);
return response.status(500).send(); 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 { getLocalHostUUID, getPeerData, query } from '../../accessModule';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stderr } from '../../shell'; import { perr } from '../../shell';
export const getHostSSH: RequestHandler< export const getHostSSH: RequestHandler<
unknown, unknown,
@ -37,7 +37,7 @@ export const getHostSSH: RequestHandler<
`IP address must be a valid IPv4 address; got [${target}]`, `IP address must be a valid IPv4 address; got [${target}]`,
); );
} catch (assertError) { } 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(); return response.status(400).send();
} }
@ -49,7 +49,7 @@ export const getHostSSH: RequestHandler<
try { try {
rsbody = await getPeerData(target, { password, port }); rsbody = await getPeerData(target, { password, port });
} catch (subError) { } catch (subError) {
stderr(`Failed to get peer data; CAUSE: ${subError}`); perr(`Failed to get peer data; CAUSE: ${subError}`);
return response.status(500).send(); return response.status(500).send();
} }

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

@ -6,7 +6,7 @@ import { LOCAL, REP_UUID } from '../../consts';
import { variable } from '../../accessModule'; import { variable } from '../../accessModule';
import { toHostUUID } from '../../convertHostUUID'; import { toHostUUID } from '../../convertHostUUID';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell'; import { perr, poutvar } from '../../shell';
export const setMapNetwork: RequestHandler< export const setMapNetwork: RequestHandler<
{ uuid: string }, { uuid: string },
@ -24,7 +24,7 @@ export const setMapNetwork: RequestHandler<
hostUuid = toHostUUID(hostUuid); hostUuid = toHostUUID(hostUuid);
stdoutVar({ hostUuid, value }, `Set map network variable with: `); poutvar({ hostUuid, value }, `Set map network variable with: `);
try { try {
assert( assert(
@ -37,7 +37,7 @@ export const setMapNetwork: RequestHandler<
`Host UUID must be a valid UUIDv4; got [${hostUuid}]`, `Host UUID must be a valid UUIDv4; got [${hostUuid}]`,
); );
} catch (error) { } 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(); return response.status(400).send();
} }
@ -59,7 +59,7 @@ export const setMapNetwork: RequestHandler<
`Result must be UUID of modified record; got: [${result}]`, `Result must be UUID of modified record; got: [${result}]`,
); );
} catch (error) { } catch (error) {
stderr( perr(
`Failed to set map network variable for host ${hostUuid}; CAUSE: ${error}`, `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 SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule'; import { job } from '../../accessModule';
import { stderr } from '../../shell'; import { perr } from '../../shell';
export const updateSystem: RequestHandler = async (request, response) => { export const updateSystem: RequestHandler = async (request, response) => {
try { try {
@ -15,7 +15,7 @@ export const updateSystem: RequestHandler = async (request, response) => {
job_title: 'job_0003', job_title: 'job_0003',
}); });
} catch (subError) { } catch (subError) {
stderr(`Failed to initiate system update; CAUSE: ${subError}`); perr(`Failed to initiate system update; CAUSE: ${subError}`);
return response.status(500).send(); return response.status(500).send();
} }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -5,7 +5,7 @@ import { DELETED, REP_UUID, SERVER_PATHS } from '../../consts';
import { job, query } from '../../accessModule'; import { job, query } from '../../accessModule';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell'; import { perr, poutvar } from '../../shell';
export const deleteServer: RequestHandler< export const deleteServer: RequestHandler<
{ serverUuid?: string }, { 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) { for (const serverUuid of serverUuids) {
try { try {
@ -60,7 +60,7 @@ export const deleteServer: RequestHandler<
job_title: 'job_0208', job_title: 'job_0208',
}); });
} catch (error) { } 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(); return response.status(500).send();
} }

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

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

@ -4,7 +4,7 @@ import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule'; import { job } from '../../accessModule';
import { toHostUUID } from '../../convertHostUUID'; import { toHostUUID } from '../../convertHostUUID';
import { stderr } from '../../shell'; import { perr } from '../../shell';
export const deleteSSHKeyConflict: RequestHandler< export const deleteSSHKeyConflict: RequestHandler<
unknown, unknown,
@ -29,7 +29,7 @@ export const deleteSSHKeyConflict: RequestHandler<
job_title: 'job_0056', job_title: 'job_0056',
}); });
} catch (subError) { } 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(); 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 { timestamp, write } from '../../accessModule';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stderr, uuid } from '../../shell'; import { perr, uuid } from '../../shell';
export const createUps: RequestHandler< export const createUps: RequestHandler<
{ uuid?: string }, { uuid?: string },
@ -43,7 +43,7 @@ export const createUps: RequestHandler<
`UPS UUID must be a valid UUIDv4; got [${upsUuid}]`, `UPS UUID must be a valid UUIDv4; got [${upsUuid}]`,
); );
} catch (error) { } 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(); return response.status(400).send();
} }
@ -75,7 +75,7 @@ export const createUps: RequestHandler<
assert(wcode === 0, `Write exited with code ${wcode}`); assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (error) { } catch (error) {
stderr(`Failed to write UPS record; CAUSE: ${error}`); perr(`Failed to write UPS record; CAUSE: ${error}`);
return response.status(500).send(); return response.status(500).send();
} }

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

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

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

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

@ -1,7 +1,7 @@
import { Application, Handler, Router } from 'express'; import { Application, Handler, Router } from 'express';
import path from 'path'; import path from 'path';
import { stdout } from './shell'; import { pout } from './shell';
export const rrouters = < export const rrouters = <
A extends Application, A extends Application,
@ -25,7 +25,7 @@ export const rrouters = <
const handlers = assign(union as R); const handlers = assign(union as R);
const { length: hcount } = handlers; 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); app.use(route, ...handlers);
} else if (key) { } 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 resolveUid = (id: number | string) => resolveId(id, 'passwd');
export const stderr = (message: string, error?: unknown) => { export const perr = (message: string, error?: unknown) => {
let msg = message; let msg = message;
if (error instanceof Error) { if (error instanceof Error) {
@ -64,9 +64,9 @@ export const stderr = (message: string, error?: unknown) => {
print(msg, { stream: 'stderr' }); 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)}`); print(`${label}${JSON.stringify(variable, null, 2)}`);
export const uuid = () => uuidgen('--random').trim(); export const uuid = () => uuidgen('--random').trim();

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

@ -4,7 +4,7 @@ import { LOCAL } from '../lib/consts';
import { query } from '../lib/accessModule'; import { query } from '../lib/accessModule';
import { toHostUUID } from '../lib/convertHostUUID'; import { toHostUUID } from '../lib/convertHostUUID';
import { stderr, stdoutVar } from '../lib/shell'; import { perr, poutvar } from '../lib/shell';
export const assertInit = export const assertInit =
({ ({
@ -34,19 +34,19 @@ export const assertInit =
LIMIT 1;`, LIMIT 1;`,
); );
} catch (error) { } 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(); 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'; let condition = rows.length === 1 && rows[0][0] === '1';
if (invert) condition = !condition; if (invert) condition = !condition;
if (condition) { if (condition) {
stderr(`Assert init failed; invert=${invert}`); perr(`Assert init failed; invert=${invert}`);
return fail(...args); return fail(...args);
} }

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

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

@ -2,7 +2,7 @@ import { createProxyMiddleware } from 'http-proxy-middleware';
import { P_UUID } from '../lib/consts'; import { P_UUID } from '../lib/consts';
import { stderr, stdout } from '../lib/shell'; import { perr, pout } from '../lib/shell';
import { getVncinfo } from '../lib/accessModule'; import { getVncinfo } from '../lib/accessModule';
const WS_SVR_VNC_URL_PREFIX = '/ws/server/vnc'; const WS_SVR_VNC_URL_PREFIX = '/ws/server/vnc';
@ -18,7 +18,7 @@ export const proxyServerVnc = createProxyMiddleware({
'$1', '$1',
); );
stdout(`Got param [${serverUuid}] from [${url}]`); pout(`Got param [${serverUuid}] from [${url}]`);
let domain: string; let domain: string;
let port: number; let port: number;
@ -27,7 +27,7 @@ export const proxyServerVnc = createProxyMiddleware({
try { try {
({ domain, port, protocol } = await getVncinfo(serverUuid)); ({ domain, port, protocol } = await getVncinfo(serverUuid));
} catch (error) { } catch (error) {
stderr(`Failed to get server ${serverUuid} VNC info; CAUSE: ${error}`); perr(`Failed to get server ${serverUuid} VNC info; CAUSE: ${error}`);
return; return;
} }
@ -36,7 +36,7 @@ export const proxyServerVnc = createProxyMiddleware({
}, },
on: { on: {
error: (error, request, response) => { error: (error, request, response) => {
stderr(`VNC proxy error: ${error}`); perr(`VNC proxy error: ${error}`);
let resType: string; let resType: string;
@ -48,7 +48,7 @@ export const proxyServerVnc = createProxyMiddleware({
resType = 'Socket'; resType = 'Socket';
} }
stdout(`Response type = ${resType}`); pout(`Response type = ${resType}`);
}, },
}, },
ws: true, ws: true,
@ -57,5 +57,5 @@ export const proxyServerVnc = createProxyMiddleware({
export const proxyServerVncUpgrade = export const proxyServerVncUpgrade =
proxyServerVnc.upgrade ?? 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 { getLocalHostUUID, query, timestamp, write } from '../lib/accessModule';
import { cname } from '../lib/cname'; import { cname } from '../lib/cname';
import { getSessionSecret } from '../lib/getSessionSecret'; 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 { export class SessionStore extends BaseSessionStore {
constructor(options = {}) { constructor(options = {}) {
@ -20,7 +20,7 @@ export class SessionStore extends BaseSessionStore {
sid: string, sid: string,
done?: ((err?: unknown) => void) | undefined, done?: ((err?: unknown) => void) | undefined,
): Promise<void> { ): Promise<void> {
stdout(`Destroy session ${sid}`); pout(`Destroy session ${sid}`);
try { try {
const wcode = await write( const wcode = await write(
@ -31,7 +31,7 @@ export class SessionStore extends BaseSessionStore {
assert(wcode === 0, `Write exited with code ${wcode}`); assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (error) { } catch (error) {
stderr( perr(
`Failed to complete DB write in destroy session ${sid}; CAUSE: ${error}`, `Failed to complete DB write in destroy session ${sid}; CAUSE: ${error}`,
); );
@ -45,7 +45,7 @@ export class SessionStore extends BaseSessionStore {
sid: string, sid: string,
done: (err: unknown, session?: SessionData | null | undefined) => void, done: (err: unknown, session?: SessionData | null | undefined) => void,
): Promise<void> { ): Promise<void> {
stdout(`Get session ${sid}`); pout(`Get session ${sid}`);
let rows: [ let rows: [
sessionUuid: string, sessionUuid: string,
@ -96,7 +96,7 @@ export class SessionStore extends BaseSessionStore {
session: SessionData, session: SessionData,
done?: ((err?: unknown) => void) | undefined, done?: ((err?: unknown) => void) | undefined,
): Promise<void> { ): Promise<void> {
stdoutVar({ session }, `Set session ${sid}: `); poutvar({ session }, `Set session ${sid}: `);
const { passport: { user: userUuid } = {} } = session; const { passport: { user: userUuid } = {} } = session;
@ -129,7 +129,7 @@ export class SessionStore extends BaseSessionStore {
assert(wcode === 0, `Write exited with code ${wcode}`); assert(wcode === 0, `Write exited with code ${wcode}`);
} catch (error) { } catch (error) {
stderr( perr(
`Failed to complete DB write in set session ${sid}; CAUSE: ${error}`, `Failed to complete DB write in set session ${sid}; CAUSE: ${error}`,
); );
@ -144,7 +144,7 @@ export class SessionStore extends BaseSessionStore {
session: SessionData, session: SessionData,
done?: ((err?: unknown) => void) | undefined, done?: ((err?: unknown) => void) | undefined,
): Promise<void> { ): 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 // 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 // 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}`); // assert(wcode === 0, `Write exited with code ${wcode}`);
// } catch (error) { // } catch (error) {
// stderr( // perr(
// `Failed to complete DB write in touch session ${sid}; CAUSE: ${error}`, // `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 sessionDeadlineEpoch = sessionModifiedEpoch + cookieOriginalMaxAge;
const cookieMaxAge = sessionDeadlineEpoch - Date.now(); const cookieMaxAge = sessionDeadlineEpoch - Date.now();
stdoutVar({ sessionModifiedDate, sessionDeadlineEpoch, cookieMaxAge }); poutvar({ sessionModifiedDate, sessionDeadlineEpoch, cookieMaxAge });
return cookieMaxAge; return cookieMaxAge;
} }
@ -193,7 +193,7 @@ export default (async () =>
genid: ({ originalUrl }) => { genid: ({ originalUrl }) => {
const sid = uuid(); const sid = uuid();
stdout(`Generated session identifier ${sid}; access to ${originalUrl}`); pout(`Generated session identifier ${sid}; access to ${originalUrl}`);
return sid; return sid;
}, },

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

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

Loading…
Cancel
Save