feat(striker-ui-api): add PUT /host/:hostUUID

main
Tsu-ba-me 2 years ago
parent 1b6f1c2a2e
commit 3a01052e03
  1. 1
      striker-ui-api/src/lib/consts/SERVER_PATHS.ts
  2. 11
      striker-ui-api/src/lib/convertHostUUID.ts
  3. 5
      striker-ui-api/src/lib/request_handlers/host/getHost.ts
  4. 10
      striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts
  5. 8
      striker-ui-api/src/lib/request_handlers/host/getHostDetail.ts
  6. 1
      striker-ui-api/src/lib/request_handlers/host/index.ts
  7. 39
      striker-ui-api/src/lib/request_handlers/host/updateHost.ts
  8. 4
      striker-ui-api/src/lib/request_handlers/job/getJob.ts
  9. 5
      striker-ui-api/src/lib/request_handlers/ssh-key/getSSHKey.ts
  10. 4
      striker-ui-api/src/routes/host.ts

@ -21,6 +21,7 @@ const EMPTY_SERVER_PATHS: ServerPath = {
'anvil-manage-power': {}, 'anvil-manage-power': {},
'anvil-provision-server': {}, 'anvil-provision-server': {},
'anvil-sync-shared': {}, 'anvil-sync-shared': {},
'striker-manage-install-target': {},
'striker-parse-os-list': {}, 'striker-parse-os-list': {},
}, },
}, },

@ -0,0 +1,11 @@
import { LOCAL } from './consts/LOCAL';
import { getLocalHostUUID } from './accessModule';
export const toHostUUID = (hostUUID: string) =>
hostUUID === LOCAL ? getLocalHostUUID() : hostUUID;
export const toLocal = (
hostUUID: string,
localHostUUID: string = getLocalHostUUID(),
) => (hostUUID === localHostUUID ? LOCAL : hostUUID);

