Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async createRoutes() {
const integrationsPromises = map(async (fn) => {
const integrationId = await this.createIntegration(fn.arn)
await this.addPermission(fn.arn)
const routesPromises = map((route) => this.createRoute(integrationId, route), fn.routes)
return all(routesPromises)
}, this.functions)
return all(integrationsPromises)
}
async clearRoutes() {
const res = await this.provider.request('ApiGatewayV2', 'getRoutes', { ApiId: this.apiId })
return all(
map(
(route) =>
this.provider.request('ApiGatewayV2', 'deleteRoute', {
ApiId: this.apiId,
RouteId: route.RouteId
}),
res.Items
)
)
}
async createAuthorizers() {
const authorizerPromises = map(async (authorizerName) => {
const authorizer = this.authorizers[authorizerName]
await this.addPermission(authorizer.arn)
return this.createAuthorizer(authorizer)
}, keys(this.authorizers))
await all(authorizerPromises)
}
const deletePolicy = async (IAM, name, arn, context) => {
const { PolicyGroups, PolicyRoles, PolicyUsers } = await IAM.listEntitiesForPolicy({
PolicyArn: arn
}).promise()
await all(
PolicyGroups.map((group) => IAM.detachGroupPolicy({ GroupName: group })),
PolicyRoles.map((role) => IAM.detachRolePolicy({ RoleName: role })),
PolicyUsers.map((user) => IAM.detachUserPolicy({ UserName: user }))
)
await IAM.deletePolicy({
PolicyArn: arn
}).promise()
context.log(`Policy '${name}' deleted.`)
return null
}
const execNodeIds = async (iteratee, nodeIds, graph, context) =>
all(
reduce(
(accum, nodeId) => {
const node = graph.node(nodeId)
if (!node) {
throw new Error(`could not find node for nodeId:${nodeId}`)
}
graph.removeNode(nodeId)
return append(execNode(iteratee, node, context), accum)
},
[],
nodeIds
)
)
async clearIntegrations() {
const res = await this.provider.request('ApiGatewayV2', 'getIntegrations', { ApiId: this.apiId })
return all(
map(
(integration) =>
this.provider.request('ApiGatewayV2', 'deleteIntegration', {
ApiId: this.apiId,
IntegrationId: integration.IntegrationId
}),
res.Items
)
)
}
const integrationsPromises = map(async (fn) => {
const integrationId = await this.createIntegration(fn.arn)
await this.addPermission(fn.arn)
const routesPromises = map((route) => this.createRoute(integrationId, route), fn.routes)
return all(routesPromises)
}, this.functions)
async construct(inputs, context) {
await super.construct(inputs, context)
this.functions = await all(
mapObjIndexed(
async (func, alias) =>
context.construct(Fn, {
...func,
functionName: func.functionName || alias
}),
resolve(this.functions)
)
)
}
async clearAuthorizers() {
const res = await this.provider.request('ApiGatewayV2', 'getAuthorizers', { ApiId: this.apiId })
return all(
map(
(authorizer) =>
this.provider.request('ApiGatewayV2', 'deleteAuthorizer', {
ApiId: this.apiId,
AuthorizerId: authorizer.AuthorizerId
}),
res.Items
)
)
}