fix(striker-ui-api): expose job endpoint for init, filter job by command

main
Tsu-ba-me 2 years ago
parent 2db17c9d1b
commit bc1b8bec20
  1. 14
      striker-ui-api/src/lib/request_handlers/job/getJob.ts
  2. 22
      striker-ui-api/src/routes/init.ts

@ -1,11 +1,14 @@
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, stdout } from '../../shell';
export const getJob = buildGetRequestHandler((request, buildQueryOptions) => { export const getJob = buildGetRequestHandler((request, buildQueryOptions) => {
const { start: rawStart } = request.query; const { start: rStart, command: rCommand } = request.query;
const start = sanitize(rawStart, 'number'); const start = sanitize(rStart, 'number');
const jcmd = sanitize(rCommand, 'string');
let condModifiedDate = ''; let condModifiedDate = '';
@ -19,6 +22,12 @@ export const getJob = buildGetRequestHandler((request, buildQueryOptions) => {
); );
} }
let condJobCommand = '';
if (REP_PEACEFUL_STRING.test(jcmd)) {
condJobCommand = `AND job.job_command LIKE '%${jcmd}%'`;
}
stdout(`condModifiedDate=[${condModifiedDate}]`); stdout(`condModifiedDate=[${condModifiedDate}]`);
if (buildQueryOptions) { if (buildQueryOptions) {
@ -78,5 +87,6 @@ export const getJob = buildGetRequestHandler((request, buildQueryOptions) => {
JOIN hosts AS hos JOIN hosts AS hos
ON job.job_host_uuid = hos.host_uuid ON job.job_host_uuid = hos.host_uuid
WHERE (job.job_progress < 100 ${condModifiedDate}) WHERE (job.job_progress < 100 ${condModifiedDate})
${condJobCommand}
AND job_name NOT LIKE 'get_server_screenshot%';`; AND job_name NOT LIKE 'get_server_screenshot%';`;
}); });

@ -4,11 +4,33 @@ import { assertInit } from '../middlewares';
import { setMapNetwork } from '../lib/request_handlers/command'; import { setMapNetwork } from '../lib/request_handlers/command';
import { configStriker } from '../lib/request_handlers/host'; import { configStriker } from '../lib/request_handlers/host';
import { getJob } from '../lib/request_handlers/job';
import { getNetworkInterface } from '../lib/request_handlers/network-interface'; import { getNetworkInterface } from '../lib/request_handlers/network-interface';
const router = express.Router(); const router = express.Router();
router router
.get(
'/job',
(request, response, next) => {
const {
path,
query: { command, start },
} = request;
if (command) return next();
return response.redirect(
`/api/init${path}?command=anvil-configure-host&start=${start}`,
);
},
assertInit({
fail: ({ url }, response) => {
response.redirect(307, `/api${url}`);
},
}),
getJob,
)
.get( .get(
'/network-interface/:hostUUID?', '/network-interface/:hostUUID?',
assertInit({ assertInit({

Loading…
Cancel
Save