@ -1,8 +1,7 @@
import { LOCAL } from '../../consts/LOCAL';
import { getLocalHostUUID } from '../../accessModule'; import { getLocalHostUUID } from '../../accessModule';
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryHostDetail } from './buildQueryHostDetail'; import { buildQueryHostDetail } from './buildQueryHostDetail';
import { toLocal } from '../../convertHostUUID';
import { sanitizeQS } from '../../sanitizeQS'; import { sanitizeQS } from '../../sanitizeQS';
export const getHost = buildGetRequestHandler((request, buildQueryOptions) => { export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
@ -23,7 +22,7 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
if (output instanceof Array) { if (output instanceof Array) {
result = output.reduce<Record<string, HostOverview>>( result = output.reduce<Record<string, HostOverview>>(
(previous, [hostName, hostUUID]) => { (previous, [hostName, hostUUID]) => {
const key = hostUUID === localHostUUID ? LOCAL : hostUUID; const key = toLocal(hostUUID, localHostUUID);
previous[key] = { hostName, hostUUID }; previous[key] = { hostName, hostUUID };

@ -1,9 +1,9 @@
import { LOCAL } from '../../consts/LOCAL';
import { getAnvilData, getLocalHostUUID } from '../../accessModule'; import { getAnvilData, getLocalHostUUID } from '../../accessModule';
import { buildUnknownIDCondition } from '../../buildCondition'; import { buildUnknownIDCondition } from '../../buildCondition';
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { toLocal } from '../../convertHostUUID';
import { match } from '../../match'; import { match } from '../../match';
import { stdout } from '../../shell';
const buildHostConnections = ( const buildHostConnections = (
fromHostUUID: string, fromHostUUID: string,
@ -63,9 +63,9 @@ export const getHostConnection = buildGetRequestHandler(
beforeBuildIDCond.length > 0 ? beforeBuildIDCond : [localHostUUID]; beforeBuildIDCond.length > 0 ? beforeBuildIDCond : [localHostUUID];
const getConnectionKey = (hostUUID: string) => const getConnectionKey = (hostUUID: string) =>
hostUUID === localHostUUID ? LOCAL : hostUUID; toLocal(hostUUID, localHostUUID);
process.stdout.write(`condHostUUIDs=[${condHostUUIDs}]\n`); stdout(`condHostUUIDs=[${condHostUUIDs}]`);
try { try {
({ database: rawDatabaseData } = getAnvilData({ database: true })); ({ database: rawDatabaseData } = getAnvilData({ database: true }));
@ -83,7 +83,7 @@ export const getHostConnection = buildGetRequestHandler(
return previous; return previous;
}, {}); }, {});
process.stdout.write(`connections=[${JSON.stringify(connections)}]\n`); stdout(`connections=[${JSON.stringify(connections, null, 2)}]`);
if (buildQueryOptions) { if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => { buildQueryOptions.afterQueryReturn = (queryStdout) => {

@ -1,13 +1,11 @@
import { LOCAL } from '../../consts/LOCAL';
import { getLocalHostUUID } from '../../accessModule';
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryHostDetail } from './buildQueryHostDetail'; import { buildQueryHostDetail } from './buildQueryHostDetail';
import { toHostUUID } from '../../convertHostUUID';
import { sanitizeSQLParam } from '../../sanitizeSQLParam'; import { sanitizeSQLParam } from '../../sanitizeSQLParam';
export const getHostDetail = buildGetRequestHandler( export const getHostDetail = buildGetRequestHandler(
({ params: { hostUUID: host } }, buildQueryOptions) => { ({ params: { hostUUID: rawHostUUID } }, buildQueryOptions) => {
const hostUUID = host === LOCAL ? getLocalHostUUID() : host; const hostUUID = toHostUUID(rawHostUUID);
const { afterQueryReturn, query } = buildQueryHostDetail({ const { afterQueryReturn, query } = buildQueryHostDetail({
keys: [sanitizeSQLParam(hostUUID)], keys: [sanitizeSQLParam(hostUUID)],
}); });

@ -2,3 +2,4 @@ export * from './createHost';
export * from './getHost'; export * from './getHost';
export * from './getHostConnection'; export * from './getHostConnection';
export * from './getHostDetail'; export * from './getHostDetail';
export * from './updateHost';

@ -0,0 +1,39 @@
import { RequestHandler } from 'express';
import { LOCAL } from '../../consts/LOCAL';
import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { job } from '../../accessModule';
import { stdout } from '../../shell';
export const updateHost: RequestHandler<
{ hostUUID: string },
undefined,
{ isEnableInstallTarget?: boolean }
> = (request, response) => {
stdout(
`Begin edit host properties.\n${JSON.stringify(request.body, null, 2)}`,
);
const {
body: { isEnableInstallTarget },
params: { hostUUID: rawHostUUID },
} = request;
const hostUUID: string | undefined =
rawHostUUID === LOCAL ? undefined : rawHostUUID;
if (isEnableInstallTarget !== undefined) {
const task = isEnableInstallTarget ? 'enable' : 'disable';
job({
file: __filename,
job_command: `${SERVER_PATHS.usr.sbin['striker-manage-install-target'].self} --${task}`,
job_description: 'job_0016',
job_host_uuid: hostUUID,
job_name: `install-target::${task}`,
job_title: 'job_0015',
});
}
response.status(200).send();
};

@ -1,6 +1,6 @@
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { sanitizeQS } from '../../sanitizeQS'; import { sanitizeQS } from '../../sanitizeQS';
import { date } 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: rawStart } = request.query;
@ -19,7 +19,7 @@ export const getJob = buildGetRequestHandler((request, buildQueryOptions) => {
); );
} }
process.stdout.write(`condModifiedDate=[${condModifiedDate}]\n`); stdout(`condModifiedDate=[${condModifiedDate}]`);
if (buildQueryOptions) { if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => { buildQueryOptions.afterQueryReturn = (queryStdout) => {

@ -1,8 +1,7 @@
import { LOCAL } from '../../consts/LOCAL';
import { getLocalHostUUID } from '../../accessModule'; import { getLocalHostUUID } from '../../accessModule';
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier'; import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import { toLocal } from '../../convertHostUUID';
import { match } from '../../match'; import { match } from '../../match';
import { sanitizeQS } from '../../sanitizeQS'; import { sanitizeQS } from '../../sanitizeQS';
@ -30,7 +29,7 @@ const MAP_TO_HANDLER: Record<string, BuildQuerySubFunction> = {
}; };
}; };
}>((previous, [hostName, hostUUID, stateName, stateNote, stateUUID]) => { }>((previous, [hostName, hostUUID, stateName, stateNote, stateUUID]) => {
const hostUUIDKey = hostUUID === localHostUUID ? LOCAL : hostUUID; const hostUUIDKey = toLocal(hostUUID, localHostUUID);
if (previous[hostUUIDKey] === undefined) { if (previous[hostUUIDKey] === undefined) {
previous[hostUUIDKey] = {}; previous[hostUUIDKey] = {};

@ -5,6 +5,7 @@ import {
getHost, getHost,
getHostConnection, getHostConnection,
getHostDetail, getHostDetail,
updateHost,
} from '../lib/request_handlers/host'; } from '../lib/request_handlers/host';
const router = express.Router(); const router = express.Router();
@ -13,6 +14,7 @@ router
.get('/', getHost) .get('/', getHost)
.get('/connection', getHostConnection) .get('/connection', getHostConnection)
.get('/:hostUUID', getHostDetail) .get('/:hostUUID', getHostDetail)
.post('/', createHost); .post('/', createHost)
.put('/:hostUUID', updateHost);
export default router; export default router;

Loading…
Cancel
Save