fix(striker-ui-api): migrate sub to access interact

main
Tsu-ba-me 2 years ago
parent f9d7449b7d
commit aa49de761a
  1. 3
      striker-ui-api/src/lib/accessModule.ts
  2. 7
      striker-ui-api/src/lib/request_handlers/command/runManifest.ts
  3. 43
      striker-ui-api/src/lib/request_handlers/host/createHostConnection.ts
  4. 37
      striker-ui-api/src/lib/request_handlers/manifest/buildManifest.ts
  5. 4
      striker-ui-api/src/lib/request_handlers/manifest/createManifest.ts
  6. 14
      striker-ui-api/src/lib/request_handlers/manifest/deleteManifest.ts
  7. 4
      striker-ui-api/src/lib/request_handlers/manifest/updateManifest.ts
  8. 20
      striker-ui-api/src/passport.ts

@ -423,7 +423,6 @@ export {
dbInsertOrUpdateVariable as variable, dbInsertOrUpdateVariable as variable,
dbJobAnvilSyncShared, dbJobAnvilSyncShared,
dbSubRefreshTimestamp as timestamp, dbSubRefreshTimestamp as timestamp,
execModuleSubroutine as sub,
getData, getData,
getFenceSpec, getFenceSpec,
getHostData, getHostData,
@ -433,6 +432,6 @@ export {
getPeerData, getPeerData,
getUpsSpec, getUpsSpec,
query, query,
subroutine, subroutine as sub,
write, write,
}; };

