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}]`,
);
let buildResult: [manifestUuid: string, anvilName: string] | undefined;
const { counts: networkCountContainer, networks: networkContainer } =
Object.values(networkList).reduce<{
counts: Record<string, number>;
@ -253,8 +251,10 @@ export const buildManifest = (
{},
);
let result: { name: string; uuid: string } | undefined;
try {
buildResult = sub('generate_manifest', {
const [uuid, name] = sub('generate_manifest', {
subModuleName: 'Striker',
subParams: {
dns,
@ -268,10 +268,12 @@ export const buildManifest = (
...networkContainer,
...hostContainer,
},
}).stdout;
}).stdout as [manifestUuid: string, anvilName: string];
result = { name, uuid };
} catch (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 './getManifest';
export * from './getManifestDetail';
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 {
createManifest,
deleteManifest,
getManifest,
getManifestDetail,
getManifestTemplate,
updateManifest,
} from '../lib/request_handlers/manifest';
const router = express.Router();
router
.delete('/', deleteManifest)
.delete('/manifestUuid', deleteManifest)
.get('/', getManifest)
.get('/template', getManifestTemplate)
.get('/:manifestUUID', getManifestDetail)
.delete('/', deleteManifest)
.delete('/manifestUuid', deleteManifest);
.post('/', createManifest)
.put('/:manifestUuid', updateManifest);
export default router;

Loading…
Cancel
Save