22
33const BbPromise = require ( 'bluebird' ) ;
44const _ = require ( 'lodash' ) ;
5+ const awsArnRegExs = require ( '../../../utils/arnRegularExpressions' ) ;
6+
57
68module . 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