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

fix(scaffolder): remove waiting until all fields are filled in before requesting user credentials #24881

Conversation

benjidotsh
Copy link
Contributor

Hey, I just made a Pull Request!

When using RepoUrlPicker with its requestUserCredentials option, the dialog only appears after all fields have a value. This results in the dialog appearing while typing in the last value, which can lead to a frustrating experience.

This pull request removes this check, which shows the dialog as soon as the RepoUrlPicker is displayed.

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • All your commits have a Signed-off-by line in the message. (more info)

… requesting user credentials

Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
@benjidotsh benjidotsh requested review from a team as code owners May 23, 2024 13:30
@github-actions github-actions bot added the area:scaffolder Everything and all things related to the scaffolder project area label May 23, 2024
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented May 23, 2024

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-scaffolder plugins/scaffolder patch v1.21.0-next.3

@benjdlambert
Copy link
Member

I'm not sure that we can do this, because when we request user credentials, they have the org and repoName already available so that we can request access to that URL with the org and repo already available.

Not sure if this could potentially break something, maybe not for GitHub but for other providers there could be a chance. What providers have you tested this with?

@benjdlambert
Copy link
Member

I want to call out also, this is another reason why I want to look at doing something like this: #16996

@benjidotsh
Copy link
Contributor Author

benjidotsh commented May 23, 2024

@benjdlambert ah, I see what you mean. I'm currently testing this with Bitbucket, where I didn't encounter any issues with it, but I can see the danger of it.

Maybe it's a better idea to make sure the dialog only pops up after the user leaves the last field for now? Or, maybe even better, add a button or when the button to the next step is pressed (if possible)?

@acierto
Copy link
Contributor

acierto commented May 31, 2024

Hey @benjidotsh!

It could be tricky to have a control of popup from the button, as the invocation of it resides in the picker.

@benjidotsh
Copy link
Contributor Author

Hey @acierto, yeah, I know, but I think we could add a prop to the picker component that acts as a handler for controlling the dialog. But maybe using an on blur event is enough - then we don't have to escape the picker component.

@backstage-goalie
Copy link
Contributor

Thanks for the contribution!
All commits need to be DCO signed before they are reviewed. Please refer to the the DCO section in CONTRIBUTING.md or the DCO status for more info.

@benjidotsh
Copy link
Contributor Author

benjidotsh commented Jun 6, 2024

@benjdlambert @acierto I dug a little deeper and, unless I'm missing something, I noticed that we only use the host part of the URL anyways.

I changed the code to only pass and check for the host for authentication, which inherently fixes the goal of this PR.

Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
@benjidotsh benjidotsh force-pushed the fix/scaffolder-request-user-credentials-on-load branch from abfec75 to bad9449 Compare June 6, 2024 11:40
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
@benjidotsh benjidotsh requested a review from a team as a code owner June 6, 2024 12:35
@github-actions github-actions bot added the area:catalog Related to the Catalog Project Area label Jun 6, 2024
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
@benjidotsh benjidotsh force-pushed the fix/scaffolder-request-user-credentials-on-load branch from c19bafb to a05727d Compare June 6, 2024 13:44
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
@benjidotsh
Copy link
Contributor Author

I think the test should call the scmAuthApi with the correct params if only a project is set is redundant, but I don't see the connection between the title and the code, so I left it in for now. Please let me know if my feeling is correct and I'll remove it.

Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
@benjidotsh
Copy link
Contributor Author

@benjdlambert can you maybe take a look at this PR again? 😇

Copy link
Member

@benjdlambert benjdlambert left a comment

Choose a reason for hiding this comment

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

Hey 👋 thanks for this!

Just wanna get some additional feedback here, thinking that we might want to solve this a different way.

I'm thinking that the secret for the actual job could be handled with something like #16996 and that a token for your other PR #25132 could be generated without waiting for all fields to be filled out of course.

@@ -93,7 +93,7 @@ export interface ScmAuthTokenOptions extends AuthRequestOptions {
gitlab?: string[];
};
};
url: string;
host: string;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, i'm not sure that we can make this change as it is now as it's a breaking change.

I wonder if we could perhaps support a union of either { url: string } | { host: string } instead.

The idea I guess is that there could be different credentials issued for different URLs, not just for VCS providers, but imagine a URL where you have a different token depending on path.

@Rugvip whats your thoughts here?

Copy link
Contributor Author

@benjidotsh benjidotsh Jun 14, 2024

Choose a reason for hiding this comment

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

Good point. I don't think it's absolutely necessary to even use host - I just refactored this because it looked like we only used the host part anyways. Even though I updated the usage of it everywhere in the code, I can imagine that an API change is not ideal for other plugins.

The idea I guess is that there could be different credentials issued for different URLs, not just for VCS providers, but imagine a URL where you have a different token depending on path.

I'm not sure what you mean with this part though. You're talking about potential use cases of ScmAuthTokenOptions that require URLs instead of hosts?

Copy link
Member

@benjdlambert benjdlambert Jun 14, 2024

Choose a reason for hiding this comment

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

No sorry , I'm talking about the getCredentials method. So lets say for GitHub for instance you have two different GitHub Apps configured in config. One of them is installed in the organization blob whilst the other is installed in the organization boop.

If I'm just requesting a token for github.com then the getCredentials method has no idea which app to select as it doesn't have context in the URL as to which org we're trying to reach right? I think thats the motivation behind keeping the URL as you can do url: 'https://github.com/blob/my-repo' to get a token for my-repo with the org blob.

That's why I think we can't remove it all at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I understand, but how it is implemented right now it completely ignores everything but the host anyways, right?

Copy link
Member

Choose a reason for hiding this comment

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

Ah wait sorry, you're right, I'm getting confused here between frontend and backend. It's the GithubCredentialsProvider that does that work, and that's backend only.

Ok, maybe there's room for us to do this, but yeah, unsure about the breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I can implement this without changing the API. I'll look into it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, should be done!

It doesn't differ too much from the original code and simplifies the PR a lot since the only thing we do is not pass the workspace and repository that go unused anyways.

@benjidotsh
Copy link
Contributor Author

@benjdlambert I agree #16996 would be the ideal solution, but I think that might be a huge undertaking. In the meantime it could be a good idea to just "fix" the existing implementation by making host the only required property since it's the only one that is being used anyways.

Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
@github-actions github-actions bot removed the area:catalog Related to the Catalog Project Area label Jun 14, 2024
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
Copy link
Member

@benjdlambert benjdlambert left a comment

Choose a reason for hiding this comment

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

Nice, thanks for the work here! Let's go with this! 🙏

@benjdlambert benjdlambert merged commit c0981a8 into backstage:master Jun 14, 2024
26 checks passed
@benjidotsh benjidotsh deleted the fix/scaffolder-request-user-credentials-on-load branch June 14, 2024 10:20
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:scaffolder Everything and all things related to the scaffolder project area
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants