Skip to content

Commit 659da6c

Browse files
Merge pull request #3440 from github/robertbrignull/database-download-creds
Push decision to use credentials or not down to where the creds are used
2 parents ee5ccec + 707cdec commit 659da6c

7 files changed

Lines changed: 15 additions & 32 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Update variant analysis view to show when cancelation is in progress. [#3405](https://github.com/github/vscode-codeql/pull/3405)
88
- Remove support for CodeQL CLI versions older than 2.13.5. [#3371](https://github.com/github/vscode-codeql/pull/3371)
99
- Add a timeout to downloading databases and the CodeQL CLI. These can be changed using the `codeQL.addingDatabases.downloadTimeout` and `codeQL.cli.downloadTimeout` settings respectively. [#3373](https://github.com/github/vscode-codeql/pull/3373)
10+
- When downloading a CodeQL database through the model editor, only use credentials when in canary mode. [#3440](https://github.com/github/vscode-codeql/pull/3440)
1011

1112
## 1.12.2 - 14 February 2024
1213

extensions/ql-vscode/src/databases/database-fetcher.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ import {
2626
getNwoFromGitHubUrl,
2727
isValidGitHubNwo,
2828
} from "../common/github-url-identifier-helper";
29-
import type { Credentials } from "../common/authentication";
3029
import type { AppCommandManager } from "../common/commands";
3130
import {
3231
addDatabaseSourceToWorkspace,
3332
allowHttp,
3433
downloadTimeout,
34+
isCanary,
3535
} from "../config";
3636
import { showAndLogInformationMessage } from "../common/logging";
3737
import { AppOctokit } from "../common/octokit";
3838
import { getLanguageDisplayName } from "../common/query-language";
3939
import type { DatabaseOrigin } from "./local-databases/database-origin";
4040
import { createTimeoutSignal } from "../common/fetch-stream";
41+
import type { App } from "../common/app";
4142

4243
/**
4344
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
@@ -90,20 +91,19 @@ export async function promptImportInternetDatabase(
9091
* User enters a GitHub repository and then the user is asked which language
9192
* to download (if there is more than one)
9293
*
94+
* @param app the App
9395
* @param databaseManager the DatabaseManager
9496
* @param storagePath where to store the unzipped database.
95-
* @param credentials the credentials to use to authenticate with GitHub
9697
* @param progress the progress callback
9798
* @param cli the CodeQL CLI server
9899
* @param language the language to download. If undefined, the user will be prompted to choose a language.
99100
* @param makeSelected make the new database selected in the databases panel (default: true)
100101
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
101102
*/
102103
export async function promptImportGithubDatabase(
103-
commandManager: AppCommandManager,
104+
app: App,
104105
databaseManager: DatabaseManager,
105106
storagePath: string,
106-
credentials: Credentials | undefined,
107107
progress: ProgressCallback,
108108
cli: CodeQLCliServer,
109109
language?: string,
@@ -117,9 +117,9 @@ export async function promptImportGithubDatabase(
117117

118118
const databaseItem = await downloadGitHubDatabase(
119119
githubRepo,
120+
app,
120121
databaseManager,
121122
storagePath,
122-
credentials,
123123
progress,
124124
cli,
125125
language,
@@ -129,7 +129,7 @@ export async function promptImportGithubDatabase(
129129

130130
if (databaseItem) {
131131
if (makeSelected) {
132-
await commandManager.execute("codeQLDatabases.focus");
132+
await app.commands.execute("codeQLDatabases.focus");
133133
}
134134
void showAndLogInformationMessage(
135135
extLogger,
@@ -169,9 +169,9 @@ export async function askForGitHubRepo(
169169
* Downloads a database from GitHub
170170
*
171171
* @param githubRepo the GitHub repository to download the database from
172+
* @param app the App
172173
* @param databaseManager the DatabaseManager
173174
* @param storagePath where to store the unzipped database.
174-
* @param credentials the credentials to use to authenticate with GitHub
175175
* @param progress the progress callback
176176
* @param cli the CodeQL CLI server
177177
* @param language the language to download. If undefined, the user will be prompted to choose a language.
@@ -180,9 +180,9 @@ export async function askForGitHubRepo(
180180
**/
181181
export async function downloadGitHubDatabase(
182182
githubRepo: string,
183+
app: App,
183184
databaseManager: DatabaseManager,
184185
storagePath: string,
185-
credentials: Credentials | undefined,
186186
progress: ProgressCallback,
187187
cli: CodeQLCliServer,
188188
language?: string,
@@ -194,6 +194,8 @@ export async function downloadGitHubDatabase(
194194
throw new Error(`Invalid GitHub repository: ${githubRepo}`);
195195
}
196196

197+
const credentials = isCanary() ? app.credentials : undefined;
198+
197199
const octokit = credentials
198200
? await credentials.getOctokit()
199201
: new AppOctokit();

extensions/ql-vscode/src/databases/local-databases-ui.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import {
4949
} from "./database-fetcher";
5050
import { asError, asyncFilter, getErrorMessage } from "../common/helpers-pure";
5151
import type { QueryRunner } from "../query-server";
52-
import { isCanary } from "../config";
5352
import type { App } from "../common/app";
5453
import { redactableError } from "../common/errors";
5554
import type { LocalDatabasesCommands } from "../common/commands";
@@ -558,13 +557,10 @@ export class DatabaseUI extends DisposableObject {
558557
private async handleChooseDatabaseGithub(): Promise<void> {
559558
return withProgress(
560559
async (progress) => {
561-
const credentials = isCanary() ? this.app.credentials : undefined;
562-
563560
await promptImportGithubDatabase(
564-
this.app.commands,
561+
this.app,
565562
this.databaseManager,
566563
this.storagePath,
567-
credentials,
568564
progress,
569565
this.queryServer.cliServer,
570566
);

extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
showAndLogErrorMessage,
1111
showAndLogWarningMessage,
1212
} from "../common/logging";
13-
import { isCanary, MAX_QUERIES } from "../config";
13+
import { MAX_QUERIES } from "../config";
1414
import { gatherQlFiles } from "../common/files";
1515
import { basename } from "path";
1616
import { showBinaryChoiceDialog } from "../common/vscode/dialog";
@@ -322,14 +322,12 @@ export class LocalQueries extends DisposableObject {
322322
private async createSkeletonQuery(): Promise<void> {
323323
await withProgress(
324324
async (progress: ProgressCallback) => {
325-
const credentials = isCanary() ? this.app.credentials : undefined;
326325
const contextStoragePath =
327326
this.app.workspaceStoragePath || this.app.globalStoragePath;
328327
const language = this.languageContextStore.selectedLanguage;
329328
const skeletonQueryWizard = new SkeletonQueryWizard(
330329
this.cliServer,
331330
progress,
332-
credentials,
333331
this.app,
334332
this.databaseManager,
335333
contextStoragePath,

extensions/ql-vscode/src/local-queries/skeleton-query-wizard.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { dirname, join } from "path";
22
import { Uri, window, window as Window, workspace } from "vscode";
33
import type { CodeQLCliServer } from "../codeql-cli/cli";
44
import { showAndLogExceptionWithTelemetry } from "../common/logging";
5-
import type { Credentials } from "../common/authentication";
65
import type { QueryLanguage } from "../common/query-language";
76
import { getLanguageDisplayName } from "../common/query-language";
87
import {
@@ -61,7 +60,6 @@ export class SkeletonQueryWizard {
6160
constructor(
6261
private readonly cliServer: CodeQLCliServer,
6362
private readonly progress: ProgressCallback,
64-
private readonly credentials: Credentials | undefined,
6563
private readonly app: App,
6664
private readonly databaseManager: DatabaseManager,
6765
private readonly databaseStoragePath: string | undefined,
@@ -388,9 +386,9 @@ export class SkeletonQueryWizard {
388386

389387
await downloadGitHubDatabase(
390388
chosenRepo,
389+
this.app,
391390
this.databaseManager,
392391
this.databaseStoragePath,
393-
this.credentials,
394392
progress,
395393
this.cliServer,
396394
this.language,

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,9 @@ export class ModelEditorView extends AbstractWebview<
917917
// imported to the query server, so we need to register it to our workspace.
918918
const makeSelected = false;
919919
const addedDatabase = await promptImportGithubDatabase(
920-
this.app.commands,
920+
this.app,
921921
this.databaseManager,
922922
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
923-
this.app.credentials,
924923
progress,
925924
this.cliServer,
926925
this.databaseItem.language,

extensions/ql-vscode/test/vscode-tests/cli-integration/local-queries/skeleton-query-wizard.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
removeSync,
1919
} from "fs-extra";
2020
import { dirname, join } from "path";
21-
import { testCredentialsWithStub } from "../../../factories/authentication";
2221
import type {
2322
DatabaseItem,
2423
DatabaseManager,
@@ -69,7 +68,6 @@ describe("SkeletonQueryWizard", () => {
6968
typeof CodeQLCliServer.prototype.resolveQlpacks
7069
>;
7170

72-
const credentials = testCredentialsWithStub();
7371
const chosenLanguage = "ruby";
7472
const selectedItems: QueryTreeViewItem[] = [];
7573

@@ -145,7 +143,6 @@ describe("SkeletonQueryWizard", () => {
145143
wizard = new SkeletonQueryWizard(
146144
mockCli,
147145
jest.fn(),
148-
credentials,
149146
mockApp,
150147
mockDatabaseManager,
151148
storagePath,
@@ -173,7 +170,6 @@ describe("SkeletonQueryWizard", () => {
173170
wizard = new SkeletonQueryWizard(
174171
mockCli,
175172
jest.fn(),
176-
credentials,
177173
mockApp,
178174
mockDatabaseManager,
179175
storagePath,
@@ -322,7 +318,6 @@ describe("SkeletonQueryWizard", () => {
322318
wizard = new SkeletonQueryWizard(
323319
mockCli,
324320
jest.fn(),
325-
credentials,
326321
mockApp,
327322
mockDatabaseManagerWithItems,
328323
storagePath,
@@ -372,7 +367,6 @@ describe("SkeletonQueryWizard", () => {
372367
wizard = new SkeletonQueryWizard(
373368
mockCli,
374369
jest.fn(),
375-
credentials,
376370
mockApp,
377371
mockDatabaseManagerWithItems,
378372
storagePath,
@@ -508,7 +502,6 @@ describe("SkeletonQueryWizard", () => {
508502
wizard = new SkeletonQueryWizard(
509503
mockCli,
510504
jest.fn(),
511-
credentials,
512505
mockApp,
513506
mockDatabaseManager,
514507
storagePath,
@@ -730,7 +723,6 @@ describe("SkeletonQueryWizard", () => {
730723
wizard = new SkeletonQueryWizard(
731724
mockCli,
732725
jest.fn(),
733-
credentials,
734726
mockApp,
735727
mockDatabaseManager,
736728
storagePath,
@@ -760,7 +752,6 @@ describe("SkeletonQueryWizard", () => {
760752
wizard = new SkeletonQueryWizard(
761753
mockCli,
762754
jest.fn(),
763-
credentials,
764755
mockApp,
765756
mockDatabaseManager,
766757
storagePath,
@@ -794,7 +785,6 @@ describe("SkeletonQueryWizard", () => {
794785
wizard = new SkeletonQueryWizard(
795786
mockCli,
796787
jest.fn(),
797-
credentials,
798788
mockApp,
799789
mockDatabaseManager,
800790
storagePath,
@@ -838,7 +828,6 @@ describe("SkeletonQueryWizard", () => {
838828
wizard = new SkeletonQueryWizard(
839829
mockCli,
840830
jest.fn(),
841-
credentials,
842831
mockApp,
843832
mockDatabaseManager,
844833
storagePath,

0 commit comments

Comments
 (0)