diff --git a/striker-ui-api/src/lib/buildCondition.ts b/striker-ui-api/src/lib/buildCondition.ts index 67c0faa1..3226a80d 100644 --- a/striker-ui-api/src/lib/buildCondition.ts +++ b/striker-ui-api/src/lib/buildCondition.ts @@ -24,9 +24,8 @@ export const buildUnknownIDCondition = ( conditionPrefix: string, { onFallback }: { onFallback?: () => string }, ): { after: string; before: string[] } => { - const before = sanitize(keys, { + const before = sanitize(keys, 'string[]', { modifierType: 'sql', - returnType: 'string[]', }); const after = buildIDCondition(before, conditionPrefix, { onFallback }); diff --git a/striker-ui-api/src/lib/request_handlers/anvil/getAnvil.ts b/striker-ui-api/src/lib/request_handlers/anvil/getAnvil.ts index 08e7e702..cd21b1dd 100644 --- a/striker-ui-api/src/lib/request_handlers/anvil/getAnvil.ts +++ b/striker-ui-api/src/lib/request_handlers/anvil/getAnvil.ts @@ -61,13 +61,10 @@ const getAnvil: RequestHandler = buildGetRequestHandler( query: anvilDetailQuery, afterQueryReturn: anvilDetailAfterQueryReturn, } = buildQueryAnvilDetail({ - anvilUUIDs: sanitize(anvilUUIDs, { + anvilUUIDs: sanitize(anvilUUIDs, 'string[]', { modifierType: 'sql', - returnType: 'string[]', - }), - isForProvisionServer: sanitize(isForProvisionServer, { - returnType: 'boolean', }), + isForProvisionServer: sanitize(isForProvisionServer, 'boolean'), }); query = anvilDetailQuery; diff --git a/striker-ui-api/src/lib/request_handlers/file/getFile.ts b/striker-ui-api/src/lib/request_handlers/file/getFile.ts index 3df20799..3e28212c 100644 --- a/striker-ui-api/src/lib/request_handlers/file/getFile.ts +++ b/striker-ui-api/src/lib/request_handlers/file/getFile.ts @@ -19,9 +19,8 @@ const getFile: RequestHandler = buildGetRequestHandler((request) => { if (fileUUIDs) { query = buildQueryFileDetail({ - fileUUIDs: sanitize(fileUUIDs, { + fileUUIDs: sanitize(fileUUIDs, 'string[]', { modifierType: 'sql', - returnType: 'string[]', }), }); } diff --git a/striker-ui-api/src/lib/request_handlers/host/createHost.ts b/striker-ui-api/src/lib/request_handlers/host/createHost.ts index e081816a..fda024d7 100644 --- a/striker-ui-api/src/lib/request_handlers/host/createHost.ts +++ b/striker-ui-api/src/lib/request_handlers/host/createHost.ts @@ -16,7 +16,7 @@ export const createHost: RequestHandler = (...args) => { }, ] = args; - const hostType = sanitize(rawHostType, { returnType: 'string' }); + const hostType = sanitize(rawHostType, 'string'); stdout(`hostType=[${hostType}]`); diff --git a/striker-ui-api/src/lib/request_handlers/host/getHost.ts b/striker-ui-api/src/lib/request_handlers/host/getHost.ts index 810f5d67..cc5daf7e 100644 --- a/striker-ui-api/src/lib/request_handlers/host/getHost.ts +++ b/striker-ui-api/src/lib/request_handlers/host/getHost.ts @@ -37,9 +37,8 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => { if (hostUUIDs) { ({ query, afterQueryReturn } = buildQueryHostDetail({ - keys: sanitize(hostUUIDs, { + keys: sanitize(hostUUIDs, 'string[]', { modifierType: 'sql', - returnType: 'string[]', }), })); } diff --git a/striker-ui-api/src/lib/request_handlers/host/prepareHost.ts b/striker-ui-api/src/lib/request_handlers/host/prepareHost.ts index 13a84f2b..483b7583 100644 --- a/striker-ui-api/src/lib/request_handlers/host/prepareHost.ts +++ b/striker-ui-api/src/lib/request_handlers/host/prepareHost.ts @@ -44,15 +44,15 @@ export const prepareHost: RequestHandler< const isHostUUIDProvided = hostUUID !== undefined; - const dataHostIPAddress = sanitize<'string'>(hostIPAddress); - const dataHostName = sanitize<'string'>(hostName); - const dataHostPassword = sanitize<'string'>(hostPassword); - const dataHostSSHPort = sanitize<'number'>(hostSSHPort) || 22; - const dataHostType = sanitize<'string'>(hostType); - const dataHostUser = sanitize<'string'>(hostUser); - const dataHostUUID = sanitize<'string'>(hostUUID); - const dataRedhatPassword = sanitize<'string'>(redhatPassword); - const dataRedhatUser = sanitize<'string'>(redhatUser); + const dataHostIPAddress = sanitize(hostIPAddress, 'string'); + const dataHostName = sanitize(hostName, 'string'); + const dataHostPassword = sanitize(hostPassword, 'string'); + const dataHostSSHPort = sanitize(hostSSHPort, 'number') || 22; + const dataHostType = sanitize(hostType, 'string'); + const dataHostUser = sanitize(hostUser, 'string'); + const dataHostUUID = sanitize(hostUUID, 'string'); + const dataRedhatPassword = sanitize(redhatPassword, 'string'); + const dataRedhatUser = sanitize(redhatUser, 'string'); try { assert( diff --git a/striker-ui-api/src/lib/request_handlers/job/getJob.ts b/striker-ui-api/src/lib/request_handlers/job/getJob.ts index 48cd78c6..3fb670e3 100644 --- a/striker-ui-api/src/lib/request_handlers/job/getJob.ts +++ b/striker-ui-api/src/lib/request_handlers/job/getJob.ts @@ -5,7 +5,7 @@ import { date, stdout } from '../../shell'; export const getJob = buildGetRequestHandler((request, buildQueryOptions) => { const { start: rawStart } = request.query; - const start = sanitize(rawStart, { returnType: 'number' }); + const start = sanitize(rawStart, 'number'); let condModifiedDate = ''; diff --git a/striker-ui-api/src/lib/request_handlers/server/getServer.ts b/striker-ui-api/src/lib/request_handlers/server/getServer.ts index 85cebdae..5aebe5b3 100644 --- a/striker-ui-api/src/lib/request_handlers/server/getServer.ts +++ b/striker-ui-api/src/lib/request_handlers/server/getServer.ts @@ -6,15 +6,12 @@ export const getServer = buildGetRequestHandler( (request, buildQueryOptions) => { const { anvilUUIDs } = request.query; - const condAnvilUUIDs = join( - sanitize(anvilUUIDs, { returnType: 'string[]' }), - { - beforeReturn: (toReturn) => - toReturn ? `AND ser.server_anvil_uuid IN (${toReturn})` : '', - elementWrapper: "'", - separator: ', ', - }, - ); + const condAnvilUUIDs = join(sanitize(anvilUUIDs, 'string[]'), { + beforeReturn: (toReturn) => + toReturn ? `AND ser.server_anvil_uuid IN (${toReturn})` : '', + elementWrapper: "'", + separator: ', ', + }); console.log(`condAnvilsUUID=[${condAnvilUUIDs}]`); diff --git a/striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts b/striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts index 29932dae..cd74ba65 100644 --- a/striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts +++ b/striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts @@ -15,9 +15,7 @@ export const getServerDetail: RequestHandler = (request, response) => { const { ss, resize } = request.query; const epoch = Date.now(); - const isScreenshot = sanitize(ss, { - returnType: 'boolean', - }); + const isScreenshot = sanitize(ss, 'boolean'); console.log( `serverUUID=[${serverUUID}],epoch=[${epoch}],isScreenshot=[${isScreenshot}]`, @@ -118,9 +116,7 @@ export const getServerDetail: RequestHandler = (request, response) => { return; } - let resizeArgs = sanitize(resize, { - returnType: 'string', - }); + let resizeArgs = sanitize(resize, 'string'); if (!/^\d+x\d+$/.test(resizeArgs)) { resizeArgs = ''; diff --git a/striker-ui-api/src/lib/sanitize.ts b/striker-ui-api/src/lib/sanitize.ts index 4226e85c..d76a87a7 100644 --- a/striker-ui-api/src/lib/sanitize.ts +++ b/striker-ui-api/src/lib/sanitize.ts @@ -52,14 +52,13 @@ const MAP_TO_RETURN_FUNCTION: MapToReturnFunction = { export const sanitize = ( value: unknown, + returnType: ReturnTypeName, { modifierType = 'none', modifier = MAP_TO_MODIFIER_FUNCTION[modifierType], - returnType = 'string', }: { modifier?: ModifierFunction; modifierType?: keyof MapToModifierFunction; - returnType?: ReturnTypeName | 'string'; } = {}, ): MapToReturnType[ReturnTypeName] => MAP_TO_RETURN_FUNCTION[returnType](value, (unmodified: unknown) => {