fix(striker-ui-api): make return type in sanitize required

This commit is contained in:
Tsu-ba-me 2022-11-10 15:54:54 -05:00
parent fcf999b11b
commit 54b78e9f25
10 changed files with 25 additions and 39 deletions

View File

@ -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 });

View File

@ -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;

View File

@ -19,9 +19,8 @@ const getFile: RequestHandler = buildGetRequestHandler((request) => {
if (fileUUIDs) {
query = buildQueryFileDetail({
fileUUIDs: sanitize(fileUUIDs, {
fileUUIDs: sanitize(fileUUIDs, 'string[]', {
modifierType: 'sql',
returnType: 'string[]',
}),
});
}

View File

@ -16,7 +16,7 @@ export const createHost: RequestHandler = (...args) => {
},
] = args;
const hostType = sanitize(rawHostType, { returnType: 'string' });
const hostType = sanitize(rawHostType, 'string');
stdout(`hostType=[${hostType}]`);

View File

@ -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[]',
}),
}));
}

View File

@ -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(

View File

@ -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 = '';

View File

@ -6,15 +6,12 @@ export const getServer = buildGetRequestHandler(
(request, buildQueryOptions) => {
const { anvilUUIDs } = request.query;
const condAnvilUUIDs = join(
sanitize(anvilUUIDs, { returnType: 'string[]' }),
{
const condAnvilUUIDs = join(sanitize(anvilUUIDs, 'string[]'), {
beforeReturn: (toReturn) =>
toReturn ? `AND ser.server_anvil_uuid IN (${toReturn})` : '',
elementWrapper: "'",
separator: ', ',
},
);
});
console.log(`condAnvilsUUID=[${condAnvilUUIDs}]`);

View File

@ -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 = '';

View File

@ -52,14 +52,13 @@ const MAP_TO_RETURN_FUNCTION: MapToReturnFunction = {
export const sanitize = <ReturnTypeName extends keyof MapToReturnType>(
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) => {