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,
dbJobAnvilSyncShared,
dbSubRefreshTimestamp as timestamp,
execModuleSubroutine as sub,
getData,
getFenceSpec,
getHostData,
@ -433,6 +432,6 @@ export {
getPeerData,
getUpsSpec,
query,
subroutine,
subroutine as sub,
write,
};

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

@ -68,10 +68,10 @@ export const createHostConnection: RequestHandler<
}
try {
localIPAddress = sub('find_matching_ip', {
subModuleName: 'System',
subParams: { host: peerIPAddress },
}).stdout;
[localIPAddress] = await sub('find_matching_ip', {
params: [{ host: peerIPAddress }],
pre: ['System'],
});
} catch (subError) {
stderr(`Failed to get matching IP address; CAUSE: ${subError}`);
@ -89,15 +89,17 @@ export const createHostConnection: RequestHandler<
stdoutVar({ pgpassFilePath, pgpassFileBody });
try {
sub('write_file', {
subModuleName: 'Storage',
subParams: {
body: pgpassFileBody,
file: pgpassFilePath,
mode: '0600',
overwrite: 1,
secure: 1,
},
await sub('write_file', {
params: [
{
body: pgpassFileBody,
file: pgpassFilePath,
mode: '0600',
overwrite: 1,
secure: 1,
},
],
pre: ['Storage'],
});
} catch (subError) {
stderr(`Failed to write ${pgpassFilePath}; CAUSE: ${subError}`);
@ -106,12 +108,15 @@ export const createHostConnection: RequestHandler<
}
try {
const [rawIsPeerDBReachable] = sub('call', {
subModuleName: 'System',
subParams: {
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];
const [rawIsPeerDBReachable]: [output: string, returnCode: number] =
await sub('call', {
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"`,
},
],
pre: ['System'],
});
isPeerDBReachable = rawIsPeerDBReachable === '1';
} catch (subError) {

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

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

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

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

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

Loading…
Cancel
Save