question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scaffolder: sample templates should validate component name properly

See original GitHub issue

Expected Behavior

Components created through our sample templates should always be possible to register in the catalog using the default validation rules.

Current Behavior

The validation of the entity name in our sample templates is too lax, for example allowing spaces. This will break the catalog registration step when creating the new component.

Possible Solution

Validate the name field in our sample templates using the same Regex as entity names are validated by, for example here: https://github.com/backstage/backstage/blob/13f5d78b0bb079030c9c8d1d58cea2bb6bacfa38/plugins/scaffolder-backend/sample-templates/react-ssr-template/template.yaml#L20

Steps to Reproduce

  1. Try to create a component called A B C
  2. Wait for scaffolder job to complete, which it will do succesfully
  3. Try to find the component in the catalog, it’s not there. Check backend logs for error: Policy check failed; caused by Error: "metadata.name" is not valid; expected a string that is sequences of [a-zA-Z0-9] separated by any of [-_.], at most 63 characters in total but found "A B C"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mtlewiscommented, Aug 5, 2021

@regicsolutions great suggestions, thanks! There’s definitely more we can do with respect to support for improved validation errors in general, especially when it comes to fields that are validated via the pattern property. I’d love to explore in particular how we can provide a generalized implementation of transformErrors that allows providing a custom error message alongside the pattern itself in the schema.

For entity names specifically, I don’t think using a pattern in the templates is the right solution. Entity names are always validated the same way in a given Backstage instance, so spreading the validation rules across all the templates creates unnecessary duplication. It also prevents us from reusing the catalog validation code itself when validating entity names.

1reaction
mtlewiscommented, Aug 2, 2021

Adding the pattern used to validate entity names results in pretty ugly error messages (see screenshot below), and by copying it into the template we also leave ourselves open to the risk that the requirements for entity names change and leave the templates out of sync.

Screenshot 2021-08-02 at 14 54 24

Is it perhaps worth considering introducing a new UI field for names that bakes in validation and friendly error messages?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing Templates · Backstage Software Catalog and ...
Templates are stored in the Software Catalog under a kind Template . You can create your own templates with a small yaml definition...
Read more >
[RFC] Next Steps for the Scaffolder · Issue #2771 - GitHub
My concern though is when you have multiple of these steps in one template and one calls it component_id , another component-id and...
Read more >
Writing scaffolder templates - Roadie.io
Here is an example of a very basic Scaffolder template that ... would like a little validation when the user enters an Entity...
Read more >
Scaffolding — Ferris Framework 2.1.0 documentation
Scaffolding can provide you with common CRUD functionality very quickly, ... It uses scaffold.singular as the template variable name. For example, if you're ......
Read more >
Scaffold generator does not generate stories or tests
After generating several scaffolds for our app, I noticed that it generates very little testing and no stories.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found