"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GlueSchemaRegistry=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var iam=()=>{var tmp=require("../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp},literal_string_1=()=>{var tmp=require("../../core/lib/private/literal-string");return literal_string_1=()=>tmp,tmp};const GLUE_SCHEMA_REGISTRY_ARN_REGEX=/^arn:[^:]+:glue:[^:]+:[^:]+:registry\/([^\/]+)$/;class GlueSchemaRegistry{props;static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_lambda_event_sources.GlueSchemaRegistry",version:"2.256.1"};constructor(props){this.props=props;try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_event_sources_GlueSchemaRegistryProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,GlueSchemaRegistry),error}}bind(_target,targetHandler){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_IEventSourceMapping(_target),jsiiDeprecationWarnings().aws_cdk_lib_aws_lambda_IFunction(targetHandler)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.bind),error}const registryProps=this.getRegistryProps(this.props,_target);return this.getSchemaRegistryPolicies(registryProps.arn,registryProps.name).forEach(i=>targetHandler.addToRolePolicy(i)),{schemaRegistryUri:registryProps.arn,eventRecordFormat:this.props.eventRecordFormat,schemaValidationConfigs:this.props.schemaValidationConfigs}}getRegistryProps(props,_target){if(props.schemaRegistry)return{arn:props.schemaRegistry.attrArn,name:props.schemaRegistry.name};if(props.schemaRegistryArn){const glueRegistryMatch=props.schemaRegistryArn?.match(GLUE_SCHEMA_REGISTRY_ARN_REGEX);if(!glueRegistryMatch)throw new(core_1()).ValidationError((0,literal_string_1().lit)`SchemaRegistryArn`,`schemaRegistryArn ${this.props.schemaRegistryArn} must match ${GLUE_SCHEMA_REGISTRY_ARN_REGEX}`,_target);return{arn:props.schemaRegistryArn,name:glueRegistryMatch[1]}}throw new(core_1()).ValidationError((0,literal_string_1().lit)`OneSchemaRegistryArnSchema`,"one of schemaRegistryArn or schemaRegistry must be passed",_target)}getSchemaRegistryPolicies(glueRegistryArn,glueRegistryName){return[new(iam()).PolicyStatement({actions:["glue:GetRegistry"],resources:[glueRegistryArn]}),new(iam()).PolicyStatement({actions:["glue:GetSchemaVersion"],resources:[glueRegistryArn,core_1().Fn.sub("arn:${AWS::Partition}:glue:${AWS::Region}:${AWS::AccountId}:schema/${registryName}/*",{registryName:glueRegistryName})]})]}}exports.GlueSchemaRegistry=GlueSchemaRegistry;
