Repository navigation
Emit warnings for invalid identifiers - #5864
Conversation
28cd400 to
e5f3d5b
Compare
|
Hey @mouellet, thanks for another awesome contribution! I haven't had much of a chance to look at this, and probably won't for another day or two - we're busy trying to get 6.4.0 out the door. But will try to review it soon! |
| return warning | ||
| } | ||
|
|
||
| var validIdentifiers = regexp.MustCompile(`^\p{L}[\p{L}\d\-.]*$`) |
There was a problem hiding this comment.
The RFC mentions that
All letters will be converted to lowercase. This is to enforce case-insensitivity and to present a consistent UI/UX while still supporting languages that don't have any casing (e.g. Japanese).
We should probably just emit a warning for now.
@vito in the future, do you see this as the CLI automatically converting the case and logging a warning; or just fail outright?
There was a problem hiding this comment.
@chenbh I see it as the server-side auto-converting case, though a client-side warning makes sense too. With this enforced on the server-side it can know to only convert newly created pipelines to lowercase while leaving the original pipelines alone. Whaddaya think?
There was a problem hiding this comment.
Isn't \p{L} short for [\p{Ll}\p{Lu}\p{Lt}\p{Lm}\p{Lo}]? If we remove \p{Lu} from that we would have valid identifier be lowercase only and support languages without case. Then there's no need for auto-converting case, right?
It's not pretty, but I think ^[\p{Ll}\p{Lt}\p{Lm}\p{Lo}][\p{Ll}\p{Lt}\p{Lm}\p{Lo}\d\-.]*$ would do that...
There was a problem hiding this comment.
@mouellet Neat! Yeah, that works as expected. I'll amend the RFC with this as well.
There was a problem hiding this comment.
This looks great so far! I think we might have to slightly rethink the approach so that we error on setting new pipelines/teams rather than just emit warnings (ignore me, I missed your discussion with @vito), but otherwise this is awesome work. Much appreciated!
Just have a few nits for now, will do more thorough acceptance on it soon.
|
@aoldershaw We decided to go with warnings instead of errors until pipelines instances (#5808) lands. Otherwise, if we enforce valid identifiers first, some users would become blocked as their previously-valid name generation schemes would no longer be functional and they would have to resort to pretty ugly sanitization schemes like This concern was mentioned here: concourse/rfcs#40 (comment) Right now the RFC states...:
When I wrote this I originally intended this to apply only to already-existing data, but now that we're here it might be wise to just have all cases result in warnings and then switch to errors after some period of time so that folks have enough time to adapt their patterns to things like pipeline instances (...and so we have time to polish pipeline instances). This would simplify the transition from 3 steps (Warn/Warn, Warn/Error w/ #5808 done, Error/Error after 1 year) down to 2 steps (Warn/Warn, Error/Error after 1 year) which may be easier to reason about. What do y'all think? Should I amend the RFC? |
aoldershaw
left a comment
There was a problem hiding this comment.
Hey, sorry for taking so long to review this! I have a couple small suggestions
| if identifier != "" && !validIdentifiers.MatchString(identifier) { | ||
| return &ConfigWarning{ | ||
| Type: "invalid_identifier", | ||
| Message: fmt.Sprintf("%s: %s", strings.Join(context, ""), fmt.Sprintf("'%s' is not a valid identifier", identifier)), |
There was a problem hiding this comment.
I wonder if we can provide more context as to what a valid identifier is, since to a new user (or to an old user who isn't familiar with the valid identifiers RFC), it might not be obvious. While we will have this documented, perhaps it's better to tell the user what exactly was wrong with their identifier, or give a brief summary of what a valid identifier is. That could just be the responsibility of fly when it encounters an invalid_identifier warning, or we could encode this information into the Message itself...not sure what the best approach is.
Since the validation logic is pretty simple, maybe it's worth not using a regex at all (which looks a bit intimidating at this point) and instead do the validation manually. This way, we can give more fine-grained warning messages that can help users out (e.g. 'some_job' is not a valid identifier: illegal character '_' or '123abc' is not a valid identifier: must start with a letter)
What do you think about that approach?
There was a problem hiding this comment.
Sure! Let's add a brief summary for must start with and illegal character. Should we print a single item (the left most one) or a list?
That could just be the responsibility of
flywhen it encounters aninvalid_identifierwarning, or we could encode this information into theMessageitself...not sure what the best approach is.
Encoding the details in the Message will keep consistency between client-side and server-side validation.
Since the validation logic is pretty simple, maybe it's worth not using a regex at all (which looks a bit intimidating at this point) and instead do the validation manually.
If it's ok with you, I'd keep using a regex for now... There's a simple way to catch the details using them.
4771844 to
4ad9bf8
Compare
There was a problem hiding this comment.
It feels really nice to use, and the errors are pretty intuitive. I have 2 small requests:
- Would it be possible for
flyto link to theschema.identifierdocs (https://concourse-ci.org/config-basics.html#schema.identifier) when there is aninvalid_identifierwarning? I think it would probably make sense to just do it once after we print out all of the warnings, rather than printing it out for every warning. So, something like:
$ fly set-pipeline -p Test -c invalid-identifiers.yml
...
DEPRECATION WARNING:
- pipeline: 'Test' is not a valid identifier: must start with a lowercase letter
- resources.new_repo: 'new_repo' is not a valid identifier: illegal character '_'
- jobs.set a pipeline: 'set a pipeline' is not a valid identifier: illegal character ' '
- jobs.set a pipeline.plan.do[0].get(new_repo): 'new_repo' is not a valid identifier: illegal character '_'
identifier schema documentation: https://concourse-ci.org/config-basics.html#schema.identifier
...or if you have any other ideas, feel free to do something else - I just feel it's valuable to have some easy access to the documentation so that users aren't just faced with illegal character without knowing what the legal characters are!
- Speaking of docs 😁 would it be possible to update the
schema.identifiersection of the docs? It's all isolated here https://github.com/concourse/docs/blob/c3ce45b93efcb2850e4912afb2feba7e4513c465/lit/docs/config/basic-schemas.lit#L63-L80 from what I can tell. I'd still provide your updated regex, but now that it's a little harder to read, I'd also provide a short list of bullet points that describe the schema rules at a high level (starts with lowercase, only lowercase letters, nums, '.', '-')
Thanks again! Also saw you created a draft PR for pipeline instances - that's awesome, looking forward to seeing that in action
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse/concourse#58010 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
concourse#5810 Signed-off-by: Mathieu Ouellet <[email protected]>
3a9f554 to
e45f3aa
Compare
aoldershaw
left a comment
There was a problem hiding this comment.
Awesome, thanks for making the changes so quickly!
What does this PR accomplish?
Bug Fix | Feature | Documentation
closes #5810.
Changes proposed by this PR:
flycommands print warnings whenteams,pipelines,jobs,steps,groups,resources,resource_types orvar_sources identifier are not valid (see rfc#40 for spec).Notes to reviewer:
Release Note
identifierschemaidentifiersdon't match the validation rules - so, we recommend adhering to the new validation as soon as possible!Contributor Checklist
Reviewer Checklist
BOSH and
Helm packaging; otherwise, ignored for
the integration
tests
(for example, if they are Garden configs that are not displayed in the
--helptext).