@@ -15,25 +15,6 @@ export const DENY_ALL_RESPONSE: AwsPolicy = {
1515 } ,
1616} ;
1717
18- export function buildRouteArn (
19- region : string ,
20- awsAccountId : string ,
21- apiId : string ,
22- stage : string ,
23- method : string ,
24- path : string
25- ) : string {
26- // Clean all starting / from path
27- while ( path . startsWith ( "/" ) ) {
28- path = path . substring ( 1 , path . length ) ;
29- }
30-
31- // Match regex with path variables and replace them with "*"
32- const regex = / { [ a - z A - Z _ $ ] + [ a - z A - Z 0 - 9 _ $ ] * } / g;
33- path = path . replace ( regex , "*" ) ;
34- return `arn:aws:execute-api:${ region } :${ awsAccountId } :${ apiId } /${ stage } /${ method } /${ path } ` ;
35- }
36-
3718export type ApiGatewayArnParts = {
3819 region : string ;
3920 awsAccountId : string ;
@@ -171,6 +152,25 @@ export class AuthorizerResponse {
171152 } ;
172153 }
173154
155+ public static buildRouteArn (
156+ region : string ,
157+ awsAccountId : string ,
158+ apiId : string ,
159+ stage : string ,
160+ method : string ,
161+ path : string
162+ ) : string {
163+ // Clean all starting / from path
164+ while ( path . startsWith ( "/" ) ) {
165+ path = path . substring ( 1 , path . length ) ;
166+ }
167+
168+ // Match regex with path variables and replace them with "*"
169+ const regex = / { [ a - z A - Z _ $ ] + [ a - z A - Z 0 - 9 _ $ ] * } / g;
170+ path = path . replace ( regex , "*" ) ;
171+ return `arn:aws:execute-api:${ region } :${ awsAccountId } :${ apiId } /${ stage } /${ method } /${ path } ` ;
172+ }
173+
174174 public static fromMethodArn (
175175 principalId : string ,
176176 arn : string ,
@@ -229,7 +229,7 @@ export class AuthorizerResponse {
229229 }
230230 if ( effect === "Allow" ) {
231231 this . allowedRoutes . push ( {
232- resourceArn : buildRouteArn (
232+ resourceArn : AuthorizerResponse . buildRouteArn (
233233 this . region ,
234234 this . awsAccountId ,
235235 this . apiId ,
@@ -241,7 +241,7 @@ export class AuthorizerResponse {
241241 } ) ;
242242 } else {
243243 this . deniedRoutes . push ( {
244- resourceArn : buildRouteArn (
244+ resourceArn : AuthorizerResponse . buildRouteArn (
245245 this . region ,
246246 this . awsAccountId ,
247247 this . apiId ,
0 commit comments