Skip to content

Commit fca45f6

Browse files
committed
feat: Recognize provider.apiGateway.usagePlan
1 parent eb2b892 commit fca45f6

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/deploy/events/apiGateway/usagePlan.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const BbPromise = require('bluebird');
55

66
module.exports = {
77
compileUsagePlan() {
8-
if (this.serverless.service.provider.usagePlan
8+
const usagePlan = _.get(this.serverless.service.provider.apiGateway, 'usagePlan')
9+
|| this.serverless.service.provider.usagePlan;
10+
if (usagePlan
911
|| _.get(this.serverless.service.provider.apiGateway, 'apiKeys')
1012
|| this.serverless.service.provider.apiKeys) {
1113
this.apiGatewayUsagePlanLogicalId = this.provider.naming.getUsagePlanLogicalId();
@@ -29,28 +31,26 @@ module.exports = {
2931
},
3032
},
3133
});
32-
if (_.has(this.serverless.service.provider, 'usagePlan.quota')
33-
&& this.serverless.service.provider.usagePlan.quota !== null) {
34+
if (_.has(usagePlan, 'quota') && usagePlan.quota !== null) {
3435
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
3536
[this.apiGatewayUsagePlanLogicalId]: {
3637
Properties: {
3738
Quota: _.merge(
38-
{ Limit: this.serverless.service.provider.usagePlan.quota.limit },
39-
{ Offset: this.serverless.service.provider.usagePlan.quota.offset },
40-
{ Period: this.serverless.service.provider.usagePlan.quota.period },
39+
{ Limit: usagePlan.quota.limit },
40+
{ Offset: usagePlan.quota.offset },
41+
{ Period: usagePlan.quota.period },
4142
),
4243
},
4344
},
4445
});
4546
}
46-
if (_.has(this.serverless.service.provider, 'usagePlan.throttle')
47-
&& this.serverless.service.provider.usagePlan.throttle !== null) {
47+
if (_.has(usagePlan, 'throttle') && usagePlan.throttle !== null) {
4848
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
4949
[this.apiGatewayUsagePlanLogicalId]: {
5050
Properties: {
5151
Throttle: _.merge(
52-
{ BurstLimit: this.serverless.service.provider.usagePlan.throttle.burstLimit },
53-
{ RateLimit: this.serverless.service.provider.usagePlan.throttle.rateLimit },
52+
{ BurstLimit: usagePlan.throttle.burstLimit },
53+
{ RateLimit: usagePlan.throttle.rateLimit },
5454
),
5555
},
5656
},

lib/deploy/events/apiGateway/usagePlan.test.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ describe('#compileUsagePlan()', () => {
8484
});
8585

8686
it('should compile custom usage plan resource', () => {
87-
serverless.service.provider.usagePlan = {
88-
quota: {
89-
limit: 500,
90-
offset: 10,
91-
period: 'MONTH',
92-
},
93-
throttle: {
94-
burstLimit: 200,
95-
rateLimit: 100,
87+
serverless.service.provider.apiGateway = {
88+
usagePlan: {
89+
quota: {
90+
limit: 500,
91+
offset: 10,
92+
period: 'MONTH',
93+
},
94+
throttle: {
95+
burstLimit: 200,
96+
rateLimit: 100,
97+
},
9698
},
9799
};
98100

0 commit comments

Comments
 (0)