-
Notifications
You must be signed in to change notification settings - Fork 191
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
Conversation
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.
There was a problem hiding this 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.
|
||
// We don't want to set this in this.octokit because that would prevent | ||
// authenticating when requireCredentials is true. | ||
return new Octokit.Octokit({ retry }); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- You first download a database from GitHub (
this.octokit
is set to an unauthenticated instance) - 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 whilerequireAuthentication
istrue
.
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.
There was a problem hiding this 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 😺 ✨
There was a problem hiding this 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 }); |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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
ready-for-doc-review
label there.