Use credentials for database download in non-canary mode#3072
Conversation
b190c35 to
636f8f1
Compare
We want users to be able to download databases from private/internal repositories without using canary mode. This will change the prompt to ask for credentials in non-canary mode as well.
8bd794e to
5d42cbc
Compare
…hub-database-authentication
starcke
left a comment
There was a problem hiding this comment.
Mostly looks good, although it would be good to see if the logic could be made a bit simpler. I also wonder about public repos.
| if (databases.length === 0) { | ||
| // If the user didn't have an access token, they have already been prompted, | ||
| // so we should give feedback. | ||
| if (!hasAccessToken) { |
There was a problem hiding this comment.
I think the behavior is correct, but I found the logic a bit hard to follow. It also seems a bit odd that there is a database prompt (the one to connect) in here instead of in github-database-prompt.ts.
I also wonder, what if the repo is public - do we then ask for a non-needed token?
There was a problem hiding this comment.
The prompt for connecting is defined in this file because it is common to both downloading and updating databases. This should make sense in #3079.
If the repo is public, we do ask for an unnecessary token. I can change this to always make a request first, and then only prompt if we get a 404. However, that will make this logic even harder to follow.
There was a problem hiding this comment.
However, that will make this logic even harder to follow.
That is probably right, although I am not super sure. I think what makes it complicated
is that we dont want to ask the user to connect and then ask them again to download the DB. If we asked
both questions then it could probably be written something like this:
databases = getDatabases(current_credentials)
if (databases.length === 0 && no_credentials) {
// Ask the user for credentials and try again
databases = getDatabases(ask_for_credentials)
}
downloadDatabaseFromGitHub(databases)
What do you think? How much do we want to prevent the second question?
There was a problem hiding this comment.
I think I've found a somewhat simpler solution which will make this easier to follow and also skip the prompt for credentials when the repo is public. I'll create a new function listDatabases which will:
- Try retrieving the databases, either with or without credentials depending on what is available
- If that fails with a 404 and they don't have an access token, ask the user whether they want to connect to GitHub
- If they do, prompt for credentials and retry the request
This function can then return a result like { databases: CodeqlDatabase[], promptedForCredentials: boolean }. The logic in the module will then be a little bit simpler since the name is promptedForCredentials instead of hasAccessToken, more closely matching what the intention is.
There was a problem hiding this comment.
I've just pushed this change, the logic for that is mostly inside github-database-api.ts and the listDatabases function.
There was a problem hiding this comment.
That looks better and also covers the public repo case. Thanks!
We want users to be able to download databases from private/internal repositories without using canary mode. This will change the prompt to ask for credentials in non-canary mode as well. This means there are now 2 different prompts:
When you click on "Connect" in the first notification, we'll prompt for credentials and then for the language (if necessary). In the second one, we'll immediately prompt for the language.
Based on #3071
Checklist
ready-for-doc-reviewlabel there.