fix(striker-ui-api): make return type in sanitize required
This commit is contained in:
parent
fcf999b11b
commit
54b78e9f25
@ -24,9 +24,8 @@ export const buildUnknownIDCondition = (
|
|||||||
conditionPrefix: string,
|
conditionPrefix: string,
|
||||||
{ onFallback }: { onFallback?: () => string },
|
{ onFallback }: { onFallback?: () => string },
|
||||||
): { after: string; before: string[] } => {
|
): { after: string; before: string[] } => {
|
||||||
const before = sanitize(keys, {
|
const before = sanitize(keys, 'string[]', {
|
||||||
modifierType: 'sql',
|
modifierType: 'sql',
|
||||||
returnType: 'string[]',
|
|
||||||
});
|
});
|
||||||
const after = buildIDCondition(before, conditionPrefix, { onFallback });
|
const after = buildIDCondition(before, conditionPrefix, { onFallback });
|
||||||
|
|
||||||
|
@ -61,13 +61,10 @@ const getAnvil: RequestHandler = buildGetRequestHandler(
|
|||||||
query: anvilDetailQuery,
|
query: anvilDetailQuery,
|
||||||
afterQueryReturn: anvilDetailAfterQueryReturn,
|
afterQueryReturn: anvilDetailAfterQueryReturn,
|
||||||
} = buildQueryAnvilDetail({
|
} = buildQueryAnvilDetail({
|
||||||
anvilUUIDs: sanitize(anvilUUIDs, {
|
anvilUUIDs: sanitize(anvilUUIDs, 'string[]', {
|
||||||
modifierType: 'sql',
|
modifierType: 'sql',
|
||||||
returnType: 'string[]',
|
|
||||||
}),
|
|
||||||
isForProvisionServer: sanitize(isForProvisionServer, {
|
|
||||||
returnType: 'boolean',
|
|
||||||
}),
|
}),
|
||||||
|
isForProvisionServer: sanitize(isForProvisionServer, 'boolean'),
|
||||||
});
|
});
|
||||||
|
|
||||||
query = anvilDetailQuery;
|
query = anvilDetailQuery;
|
||||||
|
@ -19,9 +19,8 @@ const getFile: RequestHandler = buildGetRequestHandler((request) => {
|
|||||||
|
|
||||||
if (fileUUIDs) {
|
if (fileUUIDs) {
|
||||||
query = buildQueryFileDetail({
|
query = buildQueryFileDetail({
|
||||||
fileUUIDs: sanitize(fileUUIDs, {
|
fileUUIDs: sanitize(fileUUIDs, 'string[]', {
|
||||||
modifierType: 'sql',
|
modifierType: 'sql',
|
||||||
returnType: 'string[]',
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ export const createHost: RequestHandler = (...args) => {
|
|||||||
},
|
},
|
||||||
] = args;
|
] = args;
|
||||||
|
|
||||||
const hostType = sanitize(rawHostType, { returnType: 'string' });
|
const hostType = sanitize(rawHostType, 'string');
|
||||||
|
|
||||||
stdout(`hostType=[${hostType}]`);
|
stdout(`hostType=[${hostType}]`);
|
||||||
|
|
||||||
|
@ -37,9 +37,8 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
|
|||||||
|
|
||||||
if (hostUUIDs) {
|
if (hostUUIDs) {
|
||||||
({ query, afterQueryReturn } = buildQueryHostDetail({
|
({ query, afterQueryReturn } = buildQueryHostDetail({
|
||||||
keys: sanitize(hostUUIDs, {
|
keys: sanitize(hostUUIDs, 'string[]', {
|
||||||
modifierType: 'sql',
|
modifierType: 'sql',
|
||||||
returnType: 'string[]',
|
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -44,15 +44,15 @@ export const prepareHost: RequestHandler<
|
|||||||
|
|
||||||
const isHostUUIDProvided = hostUUID !== undefined;
|
const isHostUUIDProvided = hostUUID !== undefined;
|
||||||
|
|
||||||
const dataHostIPAddress = sanitize<'string'>(hostIPAddress);
|
const dataHostIPAddress = sanitize(hostIPAddress, 'string');
|
||||||
const dataHostName = sanitize<'string'>(hostName);
|
const dataHostName = sanitize(hostName, 'string');
|
||||||
const dataHostPassword = sanitize<'string'>(hostPassword);
|
const dataHostPassword = sanitize(hostPassword, 'string');
|
||||||
const dataHostSSHPort = sanitize<'number'>(hostSSHPort) || 22;
|
const dataHostSSHPort = sanitize(hostSSHPort, 'number') || 22;
|
||||||
const dataHostType = sanitize<'string'>(hostType);
|
const dataHostType = sanitize(hostType, 'string');
|
||||||
const dataHostUser = sanitize<'string'>(hostUser);
|
const dataHostUser = sanitize(hostUser, 'string');
|
||||||
const dataHostUUID = sanitize<'string'>(hostUUID);
|
const dataHostUUID = sanitize(hostUUID, 'string');
|
||||||
const dataRedhatPassword = sanitize<'string'>(redhatPassword);
|
const dataRedhatPassword = sanitize(redhatPassword, 'string');
|
||||||
const dataRedhatUser = sanitize<'string'>(redhatUser);
|
const dataRedhatUser = sanitize(redhatUser, 'string');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assert(
|
assert(
|
||||||
|
@ -5,7 +5,7 @@ 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;
|
||||||
|
|
||||||
const start = sanitize(rawStart, { returnType: 'number' });
|
const start = sanitize(rawStart, 'number');
|
||||||
|
|
||||||
let condModifiedDate = '';
|
let condModifiedDate = '';
|
||||||
|
|
||||||
|
@ -6,15 +6,12 @@ export const getServer = buildGetRequestHandler(
|
|||||||
(request, buildQueryOptions) => {
|
(request, buildQueryOptions) => {
|
||||||
const { anvilUUIDs } = request.query;
|
const { anvilUUIDs } = request.query;
|
||||||
|
|
||||||
const condAnvilUUIDs = join(
|
const condAnvilUUIDs = join(sanitize(anvilUUIDs, 'string[]'), {
|
||||||
sanitize(anvilUUIDs, { returnType: 'string[]' }),
|
beforeReturn: (toReturn) =>
|
||||||
{
|
toReturn ? `AND ser.server_anvil_uuid IN (${toReturn})` : '',
|
||||||
beforeReturn: (toReturn) =>
|
elementWrapper: "'",
|
||||||
toReturn ? `AND ser.server_anvil_uuid IN (${toReturn})` : '',
|
separator: ', ',
|
||||||
elementWrapper: "'",
|
});
|
||||||
separator: ', ',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(`condAnvilsUUID=[${condAnvilUUIDs}]`);
|
console.log(`condAnvilsUUID=[${condAnvilUUIDs}]`);
|
||||||
|
|
||||||
|
@ -15,9 +15,7 @@ export const getServerDetail: RequestHandler = (request, response) => {
|
|||||||
const { ss, resize } = request.query;
|
const { ss, resize } = request.query;
|
||||||
|
|
||||||
const epoch = Date.now();
|
const epoch = Date.now();
|
||||||
const isScreenshot = sanitize(ss, {
|
const isScreenshot = sanitize(ss, 'boolean');
|
||||||
returnType: 'boolean',
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`serverUUID=[${serverUUID}],epoch=[${epoch}],isScreenshot=[${isScreenshot}]`,
|
`serverUUID=[${serverUUID}],epoch=[${epoch}],isScreenshot=[${isScreenshot}]`,
|
||||||
@ -118,9 +116,7 @@ export const getServerDetail: RequestHandler = (request, response) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let resizeArgs = sanitize(resize, {
|
let resizeArgs = sanitize(resize, 'string');
|
||||||
returnType: 'string',
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!/^\d+x\d+$/.test(resizeArgs)) {
|
if (!/^\d+x\d+$/.test(resizeArgs)) {
|
||||||
resizeArgs = '';
|
resizeArgs = '';
|
||||||
|
@ -52,14 +52,13 @@ const MAP_TO_RETURN_FUNCTION: MapToReturnFunction = {
|
|||||||
|
|
||||||
export const sanitize = <ReturnTypeName extends keyof MapToReturnType>(
|
export const sanitize = <ReturnTypeName extends keyof MapToReturnType>(
|
||||||
value: unknown,
|
value: unknown,
|
||||||
|
returnType: ReturnTypeName,
|
||||||
{
|
{
|
||||||
modifierType = 'none',
|
modifierType = 'none',
|
||||||
modifier = MAP_TO_MODIFIER_FUNCTION[modifierType],
|
modifier = MAP_TO_MODIFIER_FUNCTION[modifierType],
|
||||||
returnType = 'string',
|
|
||||||
}: {
|
}: {
|
||||||
modifier?: ModifierFunction;
|
modifier?: ModifierFunction;
|
||||||
modifierType?: keyof MapToModifierFunction;
|
modifierType?: keyof MapToModifierFunction;
|
||||||
returnType?: ReturnTypeName | 'string';
|
|
||||||
} = {},
|
} = {},
|
||||||
): MapToReturnType[ReturnTypeName] =>
|
): MapToReturnType[ReturnTypeName] =>
|
||||||
MAP_TO_RETURN_FUNCTION[returnType](value, (unmodified: unknown) => {
|
MAP_TO_RETURN_FUNCTION[returnType](value, (unmodified: unknown) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user