Skip to content
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

assertions: Allow to use wildcard when specifying constructPath of Annotations #25803

Open
1 of 2 tasks
tmokmss opened this issue Jun 1, 2023 · 3 comments
Open
1 of 2 tasks
Labels
@aws-cdk/assertions Related to the @aws-cdk/assertv2 package effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@tmokmss
Copy link
Contributor

tmokmss commented Jun 1, 2023

Describe the feature

Currently we can use methods like Annotations.hasError for either 1. all the constructs or 2. one specific construct.

// 1. Find errors in every construct
Annotations.fromStack(stack).findError('*', 'foo');

// 2. Find errors in the specific path
Annotations.fromStack(stack).findError('/Stack/Some/Resource', 'foo');

Now it will be much more useful if we can specify more granular match like prefix match.

// Find errors under the specific path
Annotations.fromStack(stack).findError('/Stack/Some/Resource/*', 'foo');

Use Case

I'd like to do more granular test on a specific construct. It would be ideal if we can use something like glob pattern to specify the construct path.

For example, when using with cdk-nag, we can check the vulnerabilities only for a specific construct and its children.

Proposed Solution

Use minimatch library here instead of v.id === path. minimatch is already used in aws-cdk-lib so it should not affect bundle size.

return Object.entries(section ?? {})
.filter(([_, v]) => v.id === path)
.reduce((agg, [k, v]) => { return { ...agg, [k]: v }; }, {});

However, because we can use special characters such as * or + in a construct id, the syntax of minimatch conflicts with them. We have to consider a workaround to introduce this feature without breaking changes.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.81.0

Environment details (OS name and version, etc.)

macOS

@tmokmss tmokmss added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 1, 2023
@github-actions github-actions bot added the @aws-cdk/assertions Related to the @aws-cdk/assertv2 package label Jun 1, 2023
@peterwoodworth peterwoodworth added good first issue Related to contributions. See CONTRIBUTING.md p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 1, 2023
@peterwoodworth
Copy link
Contributor

Very reasonable request, we welcome contributions!

@tmokmss
Copy link
Contributor Author

tmokmss commented Jun 2, 2023

Thanks @peterwoodworth. Actually it turned out not to be that simple as I thought at first.

Because we can use special characters such as * or + in a construct id, the syntax of minimatch conflicts with them. Because of this, if we naively allow to use * as wildcards in constructPath arg, it can be a breaking change.

We have to consider a workaround to introduce this feature without breaking changes.

@peterwoodworth
Copy link
Contributor

Because we can use special characters such as * or + in a construct id

huh, TIL. Good catch on this

@peterwoodworth peterwoodworth removed the good first issue Related to contributions. See CONTRIBUTING.md label Jun 2, 2023
@pahud pahud added p2 and removed p1 labels Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assertions Related to the @aws-cdk/assertv2 package effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

3 participants