-
Couldn't load subscription status.
- Fork 4.3k
feat(s3tables-alpha): add TablePolicy support to L2 construct library #35223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d186097
Add TablePolicy support to L2 Constructs
f8077ee
Merge branch 'main' into table-policy
xuxey 39be7d8
Fix docs wording around table resources
d56bdca
Add abstract names in table grant integ tests
b326f44
Remove unused tablePolicy reference in tests
4e05ba1
Assert that policies are not added for an imported table
2598f61
Add assertion for policy returned from addToResourcePolicy
cb5b53b
Merge branch 'main' into table-policy
xuxey 27fd02f
Aseert undefined policy returned from addToResourcePolicy failure
aa4c18d
Merge branch 'main' into table-policy
xuxey 63ff7fc
Merge branch 'main' into table-policy
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { Construct } from 'constructs'; | ||
| import { CfnTablePolicy } from 'aws-cdk-lib/aws-s3tables'; | ||
| import * as iam from 'aws-cdk-lib/aws-iam'; | ||
| import { RemovalPolicy, Resource } from 'aws-cdk-lib/core'; | ||
| import { ITable } from './table'; | ||
| import { addConstructMetadata } from 'aws-cdk-lib/core/lib/metadata-resource'; | ||
| import { propertyInjectable } from 'aws-cdk-lib/core/lib/prop-injectable'; | ||
|
|
||
| /** | ||
| * Parameters for constructing a TablePolicy | ||
| */ | ||
| export interface TablePolicyProps { | ||
| /** | ||
| * The associated table | ||
| */ | ||
| readonly table: ITable; | ||
| /** | ||
| * The policy document for the table's resource policy | ||
| * @default undefined An empty iam.PolicyDocument will be initialized | ||
| */ | ||
| readonly resourcePolicy?: iam.PolicyDocument; | ||
| /** | ||
| * Policy to apply when the policy is removed from this stack. | ||
| * | ||
| * @default - RemovalPolicy.DESTROY. | ||
| */ | ||
| readonly removalPolicy?: RemovalPolicy; | ||
| } | ||
|
|
||
| /** | ||
| * A Policy for S3 Tables. | ||
| * | ||
| * You will almost never need to use this construct directly. | ||
| * Instead, Table.addToResourcePolicy can be used to add more policies to your table directly | ||
| */ | ||
| @propertyInjectable | ||
| export class TablePolicy extends Resource { | ||
| /** Uniquely identifies this class. */ | ||
| public static readonly PROPERTY_INJECTION_ID: string = '@aws-cdk.aws-s3tables-alpha.TablePolicy'; | ||
| /** | ||
| * The IAM PolicyDocument containing permissions represented by this policy. | ||
| */ | ||
| public readonly document: iam.PolicyDocument; | ||
| /** | ||
| * @internal The underlying policy resource. | ||
| */ | ||
| private readonly _resource: CfnTablePolicy; | ||
|
|
||
| constructor(scope: Construct, id: string, props: TablePolicyProps) { | ||
| super(scope, id); | ||
| // Enhanced CDK Analytics Telemetry | ||
| addConstructMetadata(this, props); | ||
|
|
||
| // Use default policy if not provided with props | ||
| this.document = props.resourcePolicy || new iam.PolicyDocument({}); | ||
|
|
||
| this._resource = new CfnTablePolicy(this, id, { | ||
| tableArn: props.table.tableArn, | ||
| resourcePolicy: this.document, | ||
| }); | ||
|
|
||
| if (props.removalPolicy) { | ||
| this._resource.applyRemovalPolicy(props.removalPolicy); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ith-grants.js.snapshot/TableWithGrantIntegTestDefaultTestDeployAssertE9880469.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.