-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathutils.js
39 lines (35 loc) · 1.22 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
module.exports = {
getAllServiceProxies() {
if (this.serverless.service.custom && this.serverless.service.custom.apiGatewayServiceProxies) {
return this.serverless.service.custom.apiGatewayServiceProxies
}
return []
},
getServiceName(serviceProxy) {
return Object.keys(serviceProxy)[0]
},
addCors(http, integrationResponse) {
if (http && http.cors) {
let origin = http.cors.origin
if (http.cors.origins && http.cors.origins.length) {
origin = http.cors.origins.join(',')
}
const corsKey = 'method.response.header.Access-Control-Allow-Origin'
integrationResponse.IntegrationResponses.forEach((val, i) => {
integrationResponse.IntegrationResponses[i].ResponseParameters[corsKey] = `'${origin}'`
})
}
},
shouldCreateDefaultRole(serviceName) {
const proxies = this.getAllServiceProxies().filter(
(serviceProxy) => this.getServiceName(serviceProxy) === serviceName
)
if (proxies.length <= 0) {
return false
}
// if some proxies don't have a custom role defined we should create the default one
const createDefaultRole = proxies.some((proxy) => !proxy[serviceName].roleArn)
return createDefaultRole
}
}