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

scaffolder: Implement hooks for collecting secrets #25975

Merged
merged 16 commits into from
Nov 26, 2024

Conversation

benjdlambert
Copy link
Member

This is a stab at implementing #16996 and being able to move some of the secret collection amongst other things outside of the react context.

@github-actions github-actions bot added the area:scaffolder Everything and all things related to the scaffolder project area label Aug 12, 2024
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented Aug 12, 2024

Changed Packages

Package Name Package Path Changeset Bump Current Version
example-app packages/app none v0.2.103
@internal/scaffolder packages/scaffolder-internal none v0.0.3
@backstage/plugin-scaffolder-backend plugins/scaffolder-backend patch v1.27.0
@backstage/plugin-scaffolder-common plugins/scaffolder-common patch v1.5.7
@backstage/plugin-scaffolder-react plugins/scaffolder-react patch v1.14.0
@backstage/plugin-scaffolder plugins/scaffolder patch v1.27.0

Copy link
Contributor

github-actions bot commented Sep 5, 2024

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

Copy link
Contributor

github-actions bot commented Oct 8, 2024

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Oct 8, 2024
@benjdlambert benjdlambert force-pushed the blam/secret-collection branch from 3184a5a to c821e6d Compare October 11, 2024 08:42
@github-actions github-actions bot removed the stale label Oct 11, 2024
@benjdlambert benjdlambert force-pushed the blam/secret-collection branch 2 times, most recently from a33dbf7 to ff0f407 Compare October 14, 2024 07:32
@benjdlambert benjdlambert marked this pull request as ready for review October 14, 2024 14:33
@benjdlambert benjdlambert requested review from a team as code owners October 14, 2024 14:33
@@ -69,6 +70,35 @@ export function createFormField<
TUiOptions extends z.ZodType,
>(opts: FormFieldExtensionData<TReturnValue, TUiOptions>): FormField;

// @public
export function createScaffolderFormDecorator<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to expose it to zod as it is done here? #26957

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we want to align so that zod is exposed like the below:

https://github.com/backstage/backstage/pull/25975/files#diff-133af4d9fd32f76d048c15eee319683f33ae9b8045d4a258a84923c03f9ec892R78-R80

It's copying how the new frontend system exposes zod, so that you write things like this:

createScaffolderFormDecorator({
  input: {
    myInput: (z) => z.string().optional(),
  }
});

Same as this https://backstage.io/docs/frontend-system/architecture/extensions#extension-configuration

I think that other PR needs updating, just haven't had chance to leave feedback there yet.

@benjdlambert benjdlambert force-pushed the blam/secret-collection branch from e95c999 to dae54bd Compare October 28, 2024 14:16
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@github-actions github-actions bot added the stale label Nov 11, 2024
@freben freben removed the stale label Nov 12, 2024
@benjdlambert benjdlambert force-pushed the blam/secret-collection branch from e980991 to 4a2e354 Compare November 19, 2024 09:27
Comment on lines 35 to 38
TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType } = {},
TDeps extends { [key in string]: AnyApiRef } = { [key in string]: AnyApiRef },
TInput extends {} = {
[key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aim to have the defaults for these be the "any" version, so the first one would default to { [key in string]: (zImpl: typeof z) => z.ZodType }. With that it should be possible to get rid of the AnyScaffolderFormDecorator and just use ScaffolderFormDecorator without type args instead

Comment on lines 35 to 36
TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType },
TDeps extends { [key in string]: AnyApiRef },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aim to have the defaults for these be the "any" version but expressed with the more exact type than any, so the first one would default to { [key in string]: (zImpl: typeof z) => z.ZodType }. With that it should be possible to get rid of the AnyScaffolderFormDecorator and just use ScaffolderFormDecorator without type args instead.

});
} catch (ex) {
// eslint-disable-next-line no-console
console.error(ex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need proper error handling here no?

const formDecorator = formDecorators?.get(decorator.id);
if (!formDecorator) {
// eslint-disable-next-line no-console
console.error('Failed to find form decorator', decorator.id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, would need to forward this to the user

input?: TInputSchema;
};
deps?: TDeps;
fn: (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking it might be nice to call this one decorator or smth?

@@ -190,6 +220,50 @@ export interface ScaffolderFieldProps {
required?: boolean;
}

// @alpha (undocumented)
export type ScaffolderFormDecorator<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed I'm thinking it's best to make this an opaque type

@github-actions github-actions bot added area:techdocs Related to the TechDocs Project Area area:kubernetes Related to the Kubernetes Project Area - not deploying Backstage with k8s. search Things related to Search area:search labels Nov 19, 2024
Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍

Just a minor thing, and then perhaps it's best to add some docs for this too?

@@ -379,5 +414,20 @@ export type TemplateWizardPageProps = {
};
};

// @alpha (undocumented)
export const useFormDecorators: ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, should this one really be exported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm maybe not at the moment, you can provide your own TemplateWizardPage and this would need to be a building block of it. Will remove it for now.

createApiFactory({
api: formDecoratorsApiRef,
deps: {},
factory: () => DefaultScaffolderFormDecoratorsApi.create(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking we should be shipping any built-in decorators btw? Or in case that might be a security issue or such, having default ones be provided in the new system as extensions that are disabled by default?

Copy link
Member Author

@benjdlambert benjdlambert Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially, maybe the ones for provider tokens for sure might be a good idea, but nothing concrete as yet. Just wanna see how this these things feel, and we go from there.

@benjdlambert benjdlambert requested a review from a team as a code owner November 19, 2024 13:10
@github-actions github-actions bot added documentation Improvements or additions to documentation microsite Changes to backstage.io labels Nov 19, 2024
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>

Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>

Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
@benjdlambert benjdlambert force-pushed the blam/secret-collection branch from 1c62680 to 4c8acd2 Compare November 25, 2024 15:13
Signed-off-by: blam <ben@blam.sh>
@benjdlambert benjdlambert force-pushed the blam/secret-collection branch from 4c8acd2 to e37287d Compare November 25, 2024 15:14
@benjdlambert benjdlambert merged commit 814599c into master Nov 26, 2024
36 checks passed
@benjdlambert benjdlambert deleted the blam/secret-collection branch November 26, 2024 09:29
Copy link
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.34.0 release, scheduled for Tue, 17 Dec 2024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:catalog Related to the Catalog Project Area area:kubernetes Related to the Kubernetes Project Area - not deploying Backstage with k8s. area:scaffolder Everything and all things related to the scaffolder project area area:search area:techdocs Related to the TechDocs Project Area documentation Improvements or additions to documentation microsite Changes to backstage.io search Things related to Search
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants