fix(striker-ui-api): add install-target state to GET /host/:hostUUID

main
Tsu-ba-me 2 years ago
parent 0aec411e1a
commit f9bd775ed6
  1. 2
      striker-ui-api/src/lib/accessModule.ts
  2. 1
      striker-ui-api/src/lib/consts/LOCAL.ts
  3. 28
      striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts
  4. 6
      striker-ui-api/src/lib/request_handlers/host/getHostDetail.ts

@ -140,7 +140,7 @@ const getAnvilData = (
).stdout;
const getLocalHostUUID = () => {
let result;
let result: string;
try {
result = execModuleSubroutine('host_uuid', {

@ -0,0 +1 @@
export const LOCAL = 'local';

@ -3,6 +3,20 @@ import { buildQueryResultModifier } from '../../buildQueryResultModifier';
import { cap } from '../../cap';
import { stdout } from '../../shell';
type ExtractVariableKeyFunction = (parts: string[]) => string;
const MAP_TO_EXTRACTOR: { [prefix: string]: ExtractVariableKeyFunction } = {
form: ([, part2]) => {
const [head, ...rest] = part2.split('_');
return rest.reduce<string>(
(previous, part) => `${previous}${cap(part)}`,
head,
);
},
'install-target': () => 'installTargetEnable',
};
export const buildQueryHostDetail: BuildQueryDetailFunction = ({
keys: hostUUIDs = '*',
} = {}) => {
@ -19,7 +33,10 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
FROM variables AS var
JOIN hosts AS hos
ON var.variable_source_uuid = hos.host_uuid
WHERE variable_name LIKE 'form::config_%'
WHERE (
variable_name LIKE 'form::config_%'
OR variable_name = 'install-target::enabled'
)
${condHostUUIDs};`;
const afterQueryReturn: QueryResultModifierFunction =
@ -30,12 +47,9 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
{ hostName: string; hostUUID: string } & Record<string, string>
>(
(previous, [, , variableName, variableValue]) => {
const [, , variableKey] = variableName.split('::');
const [head, ...rest] = variableKey.split('_');
const key = rest.reduce<string>(
(previous, part) => `${previous}${cap(part)}`,
head,
);
const [variablePrefix, ...restVariableParts] =
variableName.split('::');
const key = MAP_TO_EXTRACTOR[variablePrefix](restVariableParts);
previous[key] = variableValue;

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

Loading…
Cancel
Save