Skip to content

Commit ebaf2fd

Browse files
committed
WIP: add getMethodAuthorization method
1 parent af774da commit ebaf2fd

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

lib/deploy/events/apiGateway/authorizers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ const awsArnRegExs = require('../../../utils/arnRegularExpressions');
66

77
module.exports = {
88
compileAuthorizers() {
9+
console.log("*** compileAuthorizers")
910
this.pluginhttpValidated.events.forEach((event) => {
11+
console.log(event)
12+
13+
1014
if (event.http.authorizer && event.http.authorizer.arn) {
1115
const authorizer = event.http.authorizer;
1216
const authorizerProperties = {

lib/deploy/events/apiGateway/methods.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const BbPromise = require('bluebird');
44
const _ = require('lodash');
5+
const awsArnRegExs = require('../../../utils/arnRegularExpressions');
6+
57

68
module.exports = {
79

@@ -17,7 +19,7 @@ module.exports = {
1719
Properties: {
1820
HttpMethod: event.http.method.toUpperCase(),
1921
RequestParameters: {},
20-
AuthorizationType: 'NONE',
22+
AuthorizationType: 'CUSTOM',
2123
ApiKeyRequired: Boolean(event.http.private),
2224
ResourceId: resourceId,
2325
RestApiId: this.provider.getApiGatewayRestApiId(),
@@ -26,7 +28,8 @@ module.exports = {
2628

2729
_.merge(template,
2830
this.getMethodIntegration(event.stateMachineName, stateMachineObj, event.http),
29-
this.getMethodResponses(event.http)
31+
this.getMethodResponses(event.http),
32+
this.getMethodAuthorization(event.http)
3033
);
3134

3235
const methodLogicalId = this.provider.naming
@@ -179,4 +182,64 @@ module.exports = {
179182

180183
return methodResponse;
181184
},
185+
186+
getMethodAuthorization(http) {
187+
console.log('*** http')
188+
console.log(http)
189+
if (_.get(http, 'authorizer.type') === 'AWS_IAM') {
190+
return {
191+
Properties: {
192+
AuthorizationType: 'AWS_IAM',
193+
},
194+
};
195+
}
196+
197+
if (http.authorizer) {
198+
if (http.authorizer.type && http.authorizer.authorizerId) {
199+
return {
200+
Properties: {
201+
AuthorizationType: http.authorizer.type,
202+
AuthorizerId: http.authorizer.authorizerId,
203+
},
204+
};
205+
}
206+
// if (http.authorizer && awsArnRegExs.lambdaArnExpr.test(http.authorizer)) {
207+
if (http.authorizer && typeof(http.authorizer) === 'string') {
208+
return {
209+
Properties: {
210+
AuthorizationType: 'CUSTOM',
211+
AuthorizerId: http.authorizer,
212+
ApiKeyRequired: true,
213+
// AuthorizerId: { Ref: http.authorizer } ,
214+
},
215+
};
216+
}
217+
218+
const authorizerLogicalId = this.provider.naming
219+
.getAuthorizerLogicalId(http.authorizer.name);
220+
221+
let authorizationType;
222+
const authorizerArn = http.authorizer.arn;
223+
if (typeof authorizerArn === 'string'
224+
&& awsArnRegExs.cognitoIdpArnExpr.test(authorizerArn)) {
225+
authorizationType = 'COGNITO_USER_POOLS';
226+
} else {
227+
authorizationType = 'CUSTOM';
228+
}
229+
230+
return {
231+
Properties: {
232+
AuthorizationType: authorizationType,
233+
AuthorizerId: { Ref: authorizerLogicalId },
234+
},
235+
DependsOn: authorizerLogicalId,
236+
};
237+
}
238+
239+
return {
240+
Properties: {
241+
AuthorizationType: 'NONE',
242+
},
243+
};
244+
},
182245
};

0 commit comments

Comments
 (0)