fix(striker-ui-api): add POST (create) and PUT (update) for /manifest

main
Tsu-ba-me 2 years ago
parent 5de6046715
commit b7b4e13028
  1. 12
      striker-ui-api/src/lib/request_handlers/manifest/buildManifest.ts
  2. 29
      striker-ui-api/src/lib/request_handlers/manifest/createManifest.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/manifest/index.ts
  4. 34
      striker-ui-api/src/lib/request_handlers/manifest/updateManifest.ts
  5. 8
      striker-ui-api/src/routes/manifest.ts

@ -73,8 +73,6 @@ export const buildManifest = (
`Sequence must be an integer; got [${sequence}]`, `Sequence must be an integer; got [${sequence}]`,
); );
let buildResult: [manifestUuid: string, anvilName: string] | undefined;
const { counts: networkCountContainer, networks: networkContainer } = const { counts: networkCountContainer, networks: networkContainer } =
Object.values(networkList).reduce<{ Object.values(networkList).reduce<{
counts: Record<string, number>; counts: Record<string, number>;
@ -253,8 +251,10 @@ export const buildManifest = (
{}, {},
); );
let result: { name: string; uuid: string } | undefined;
try { try {
buildResult = sub('generate_manifest', { const [uuid, name] = sub('generate_manifest', {
subModuleName: 'Striker', subModuleName: 'Striker',
subParams: { subParams: {
dns, dns,
@ -268,10 +268,12 @@ export const buildManifest = (
...networkContainer, ...networkContainer,
...hostContainer, ...hostContainer,
}, },
}).stdout; }).stdout as [manifestUuid: string, anvilName: string];
result = { name, uuid };
} catch (subError) { } catch (subError) {
throw new Error(`Failed to generate manifest; CAUSE: ${subError}`); throw new Error(`Failed to generate manifest; CAUSE: ${subError}`);
} }
return buildResult; return result;
}; };

@ -0,0 +1,29 @@
import { AssertionError } from 'assert';
import { RequestHandler } from 'express';
import { buildManifest } from './buildManifest';
import { stderr } from '../../shell';
export const createManifest: RequestHandler = (...handlerArgs) => {
const [, response] = handlerArgs;
let result: Record<string, string> = {};
try {
result = buildManifest(...handlerArgs);
} catch (buildError) {
stderr(`Failed to create new install manifest; CAUSE ${buildError}`);
let code = 500;
if (buildError instanceof AssertionError) {
code = 400;
}
response.status(code).send();
return;
}
response.status(201).send(result);
};

@ -1,4 +1,6 @@
export * from './createManifest';
export * from './deleteManifest'; export * from './deleteManifest';
export * from './getManifest'; export * from './getManifest';
export * from './getManifestDetail'; export * from './getManifestDetail';
export * from './getManifestTemplate'; export * from './getManifestTemplate';
export * from './updateManifest';

@ -0,0 +1,34 @@
import { AssertionError } from 'assert';
import { RequestHandler } from 'express';
import { buildManifest } from './buildManifest';
import { stderr } from '../../shell';
export const updateManifest: RequestHandler = (...args) => {
const [request, response] = args;
const {
params: { manifestUuid },
} = request;
let result: Record<string, string> = {};
try {
result = buildManifest(...args);
} catch (buildError) {
stderr(
`Failed to update install manifest ${manifestUuid}; CAUSE: ${buildError}`,
);
let code = 500;
if (buildError instanceof AssertionError) {
code = 400;
}
response.status(code).send();
return;
}
response.status(200).send(result);
};

@ -1,19 +1,23 @@
import express from 'express'; import express from 'express';
import { import {
createManifest,
deleteManifest, deleteManifest,
getManifest, getManifest,
getManifestDetail, getManifestDetail,
getManifestTemplate, getManifestTemplate,
updateManifest,
} from '../lib/request_handlers/manifest'; } from '../lib/request_handlers/manifest';
const router = express.Router(); const router = express.Router();
router router
.delete('/', deleteManifest)
.delete('/manifestUuid', deleteManifest)
.get('/', getManifest) .get('/', getManifest)
.get('/template', getManifestTemplate) .get('/template', getManifestTemplate)
.get('/:manifestUUID', getManifestDetail) .get('/:manifestUUID', getManifestDetail)
.delete('/', deleteManifest) .post('/', createManifest)
.delete('/manifestUuid', deleteManifest); .put('/:manifestUuid', updateManifest);
export default router; export default router;

Loading…
Cancel
Save