@ -122,7 +122,7 @@ export const runManifest: RequestHandler<
const joinAnJobs: DBJobParams[] = []; const joinAnJobs: DBJobParams[] = [];
let anParams: Record<string, string> | undefined; let anParams: Record<string, string>;
try { try {
anParams = Object.values(hostList).reduce<Record<string, string>>( anParams = Object.values(hostList).reduce<Record<string, string>>(
@ -163,8 +163,9 @@ export const runManifest: RequestHandler<
} }
try { try {
const [newAnUuid] = sub('insert_or_update_anvils', { subParams: anParams }) const [newAnUuid]: [string] = await sub('insert_or_update_anvils', {
.stdout as [string]; params: [anParams],
});
joinAnJobs.forEach((jobParams) => { joinAnJobs.forEach((jobParams) => {
jobParams.job_data += `,anvil_uuid=${newAnUuid}`; jobParams.job_data += `,anvil_uuid=${newAnUuid}`;

@ -68,10 +68,10 @@ export const createHostConnection: RequestHandler<
} }
try { try {
localIPAddress = sub('find_matching_ip', { [localIPAddress] = await sub('find_matching_ip', {
subModuleName: 'System', params: [{ host: peerIPAddress }],
subParams: { host: peerIPAddress }, pre: ['System'],
}).stdout; });
} catch (subError) { } catch (subError) {
stderr(`Failed to get matching IP address; CAUSE: ${subError}`); stderr(`Failed to get matching IP address; CAUSE: ${subError}`);
@ -89,15 +89,17 @@ export const createHostConnection: RequestHandler<
stdoutVar({ pgpassFilePath, pgpassFileBody }); stdoutVar({ pgpassFilePath, pgpassFileBody });
try { try {
sub('write_file', { await sub('write_file', {
subModuleName: 'Storage', params: [
subParams: { {
body: pgpassFileBody, body: pgpassFileBody,
file: pgpassFilePath, file: pgpassFilePath,
mode: '0600', mode: '0600',
overwrite: 1, overwrite: 1,
secure: 1, secure: 1,
}, },
],
pre: ['Storage'],
}); });
} catch (subError) { } catch (subError) {
stderr(`Failed to write ${pgpassFilePath}; CAUSE: ${subError}`); stderr(`Failed to write ${pgpassFilePath}; CAUSE: ${subError}`);
@ -106,12 +108,15 @@ export const createHostConnection: RequestHandler<
} }
try { try {
const [rawIsPeerDBReachable] = sub('call', { const [rawIsPeerDBReachable]: [output: string, returnCode: number] =
subModuleName: 'System', await sub('call', {
subParams: { params: [
shell_call: `PGPASSFILE="${pgpassFilePath}" ${SERVER_PATHS.usr.bin.psql.self} --host ${peerIPAddress} --port ${commonDBPort} --dbname ${commonDBName} --username ${commonDBUser} --no-password --tuples-only --no-align --command "SELECT 1"`, {
}, shell_call: `PGPASSFILE="${pgpassFilePath}" ${SERVER_PATHS.usr.bin.psql.self} --host ${peerIPAddress} --port ${commonDBPort} --dbname ${commonDBName} --username ${commonDBUser} --no-password --tuples-only --no-align --command "SELECT 1"`,
}).stdout as [output: string, returnCode: number]; },
],
pre: ['System'],
});
isPeerDBReachable = rawIsPeerDBReachable === '1'; isPeerDBReachable = rawIsPeerDBReachable === '1';
} catch (subError) { } catch (subError) {

@ -13,7 +13,7 @@ import { sub } from '../../accessModule';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stdout } from '../../shell'; import { stdout } from '../../shell';
export const buildManifest = ( export const buildManifest = async (
...[request]: Parameters< ...[request]: Parameters<
RequestHandler< RequestHandler<
{ manifestUuid?: string }, { manifestUuid?: string },
@ -257,24 +257,29 @@ export const buildManifest = (
{}, {},
); );
let result: { name: string; uuid: string } | undefined; let result: { name: string; uuid: string };
try { try {
const [uuid, name] = sub('generate_manifest', { const [uuid, name]: [manifestUuid: string, anvilName: string] = await sub(
subModuleName: 'Striker', 'generate_manifest',
subParams: { {
dns, params: [
domain, {
manifest_uuid: manifestUuid, dns,
mtu, domain,
ntp, manifest_uuid: manifestUuid,
prefix, mtu,
sequence, ntp,
...networkCountContainer, prefix,
...networkContainer, sequence,
...hostContainer, ...networkCountContainer,
...networkContainer,
...hostContainer,
},
],
pre: ['Striker'],
}, },
}).stdout as [manifestUuid: string, anvilName: string]; );
result = { name, uuid }; result = { name, uuid };
} catch (subError) { } catch (subError) {

@ -4,13 +4,13 @@ import { RequestHandler } from 'express';
import { buildManifest } from './buildManifest'; import { buildManifest } from './buildManifest';
import { stderr } from '../../shell'; import { stderr } from '../../shell';
export const createManifest: RequestHandler = (...handlerArgs) => { export const createManifest: RequestHandler = async (...handlerArgs) => {
const [, response] = handlerArgs; const [, response] = handlerArgs;
let result: Record<string, string> = {}; let result: Record<string, string> = {};
try { try {
result = buildManifest(...handlerArgs); result = await buildManifest(...handlerArgs);
} catch (buildError) { } catch (buildError) {
stderr(`Failed to create new install manifest; CAUSE ${buildError}`); stderr(`Failed to create new install manifest; CAUSE ${buildError}`);

@ -7,7 +7,7 @@ export const deleteManifest: RequestHandler<
{ manifestUuid: string }, { manifestUuid: string },
undefined, undefined,
{ uuids: string[] } { uuids: string[] }
> = (request, response) => { > = async (request, response) => {
const { const {
params: { manifestUuid: rawManifestUuid }, params: { manifestUuid: rawManifestUuid },
body: { uuids: rawManifestUuidList } = {}, body: { uuids: rawManifestUuidList } = {},
@ -17,21 +17,19 @@ export const deleteManifest: RequestHandler<
? rawManifestUuidList ? rawManifestUuidList
: [rawManifestUuid]; : [rawManifestUuid];
manifestUuidList.forEach((uuid) => { for (const uuid of manifestUuidList) {
stdout(`Begin delete manifest ${uuid}.`); stdout(`Begin delete manifest ${uuid}.`);
try { try {
sub('insert_or_update_manifests', { await sub('insert_or_update_manifests', {
subParams: { delete: 1, manifest_uuid: uuid }, params: [{ delete: 1, manifest_uuid: uuid }],
}); });
} catch (subError) { } catch (subError) {
stderr(`Failed to delete manifest ${uuid}; CAUSE: ${subError}`); stderr(`Failed to delete manifest ${uuid}; CAUSE: ${subError}`);
response.status(500).send(); return response.status(500).send();
return;
} }
}); }
response.status(204).send(); response.status(204).send();
}; };

@ -4,7 +4,7 @@ import { RequestHandler } from 'express';
import { buildManifest } from './buildManifest'; import { buildManifest } from './buildManifest';
import { stderr } from '../../shell'; import { stderr } from '../../shell';
export const updateManifest: RequestHandler = (...args) => { export const updateManifest: RequestHandler = async (...args) => {
const [request, response] = args; const [request, response] = args;
const { const {
params: { manifestUuid }, params: { manifestUuid },
@ -13,7 +13,7 @@ export const updateManifest: RequestHandler = (...args) => {
let result: Record<string, string> = {}; let result: Record<string, string> = {};
try { try {
result = buildManifest(...args); result = await buildManifest(...args);
} catch (buildError) { } catch (buildError) {
stderr( stderr(
`Failed to update install manifest ${manifestUuid}; CAUSE: ${buildError}`, `Failed to update install manifest ${manifestUuid}; CAUSE: ${buildError}`,

@ -55,15 +55,17 @@ passport.use(
}; };
try { try {
encryptResult = sub('encrypt_password', { [encryptResult] = await sub('encrypt_password', {
subModuleName: 'Account', params: [
subParams: { {
algorithm: userAlgorithm, algorithm: userAlgorithm,
hash_count: userHashCount, hash_count: userHashCount,
password, password,
salt: userSalt, salt: userSalt,
}, },
}).stdout; ],
pre: ['Account'],
});
} catch (subError) { } catch (subError) {
return done(subError); return done(subError);
} }

Loading…
Cancel
Save