Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(attributes, key) => {
if (!contains(key, keys(inputs))) {
// return empty object to "unset" removed value
return concat(attributes, [{ [key]: {} }])
}
return attributes
},
[],
async prepareFunctions() {
const stackName = this.provider.naming.getStackName()
// get a list of CF outputs...
const res = await this.provider.request('CloudFormation', 'describeStacks', {
StackName: stackName
})
const outputs = res.Stacks[0].Outputs
keys(this.serverless.service.functions || {}).map((name) => {
const func = this.serverless.service.functions[name]
if (func.events && func.events.find((event) => event.websocket)) {
// find the arn of this function in the list of outputs...
const outputKey = this.provider.naming.getLambdaVersionOutputLogicalId(name)
const outputFounded = outputs.find((output) => output.OutputKey === outputKey)
if (!outputFounded) {
this.canNotFindOutputError(outputKey, stackName)
}
const arn = outputFounded.OutputValue
// get list of route keys configured for this function
const routes = map((e) => {
if (e.websocket.authorizer && e.websocket.authorizer.name && !this.authorizers[e.websocket.authorizer.name]) {
const authorizerOutputKey = this.provider.naming.getLambdaVersionOutputLogicalId(e.websocket.authorizer.name)
const evaluateVariableString = (variableString, data) => {
const { exact, match, expression } = matchVariable(variableString)
if (!match) {
return variableString
}
const resolvedExpression = evaluateVariableString(expression, data)
const self = get('this', data)
data = omit(['this'], data)
const params = concat(keys(data), UTIL_METHODS.KEYS)
const args = concat(values(data), UTIL_METHODS.VALUES)
const func = new Function(params, `return ${resolvedExpression}`)
let value = func.apply(self, args)
if (!exact) {
value = variableString.replace(match, value)
}
return value
}
const printObj = (obj, log, level = 0) => {
if (!obj) {
return
}
const subLog = (line) => log(` ${line}`)
if (
(keys(obj).length === 3 || (keys(obj).length === 4 && obj.children)) &&
obj.title &&
obj.type &&
obj.data
) {
if (isArray(obj.data)) {
printArray(compact(obj.data), subLog, level + 1)
} else {
printObj(compact(obj.data), subLog, level)
}
if (obj.children && level <= 1) {
if (isArray(obj.children)) {
printArray(compact(obj.children), subLog)
} else {
printObj(compact(obj.children), subLog)
}
}
shouldDeploy(prevInstance) {
if (!prevInstance) {
return 'deploy'
}
const inputs = {
topic: this.topic,
protocol: this.protocol,
endpoint: this.endpoint,
subscriptionAttributes: this.subscriptionAttributes
}
const prevInputs = prevInstance ? pick(keys(inputs), prevInstance) : {}
const configChanged = not(equals(inputs, prevInputs))
if (
not(equals(prevInstance.protocol, inputs.protocol)) ||
not(equals(prevInstance.topic, inputs.topic))
) {
return 'replace'
} else if (configChanged) {
return 'deploy'
}
return undefined
}
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 children = get('children', component)
if (children) {
return reduce(
(accum, childKey) => {
const instanceId = resolve(get('instanceId', children[childKey]))
if (isNil(instanceId)) {
throw new Error(
`Found a child without an instanceId while getting children ids. This should not happen. The child was ${
children[childKey]
} and belongs to parent ${component}`
)
}
return append(instanceId, accum)
},
[],
keys(children)
)
}
return []
}