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

Remove canary requirement for GitHub database download #1485

Merged
merged 6 commits into from
Aug 31, 2022

Conversation

koesie10
Copy link
Member

@koesie10 koesie10 commented Aug 30, 2022

This adds the ability for users to download CodeQL databases from GitHub without the canary flag being set.

If the canary flag is set, we will always require authentication. If it is not set, we do not require authentication, but will use an authentication token if it is available. The "Authenticate to GitHub" command is also available, so users which are not using the canary flag can still download private CodeQL databases using that command, although it's only available using the command palette.

See #1466 for the initial implementation of this.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

This makes authentication for download GitHub CodeQL databases optional.
If you are already authenticated, your token will be used. If you are
not authenticated, an anonymous request will be made.

If the canary flag is enabled, you will be prompted for credentials when
downloading a database and you are not yet logged in.
@koesie10 koesie10 marked this pull request as ready for review August 30, 2022 13:44
@koesie10 koesie10 requested a review from a team as a code owner August 30, 2022 13:44
@koesie10 koesie10 requested a review from a team August 30, 2022 13:44
Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

A couple of minor suggestions, but this can go in without them.

extensions/ql-vscode/src/authentication.ts Outdated Show resolved Hide resolved

// We don't want to set this in this.octokit because that would prevent
// authenticating when requireCredentials is true.
return new Octokit.Octokit({ retry });
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be safe to store this octokit instance in this.octokit. Above, a listener is being registered that will recreate the octokit instance when credentials change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Though, what you have now is also fine.

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 it's not safe to store it in the instance variable. That would fail in the following scenario:

  1. You first download a database from GitHub (this.octokit is set to an unauthenticated instance)
  2. You now try to run a variant analysis, which requires authentication. However, this.octokit is set so an unauthenticated instance, so an unauthenticated instance is returned while requireAuthentication is true.

koesie10 and others added 2 commits August 31, 2022 11:48
Co-authored-by: Andrew Eisenberg <[email protected]>
This does not remove the previously added mechanism of not requesting
credentials, but using them when they are available. I expect this to be
used in the future.
Copy link
Contributor

@shati-patel shati-patel left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! This looks good to me 😺 ✨

@koesie10 koesie10 merged commit af8f023 into main Aug 31, 2022
@koesie10 koesie10 deleted the koesie10/add-github-download-button branch August 31, 2022 14:57
Copy link
Contributor

@robertbrignull robertbrignull left a comment

Choose a reason for hiding this comment

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

I have a couple of questions about points in the code. I have tried it out though and it seems to be working as intended.

@@ -99,14 +101,15 @@ export async function promptImportGithubDatabase(
throw new Error(`Invalid GitHub repository: ${githubRepo}`);
}

const result = await convertGithubNwoToDatabaseUrl(githubRepo, credentials, progress);
const octokit = credentials ? await credentials.getOctokit(true) : new Octokit.Octokit({ retry });
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to move this new Octokit.Octokit({ retry }) somewhere so it's co-located with how the credentials creates its octokit? This might mean making a new util file just for creating octokits.

My reasoning here is that we want to construction to be the same in all cases, and that's difficult if we're constructing them and passing settings (like retry) from various places.

Do you think pulling that out to a shared location makes sense?

ctx.subscriptions.push(
commandRunner('codeQL.authenticateToGitHub', async () => {
if (isCanary()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this change still be here? I thought we would still only authenticate when in canary mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

This command should never be called in non-canary mode, so this shouldn't really matter

* @param requireAuthentication Whether the Octokit instance needs to be authenticated as user.
* @returns An instance of Octokit.
*/
async getOctokit(requireAuthentication = true): Promise<Octokit.Octokit> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a case where we pass false to this method?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not currently, but see 23a0e03 where I give a reasoning for why I left it like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants