File tree 6 files changed +23
-15
lines changed
lib/deploy/events/apiGateway 6 files changed +23
-15
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ const BbPromise = require('bluebird');
5
5
6
6
module . exports = {
7
7
compileApiKeys ( ) {
8
- if ( this . serverless . service . provider . apiKeys ) {
9
- if ( ! Array . isArray ( this . serverless . service . provider . apiKeys ) ) {
8
+ const apiKeys = _ . get ( this . serverless . service . provider . apiGateway , 'apiKeys' )
9
+ || this . serverless . service . provider . apiKeys ;
10
+ if ( apiKeys ) {
11
+ if ( ! Array . isArray ( apiKeys ) ) {
10
12
throw new this . serverless . classes . Error ( 'apiKeys property must be an array' ) ;
11
13
}
12
14
13
- _ . forEach ( this . serverless . service . provider . apiKeys , ( apiKey , i ) => {
15
+ _ . forEach ( apiKeys , ( apiKey , i ) => {
14
16
const apiKeyNumber = i + 1 ;
15
17
16
18
if ( typeof apiKey !== 'string' ) {
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ describe('#methods()', () => {
16
16
region : 'us-east-1' ,
17
17
} ;
18
18
serverless . setProvider ( 'aws' , new AwsProvider ( serverless ) ) ;
19
- serverless . service . provider . apiKeys = [ '1234567890' ] ;
19
+ if ( ! serverless . service . provider . apiGateway ) serverless . service . provider . apiGateway = { } ;
20
+ serverless . service . provider . apiGateway . apiKeys = [ '1234567890' ] ;
20
21
serverless . service . provider . compiledCloudFormationTemplate = {
21
22
Resources : { } ,
22
23
} ;
@@ -79,12 +80,12 @@ describe('#methods()', () => {
79
80
} ) ) ;
80
81
81
82
it ( 'throw error if apiKey property is not an array' , ( ) => {
82
- serverlessStepFunctions . serverless . service . provider . apiKeys = 2 ;
83
+ serverlessStepFunctions . serverless . service . provider . apiGateway . apiKeys = 2 ;
83
84
expect ( ( ) => serverlessStepFunctions . compileApiKeys ( ) ) . to . throw ( Error ) ;
84
85
} ) ;
85
86
86
87
it ( 'throw error if an apiKey is not a string' , ( ) => {
87
- serverlessStepFunctions . serverless . service . provider . apiKeys = [ 2 ] ;
88
+ serverlessStepFunctions . serverless . service . provider . apiGateway . apiKeys = [ 2 ] ;
88
89
expect ( ( ) => serverlessStepFunctions . compileApiKeys ( ) ) . to . throw ( Error ) ;
89
90
} ) ;
90
91
} ) ;
Original file line number Diff line number Diff line change @@ -5,7 +5,9 @@ const BbPromise = require('bluebird');
5
5
6
6
module . exports = {
7
7
compileUsagePlan ( ) {
8
- if ( this . serverless . service . provider . usagePlan || this . serverless . service . provider . apiKeys ) {
8
+ if ( this . serverless . service . provider . usagePlan
9
+ || _ . get ( this . serverless . service . provider . apiGateway , 'apiKeys' )
10
+ || this . serverless . service . provider . apiKeys ) {
9
11
this . apiGatewayUsagePlanLogicalId = this . provider . naming . getUsagePlanLogicalId ( ) ;
10
12
_ . merge ( this . serverless . service . provider . compiledCloudFormationTemplate . Resources , {
11
13
[ this . apiGatewayUsagePlanLogicalId ] : {
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ describe('#compileUsagePlan()', () => {
17
17
} ;
18
18
serverless . service . service = 'first-service' ;
19
19
serverless . setProvider ( 'aws' , new AwsProvider ( serverless ) ) ;
20
- serverless . service . provider . apiKeys = [ '1234567890' ] ;
20
+ if ( ! serverless . service . provider . apiGateway ) serverless . service . provider . apiGateway = { } ;
21
+ serverless . service . provider . apiGateway . apiKeys = [ '1234567890' ] ;
21
22
serverless . service . provider . compiledCloudFormationTemplate = {
22
23
Resources : { } ,
23
24
} ;
@@ -36,7 +37,7 @@ describe('#compileUsagePlan()', () => {
36
37
} ) ;
37
38
38
39
it ( 'should compile default usage plan resource' , ( ) => {
39
- serverless . service . provider . apiKeys = [ '1234567890' ] ;
40
+ serverless . service . provider . apiGateway . apiKeys = [ '1234567890' ] ;
40
41
return serverlessStepFunctions . compileUsagePlan ( ) . then ( ( ) => {
41
42
expect (
42
43
serverlessStepFunctions . serverless . service . provider . compiledCloudFormationTemplate
Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ const BbPromise = require('bluebird');
5
5
6
6
module . exports = {
7
7
compileUsagePlanKeys ( ) {
8
- if ( this . serverless . service . provider . apiKeys ) {
9
- if ( ! Array . isArray ( this . serverless . service . provider . apiKeys ) ) {
8
+ const apiKeys = _ . get ( this . serverless . service . provider . apiGateway , 'apiKeys' )
9
+ || this . serverless . service . provider . apiKeys ;
10
+ if ( apiKeys ) {
11
+ if ( ! Array . isArray ( apiKeys ) ) {
10
12
throw new this . serverless . classes . Error ( 'apiKeys property must be an array' ) ;
11
13
}
12
14
13
- _ . forEach ( this . serverless . service . provider . apiKeys , ( apiKey , i ) => {
15
+ _ . forEach ( apiKeys , ( apiKey , i ) => {
14
16
const usagePlanKeyNumber = i + 1 ;
15
17
16
18
if ( typeof apiKey !== 'string' ) {
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ describe('#compileUsagePlanKeys()', () => {
19
19
serverless . service . service = 'first-service' ;
20
20
serverless . service . provider = {
21
21
name : 'aws' ,
22
- apiKeys : [ '1234567890' ] ,
22
+ apiGateway : { apiKeys : [ '1234567890' ] } ,
23
23
} ;
24
24
serverless . service . provider . compiledCloudFormationTemplate = {
25
25
Resources : { } ,
@@ -66,12 +66,12 @@ describe('#compileUsagePlanKeys()', () => {
66
66
} ) ) ;
67
67
68
68
it ( 'throw error if apiKey property is not an array' , ( ) => {
69
- serverlessStepFunctions . serverless . service . provider . apiKeys = 2 ;
69
+ serverlessStepFunctions . serverless . service . provider . apiGateway . apiKeys = 2 ;
70
70
expect ( ( ) => serverlessStepFunctions . compileUsagePlanKeys ( ) ) . to . throw ( Error ) ;
71
71
} ) ;
72
72
73
73
it ( 'throw error if an apiKey is not a string' , ( ) => {
74
- serverlessStepFunctions . serverless . service . provider . apiKeys = [ 2 ] ;
74
+ serverlessStepFunctions . serverless . service . provider . apiGateway . apiKeys = [ 2 ] ;
75
75
expect ( ( ) => serverlessStepFunctions . compileUsagePlanKeys ( ) ) . to . throw ( Error ) ;
76
76
} ) ;
77
77
} ) ;
You can’t perform that action at this time.
0 commit comments