UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 3.75 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TableGrants=void 0;var jsiiDeprecationWarnings=()=>{var tmp=require("../../.warnings.jsii.js");return jsiiDeprecationWarnings=()=>tmp,tmp};const JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti");var perms=()=>{var tmp=require("./perms");return perms=()=>tmp,tmp},iam=()=>{var tmp=require("../../aws-iam");return iam=()=>tmp,tmp},core_1=()=>{var tmp=require("../../core");return core_1=()=>tmp,tmp};class TableGrants{static[JSII_RTTI_SYMBOL_1]={fqn:"aws-cdk-lib.aws_dynamodb.TableGrants",version:"2.233.0"};table;arns=[];encryptedResource;policyResource;constructor(props){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_dynamodb_TableGrantsProps(props)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,TableGrants),error}this.table=props.table,this.encryptedResource=props.encryptedResource,this.policyResource=props.policyResource;const stack=core_1().Stack.of(this.table);this.arns=[this.table.tableRef.tableArn,...(props.regions??[]).map(region=>stack.formatArn({region,service:"dynamodb",resource:"table",resourceName:this.table.tableRef.tableName}))],props.hasIndex&&this.arns.push(...this.arns.map(arn=>`${arn}/index/*`))}actions(grantee,...actions){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.actions),error}return this.policyResource?iam().Grant.addToPrincipalOrResource({grantee,actions,resourceArns:this.arns,resource:this.policyResource,resourceSelfArns:["*"]}):iam().Grant.addToPrincipal({grantee,actions,resourceArns:this.arns})}readData(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.readData),error}const actions=[...perms().RESOURCE_READ_DATA_ACTIONS,perms().DESCRIBE_TABLE];return this.encryptedResource?.grantOnKey(grantee,...perms().KEY_READ_ACTIONS),this.actions(grantee,...actions).combine(iam().Grant.addToPrincipal({grantee,actions:perms().PRINCIPAL_ONLY_READ_DATA_ACTIONS,resourceArns:this.arns}))}writeData(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.writeData),error}const actions=[...perms().WRITE_DATA_ACTIONS,perms().DESCRIBE_TABLE],result=this.actions(grantee,...actions);return this.encryptedResource?.grantOnKey(grantee,...perms().KEY_READ_ACTIONS,...perms().KEY_WRITE_ACTIONS),result}readWriteData(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.readWriteData),error}const actions=[...perms().RESOURCE_READ_DATA_ACTIONS,...perms().WRITE_DATA_ACTIONS,perms().DESCRIBE_TABLE],result=this.actions(grantee,...actions);return this.encryptedResource?.grantOnKey(grantee,...perms().KEY_READ_ACTIONS,...perms().KEY_WRITE_ACTIONS),result.combine(iam().Grant.addToPrincipal({grantee,actions:perms().PRINCIPAL_ONLY_READ_DATA_ACTIONS,resourceArns:this.arns}))}fullAccess(grantee){try{jsiiDeprecationWarnings().aws_cdk_lib_aws_iam_IGrantable(grantee)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.fullAccess),error}const actions=["dynamodb:*"],result=this.actions(grantee,...actions);return this.encryptedResource?.grantOnKey(grantee,...perms().KEY_READ_ACTIONS,...perms().KEY_WRITE_ACTIONS),result}}exports.TableGrants=TableGrants;