Open benjdlambert opened 1 year ago
Thanks for raising this RFC. Personally I am in favour of the pattern similar to apiFactories
.
Therefore with this approach, they should be passed in as an array to a hooks prop belonging to <ScaffolderPlugin />
, rather than a JSX element that doesn't render any visible components
@UsainBloot +1, I do prefer the option of implementing this pattern though Utility APIs. It feels like the best tool for the job.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
🔖 Need
In order to collect secrets from a user to run in a job, you have the
useTemplateSecrets
hook which enables you to set secrets insideCustomFieldExtensions
. ForGITHUB_TOKEN
s we've added the ability to configure theFieldExtension
through the use of therequestUserCredentials
options like so:But let's say that I don't have the need for a
RepoPicker
. How do I get the currentGITHUB_TOKEN
from the user.The current solution
The way that we suggest people do this right now is by creating their own
FieldExtensions
and then having a field in theJSONSchema
that doesn't actually provide any value to the template in order to collect that secret and then set it usinguseTemplateSecrets
.This is a bit of a hack, and pretty clunky because you also need to hide the input field from the the
JSONSchema
, and it actually really isn't even a field extension at all at that point.🎉 Proposal
I'm suggesting an API that we can pass in functions that can be deployed with the
frontend
which run on the client.Not sure if it makes sense to make these components or not yet, that just always get magically rendered in the
Form
or not, thinking that you could provide some feedback to the user that isn't presented when calling the implementation of the API.Proposal
When writing up the
Scaffolder
plugin inApp.tsx
you could have the ability to pass in hooks that are going to be called when theTemplateEntity
has been loaded in the client. This will allow you to use existing hooks today, to be able to grab information from the user on load, and update the secrets context.And then you can apply which hooks to collect in the
template.yaml
〽️ Alternatives
There's a few different approaches that we could use that I think both have positives and negatives.
hooks
vs pureasync
A problem I can see with the
hook
approach, is that theuseAsync
thing is a little awkward, as you wouldn't be able to useasync/await
inside the mainhook
function just like React components. But if we were to enable that, we would need some way of being able to get access to theapis
that are registered in Backstage, and the way you can do that today in thevalidators
is accessing theapiHolder
directly as something that's passed in:There's also another option here, which maybe would be good to move over the
validator
functions to, is that we follow a pattern similar to theapiFactories
of both the frontend and backend and use our own DI framework to do it. I came up with this approach just writing this doc, so I'm still stewing on this, but quite like it!Extension code or no?
One other thing that popped up would be how we get these things into the
ScaffolderPlugin
. We have the<ScaffolderFieldExtension>
wrapper component, and the extensions are passed in as JSX elements. I thought about doing that here but think that it leads to confusion if they're hooks or not. Not sure:❌ Risks
No response
👀 Have you spent some time to check if this RFC has been raised before?
🏢 Have you read the Code of Conduct?