Skip to content

Commit f8105e1

Browse files
authored
Merge pull request #108 from vonpoland/feature/add-private-mode-to-http-events
Added handling of 'private' param to http events.
2 parents b1b182c + b1435a2 commit f8105e1

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/deploy/events/apiGateway/methods.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
HttpMethod: event.http.method.toUpperCase(),
1919
RequestParameters: {},
2020
AuthorizationType: 'NONE',
21+
ApiKeyRequired: Boolean(event.http.private),
2122
ResourceId: resourceId,
2223
RestApiId: { Ref: this.apiGatewayRestApiLogicalId },
2324
},

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,25 @@ describe('#methods()', () => {
2828
};
2929
serverlessStepFunctions.apiGatewayResourceLogicalIds
3030
= { 'foo/bar': 'apiGatewayResourceLogicalId' };
31-
serverlessStepFunctions.apiGatewayResourceNames
32-
= { 'foo/bar': 'apiGatewayResourceNames' };
31+
serverlessStepFunctions.apiGatewayResourceNames = {
32+
'foo/bar1': 'apiGatewayResourceNamesFirst',
33+
'foo/bar2': 'apiGatewayResourceNamesSecond',
34+
};
3335
serverlessStepFunctions.pluginhttpValidated = {
3436
events: [
3537
{
3638
stateMachineName: 'first',
3739
http: {
38-
path: 'foo/bar',
40+
path: 'foo/bar1',
41+
method: 'post',
42+
},
43+
},
44+
{
45+
stateMachineName: 'first',
46+
http: {
47+
path: 'foo/bar2',
3948
method: 'post',
49+
private: true,
4050
},
4151
},
4252
],
@@ -48,9 +58,22 @@ describe('#methods()', () => {
4858
.compileMethods().then(() => {
4959
expect(serverlessStepFunctions.serverless.service.provider.compiledCloudFormationTemplate
5060
.Resources)
51-
.to.have.property('ApiGatewayMethodapiGatewayResourceNamesPost');
61+
.to.have.property('ApiGatewayMethodapiGatewayResourceNamesFirstPost');
5262
})
5363
);
64+
65+
it('should verify if http private parameter is correctly passed to resource',
66+
() => serverlessStepFunctions
67+
.compileMethods().then(() => {
68+
const resources = serverlessStepFunctions
69+
.serverless.service.provider.compiledCloudFormationTemplate.Resources;
70+
71+
expect(resources.ApiGatewayMethodapiGatewayResourceNamesFirstPost
72+
.Properties.ApiKeyRequired).to.eql(false);
73+
expect(resources.ApiGatewayMethodapiGatewayResourceNamesSecondPost
74+
.Properties.ApiKeyRequired).to.eql(true);
75+
})
76+
);
5477
});
5578

5679
describe('#getMethodIntegration()', () => {

0 commit comments

Comments
 (0)