adding a real test Method for API gateway
This commit is contained in:
@@ -589,6 +589,25 @@ export function createCloudRoutes(injectedService?: CloudProxyService) {
|
||||
})
|
||||
})
|
||||
|
||||
app.post('/:cloud/services/apigateway/resources/:id/methods/test', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
|
||||
return withRuntime(c, async () => {
|
||||
const input = await c.req.json<Record<string, unknown>>()
|
||||
const result = await svc(c).testApiGatewayMethod(cloud, c.req.param('id'), {
|
||||
resourceId: typeof input.resourceId === 'string' ? input.resourceId : '',
|
||||
httpMethod: typeof input.httpMethod === 'string' ? input.httpMethod : '',
|
||||
pathWithQueryString: typeof input.pathWithQueryString === 'string' ? input.pathWithQueryString : '',
|
||||
body: typeof input.body === 'string' ? input.body : '',
|
||||
headers: stringHeaders(input.headers),
|
||||
multiValueHeaders: stringArrayHeaders(input.multiValueHeaders),
|
||||
stageVariables: stringHeaders(input.stageVariables),
|
||||
})
|
||||
return c.json(result)
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/:cloud/services/storage/resources/:id/lambda-triggers', async (c) => {
|
||||
const cloud = c.req.param('cloud') as CloudProvider
|
||||
if (cloud !== 'aws') return c.json({error: 'Unknown cloud or service'}, 404)
|
||||
@@ -1178,6 +1197,13 @@ function stringHeaders(value: unknown): Record<string, string> {
|
||||
return Object.fromEntries(entries) as Record<string, string>
|
||||
}
|
||||
|
||||
function stringArrayHeaders(value: unknown): Record<string, string[]> {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return {}
|
||||
return Object.fromEntries(Object.entries(value).flatMap(([name, values]) =>
|
||||
Array.isArray(values) && values.every((header) => typeof header === 'string') ? [[name, values]] : [],
|
||||
))
|
||||
}
|
||||
|
||||
function decodeBase64(value: unknown, field: string, maxLength: number): Uint8Array {
|
||||
if (typeof value !== 'string') throw new ValidationError(`${field} must be a base64 string`)
|
||||
if (value.length > maxLength) throw new ValidationError(`${field} is too large`)
|
||||
|
||||
Reference in New Issue
Block a user