Skip to content

Commit 45e10e1

Browse files
committed
add validation feature of sqs
1 parent 0b159e9 commit 45e10e1

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const compileKinesisServiceProxy = require('./package/kinesis/compileKinesisServ
1919
// SQS
2020
const compileMethodsToSqs = require('./package/sqs/compileMethodsToSqs')
2121
const compileIamRoleToSqs = require('./package/sqs/compileIamRoleToSqs')
22-
//const validateKinesisServiceProxy = require('./package/sqs/validateKinesisServiceProxy')
22+
const validateSqsServiceProxy = require('./package/sqs/validateSqsServiceProxy')
2323
const compileSqsServiceProxy = require('./package/sqs/compileSqsServiceProxy')
2424

2525
class ServerlessApigatewayServiceProxy {
@@ -44,6 +44,7 @@ class ServerlessApigatewayServiceProxy {
4444
compileMethodsToSqs,
4545
compileIamRoleToSqs,
4646
compileSqsServiceProxy,
47+
validateSqsServiceProxy,
4748
getStackInfo,
4849
validate,
4950
methods,

lib/package/sqs/compileSqsServiceProxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22
module.exports = {
33
async compileSqsServiceProxy() {
4-
//await this.validateKinesisServiceProxy()
4+
await this.validateSqsServiceProxy()
55
await this.compileIamRoleToSqs()
66
await this.compileMethodsToSqs()
77
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict'
2+
3+
const BbPromise = require('bluebird')
4+
const _ = require('lodash')
5+
6+
module.exports = {
7+
async validateSqsServiceProxy() {
8+
await BbPromise.all(
9+
this.validated.events.map(async (serviceProxy) => {
10+
if (serviceProxy.functionName == 'sqs') {
11+
if (!_.has(serviceProxy.http, 'queueName')) {
12+
return BbPromise.reject(
13+
new this.serverless.classes.Error('Missing "queueName" property in SQS Service Proxy')
14+
)
15+
}
16+
17+
if (
18+
typeof serviceProxy.http.queueName != 'object' &&
19+
typeof serviceProxy.http.queueName != 'string'
20+
) {
21+
const errorMessage = [
22+
'You can only set "string" or the AWS "Fn::GetAtt" intrinsic function',
23+
' like { Fn::GetAtt: [ "SQSQueueResourceId", "QueueName" ] }}',
24+
' as a queueName property'
25+
].join('')
26+
return BbPromise.reject(new this.serverless.classes.Error(errorMessage))
27+
}
28+
29+
if (
30+
typeof serviceProxy.http.queueName == 'object' &&
31+
!_.has(serviceProxy.http.queueName, 'Fn::GetAtt')
32+
) {
33+
const errorMessage = [
34+
'You can only set "string" or the AWS "Fn::GetAtt" intrinsic function',
35+
' like { Fn::GetAtt: [ "SQSQueueResourceId", "QueueName" ] }}',
36+
' as a queueName property'
37+
].join('')
38+
return BbPromise.reject(new this.serverless.classes.Error(errorMessage))
39+
}
40+
}
41+
})
42+
)
43+
}
44+
}

0 commit comments

Comments
 (0)