UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 3.63 kB
"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.HttpLambdaAuthorizer=exports.HttpLambdaResponseType=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var aws_apigatewayv2_1=()=>{var tmp=require("../../../aws-apigatewayv2");return aws_apigatewayv2_1=()=>tmp,tmp},aws_iam_1=()=>{var tmp=require("../../../aws-iam");return aws_iam_1=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../../../core/lib/errors");return errors_1=()=>tmp,tmp},HttpLambdaResponseType;(function(HttpLambdaResponseType2){HttpLambdaResponseType2[HttpLambdaResponseType2.SIMPLE=0]="SIMPLE",HttpLambdaResponseType2[HttpLambdaResponseType2.IAM=1]="IAM"})(HttpLambdaResponseType||(exports.HttpLambdaResponseType=HttpLambdaResponseType={}));class HttpLambdaAuthorizer{constructor(id,handler,props={}){this.id=id,this.handler=handler,this.props=props,this.authorizationType="CUSTOM";try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_IFunction(handler),jsiiDeprecationWarnings().aws_cdk_lib_aws_apigatewayv2_authorizers_HttpLambdaAuthorizerProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,HttpLambdaAuthorizer),error}}get authorizerId(){if(!this.authorizer)throw new(errors_1()).UnscopedValidationError("Cannot access authorizerId until authorizer is attached to a HttpRoute");return this.authorizer.authorizerId}bind(options){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_apigatewayv2_HttpRouteAuthorizerBindOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}if(this.httpApi&&this.httpApi.apiId!==options.route.httpApi.apiId)throw new(errors_1()).ValidationError("Cannot attach the same authorizer to multiple Apis",options.scope);if(!this.authorizer){const enableSimpleResponses=(this.props.responseTypes??[HttpLambdaResponseType.IAM]).includes(HttpLambdaResponseType.SIMPLE)||void 0;this.httpApi=options.route.httpApi,this.authorizer=new(aws_apigatewayv2_1()).HttpAuthorizer(options.scope,this.id,{httpApi:options.route.httpApi,identitySource:this.props.identitySource??["$request.header.Authorization"],type:aws_apigatewayv2_1().HttpAuthorizerType.LAMBDA,authorizerName:this.props.authorizerName??this.id,enableSimpleResponses,payloadFormatVersion:enableSimpleResponses?aws_apigatewayv2_1().AuthorizerPayloadVersion.VERSION_2_0:aws_apigatewayv2_1().AuthorizerPayloadVersion.VERSION_1_0,authorizerUri:lambdaAuthorizerArn(this.handler),resultsCacheTtl:this.props.resultsCacheTtl??core_1().Duration.minutes(5)}),this.handler.addPermission(`${core_1().Names.nodeUniqueId(this.authorizer.node)}-Permission`,{scope:options.scope,principal:new(aws_iam_1()).ServicePrincipal("apigateway.amazonaws.com"),sourceArn:core_1().Stack.of(options.route).formatArn({service:"execute-api",resource:options.route.httpApi.apiId,resourceName:`authorizers/${this.authorizer.authorizerId}`})})}return{authorizerId:this.authorizer.authorizerId,authorizationType:this.authorizationType}}}exports.HttpLambdaAuthorizer=HttpLambdaAuthorizer,_a=JSII_RTTI_SYMBOL_1,HttpLambdaAuthorizer[_a]={fqn:"aws-cdk-lib.aws_apigatewayv2_authorizers.HttpLambdaAuthorizer",version:"2.185.0"};function lambdaAuthorizerArn(handler){return`arn:${core_1().Stack.of(handler).partition}:apigateway:${core_1().Stack.of(handler).region}:lambda:path/2015-03-31/functions/${handler.functionArn}/invocations`}