Skip to content

Commit eb2b892

Browse files
committed
feat: Recognize provider.apiGateway.resourcePolicy
1 parent 7ac5897 commit eb2b892

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

lib/deploy/events/apiGateway/restApi.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ module.exports = {
4343
},
4444
});
4545

46-
if (!_.isEmpty(this.serverless.service.provider.resourcePolicy)) {
46+
const resourcePolicy = _.get(this.serverless.service.provider.apiGateway, 'resourcePolicy')
47+
|| this.serverless.service.provider.resourcePolicy;
48+
49+
if (!_.isEmpty(resourcePolicy)) {
4750
const policy = {
4851
Version: '2012-10-17',
49-
Statement: this.serverless.service.provider.resourcePolicy,
52+
Statement: resourcePolicy,
5053
};
5154
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate
5255
.Resources[this.apiGatewayRestApiLogicalId].Properties, {

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,21 @@ describe('#compileRestApi()', () => {
8989
}));
9090

9191
it('should create a REST API resource with resource policy', () => {
92-
serverlessStepFunctions.serverless.service.provider.resourcePolicy = [
93-
{
94-
Effect: 'Allow',
95-
Principal: '*',
96-
Action: 'execute-api:Invoke',
97-
Resource: ['execute-api:/*/*/*'],
98-
Condition: {
99-
IpAddress: {
100-
'aws:SourceIp': ['123.123.123.123'],
92+
serverlessStepFunctions.serverless.service.provider.apiGateway = {
93+
resourcePolicy: [
94+
{
95+
Effect: 'Allow',
96+
Principal: '*',
97+
Action: 'execute-api:Invoke',
98+
Resource: ['execute-api:/*/*/*'],
99+
Condition: {
100+
IpAddress: {
101+
'aws:SourceIp': ['123.123.123.123'],
102+
},
101103
},
102104
},
103-
},
104-
];
105+
],
106+
};
105107
return serverlessStepFunctions.compileRestApi().then(() => {
106108
expect(serverlessStepFunctions.serverless.service.provider
107109
.compiledCloudFormationTemplate.Resources).to.deep.equal(

0 commit comments

Comments
 (0)