diff --git a/striker-ui-api/src/lib/accessModule.ts b/striker-ui-api/src/lib/accessModule.ts index 1bdc1d1a..c9d38cde 100644 --- a/striker-ui-api/src/lib/accessModule.ts +++ b/striker-ui-api/src/lib/accessModule.ts @@ -140,7 +140,7 @@ const getAnvilData = ( ).stdout; const getLocalHostUUID = () => { - let result; + let result: string; try { result = execModuleSubroutine('host_uuid', { diff --git a/striker-ui-api/src/lib/consts/LOCAL.ts b/striker-ui-api/src/lib/consts/LOCAL.ts new file mode 100644 index 00000000..9d6bca63 --- /dev/null +++ b/striker-ui-api/src/lib/consts/LOCAL.ts @@ -0,0 +1 @@ +export const LOCAL = 'local'; diff --git a/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts b/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts index aa235463..7f4307af 100644 --- a/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts +++ b/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts @@ -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( + (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 >( (previous, [, , variableName, variableValue]) => { - const [, , variableKey] = variableName.split('::'); - const [head, ...rest] = variableKey.split('_'); - const key = rest.reduce( - (previous, part) => `${previous}${cap(part)}`, - head, - ); + const [variablePrefix, ...restVariableParts] = + variableName.split('::'); + const key = MAP_TO_EXTRACTOR[variablePrefix](restVariableParts); previous[key] = variableValue; diff --git a/striker-ui-api/src/lib/request_handlers/host/getHostDetail.ts b/striker-ui-api/src/lib/request_handlers/host/getHostDetail.ts index e48a2f81..3c7c0419 100644 --- a/striker-ui-api/src/lib/request_handlers/host/getHostDetail.ts +++ b/striker-ui-api/src/lib/request_handlers/host/getHostDetail.ts @@ -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)], });