-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(core): convert "/" in construct id to "--" and disallow tokens #1375
Conversation
Relax construct ID constraints to allow "/" (path seprator) to be used in construct IDs, but convert it to "--" so it won't collide with path strings. It's quite rare for people to actually try to find a construct by their ID (it's mostly "write-only") and the logical ID is eventually mangled anyway when synthesized to CFN. Fails if the construct ID contains a token. This won't work because we mangle the IDs as strings when we generate the logical ID and the construct's unique ID, and stringified tokens won't be resolved. Fixes #1351 Fixes #1374
Why is allowing |
@RomainMuller fully relaxing the constraints on construct IDs will make it easier to people to use any string that has the "locality" property for the ID without needing to think if this string is a valid ID, and sometimes (like #1351) those IDs are derived from user inputs. #1351 is a good example where @rix0rrr used the CloudWatch metric namespace for the construct ID, but didn't consider the option that the namespace may contain "/"s. The risk for collision is very low, in which case users will get a very early error and they can address, so I don't think that's a real concern. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not the biggest fan of going --
, but fine, I guess. The risk of a collision on --
is kinda low. I still think this should at least be documented in the escape hatch configuration (you'll have a hard time finding the constructs you want to fiddle with otherwise).
To solve @PaulMaddox's toString() issue, do you think we should build in a substring search for 'function()' and reject that as well? I mean, it's probably not going to be common but it has happened to a knowledgeable individual, and the check for it isn't that hard. |
@rix0rrr not sure... People can throw all bunch of garbage into the ID that is not a "good ID", but we can't catch all of that. I can even think of a legitimate use case where |
@RomainMuller I don't think we need to confuse people in the documentation of the escape hatch. The docs tell you to do |
Thanks so much for taking the time to contribute to the AWS CDK ❤️ We will shortly assign someone to review this pull request and help get it
|
Relax construct ID constraints to allow "/" (path seprator)
to be used in construct IDs, but convert it to "--" so it won't
collide with path strings.
It's quite rare for people to actually try to find a construct
by their ID (it's mostly "write-only") and the logical ID is eventually
mangled anyway when synthesized to CFN.
Fails if the construct ID contains a token. This won't work because
we mangle the IDs as strings when we generate the logical ID
and the construct's unique ID, and stringified tokens won't be
resolved.
Fixes #1351
Fixes #1374
Pull Request Checklist
Please check all boxes, including N/A items:
Testing
Documentation
Title and description
fix(module): <title>
bug fix (patch)feat(module): <title>
feature/capability (minor)chore(module): <title>
won't appear in changelogbuild(module): <title>
won't appear in changelogBREAKING CHANGE: <describe exactly what changed and how to achieve similar behavior + link to documentation/gist/issue if more details are required>
Fixes #xxx
orCloses #xxx
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.