Push decision to use credentials or not down to where the creds are used
This commit is contained in:
@@ -26,18 +26,19 @@ import {
|
||||
getNwoFromGitHubUrl,
|
||||
isValidGitHubNwo,
|
||||
} from "../common/github-url-identifier-helper";
|
||||
import type { Credentials } from "../common/authentication";
|
||||
import type { AppCommandManager } from "../common/commands";
|
||||
import {
|
||||
addDatabaseSourceToWorkspace,
|
||||
allowHttp,
|
||||
downloadTimeout,
|
||||
isCanary,
|
||||
} from "../config";
|
||||
import { showAndLogInformationMessage } from "../common/logging";
|
||||
import { AppOctokit } from "../common/octokit";
|
||||
import { getLanguageDisplayName } from "../common/query-language";
|
||||
import type { DatabaseOrigin } from "./local-databases/database-origin";
|
||||
import { createTimeoutSignal } from "../common/fetch-stream";
|
||||
import type { App } from "../common/app";
|
||||
|
||||
/**
|
||||
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
|
||||
@@ -90,9 +91,9 @@ export async function promptImportInternetDatabase(
|
||||
* User enters a GitHub repository and then the user is asked which language
|
||||
* to download (if there is more than one)
|
||||
*
|
||||
* @param app the App
|
||||
* @param databaseManager the DatabaseManager
|
||||
* @param storagePath where to store the unzipped database.
|
||||
* @param credentials the credentials to use to authenticate with GitHub
|
||||
* @param progress the progress callback
|
||||
* @param cli the CodeQL CLI server
|
||||
* @param language the language to download. If undefined, the user will be prompted to choose a language.
|
||||
@@ -100,10 +101,9 @@ export async function promptImportInternetDatabase(
|
||||
* @param addSourceArchiveFolder whether to add a workspace folder containing the source archive to the workspace
|
||||
*/
|
||||
export async function promptImportGithubDatabase(
|
||||
commandManager: AppCommandManager,
|
||||
app: App,
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
credentials: Credentials | undefined,
|
||||
progress: ProgressCallback,
|
||||
cli: CodeQLCliServer,
|
||||
language?: string,
|
||||
@@ -117,9 +117,9 @@ export async function promptImportGithubDatabase(
|
||||
|
||||
const databaseItem = await downloadGitHubDatabase(
|
||||
githubRepo,
|
||||
app,
|
||||
databaseManager,
|
||||
storagePath,
|
||||
credentials,
|
||||
progress,
|
||||
cli,
|
||||
language,
|
||||
@@ -129,7 +129,7 @@ export async function promptImportGithubDatabase(
|
||||
|
||||
if (databaseItem) {
|
||||
if (makeSelected) {
|
||||
await commandManager.execute("codeQLDatabases.focus");
|
||||
await app.commands.execute("codeQLDatabases.focus");
|
||||
}
|
||||
void showAndLogInformationMessage(
|
||||
extLogger,
|
||||
@@ -169,9 +169,9 @@ export async function askForGitHubRepo(
|
||||
* Downloads a database from GitHub
|
||||
*
|
||||
* @param githubRepo the GitHub repository to download the database from
|
||||
* @param app the App
|
||||
* @param databaseManager the DatabaseManager
|
||||
* @param storagePath where to store the unzipped database.
|
||||
* @param credentials the credentials to use to authenticate with GitHub
|
||||
* @param progress the progress callback
|
||||
* @param cli the CodeQL CLI server
|
||||
* @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(
|
||||
**/
|
||||
export async function downloadGitHubDatabase(
|
||||
githubRepo: string,
|
||||
app: App,
|
||||
databaseManager: DatabaseManager,
|
||||
storagePath: string,
|
||||
credentials: Credentials | undefined,
|
||||
progress: ProgressCallback,
|
||||
cli: CodeQLCliServer,
|
||||
language?: string,
|
||||
@@ -194,6 +194,8 @@ export async function downloadGitHubDatabase(
|
||||
throw new Error(`Invalid GitHub repository: ${githubRepo}`);
|
||||
}
|
||||
|
||||
const credentials = isCanary() ? app.credentials : undefined;
|
||||
|
||||
const octokit = credentials
|
||||
? await credentials.getOctokit()
|
||||
: new AppOctokit();
|
||||
|
||||
@@ -49,7 +49,6 @@ import {
|
||||
} from "./database-fetcher";
|
||||
import { asError, asyncFilter, getErrorMessage } from "../common/helpers-pure";
|
||||
import type { QueryRunner } from "../query-server";
|
||||
import { isCanary } from "../config";
|
||||
import type { App } from "../common/app";
|
||||
import { redactableError } from "../common/errors";
|
||||
import type { LocalDatabasesCommands } from "../common/commands";
|
||||
@@ -558,13 +557,10 @@ export class DatabaseUI extends DisposableObject {
|
||||
private async handleChooseDatabaseGithub(): Promise<void> {
|
||||
return withProgress(
|
||||
async (progress) => {
|
||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||
|
||||
await promptImportGithubDatabase(
|
||||
this.app.commands,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.storagePath,
|
||||
credentials,
|
||||
progress,
|
||||
this.queryServer.cliServer,
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
showAndLogErrorMessage,
|
||||
showAndLogWarningMessage,
|
||||
} from "../common/logging";
|
||||
import { isCanary, MAX_QUERIES } from "../config";
|
||||
import { MAX_QUERIES } from "../config";
|
||||
import { gatherQlFiles } from "../common/files";
|
||||
import { basename } from "path";
|
||||
import { showBinaryChoiceDialog } from "../common/vscode/dialog";
|
||||
@@ -322,14 +322,12 @@ export class LocalQueries extends DisposableObject {
|
||||
private async createSkeletonQuery(): Promise<void> {
|
||||
await withProgress(
|
||||
async (progress: ProgressCallback) => {
|
||||
const credentials = isCanary() ? this.app.credentials : undefined;
|
||||
const contextStoragePath =
|
||||
this.app.workspaceStoragePath || this.app.globalStoragePath;
|
||||
const language = this.languageContextStore.selectedLanguage;
|
||||
const skeletonQueryWizard = new SkeletonQueryWizard(
|
||||
this.cliServer,
|
||||
progress,
|
||||
credentials,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
contextStoragePath,
|
||||
|
||||
@@ -2,7 +2,6 @@ import { dirname, join } from "path";
|
||||
import { Uri, window, window as Window, workspace } from "vscode";
|
||||
import type { CodeQLCliServer } from "../codeql-cli/cli";
|
||||
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||
import type { Credentials } from "../common/authentication";
|
||||
import type { QueryLanguage } from "../common/query-language";
|
||||
import { getLanguageDisplayName } from "../common/query-language";
|
||||
import {
|
||||
@@ -61,7 +60,6 @@ export class SkeletonQueryWizard {
|
||||
constructor(
|
||||
private readonly cliServer: CodeQLCliServer,
|
||||
private readonly progress: ProgressCallback,
|
||||
private readonly credentials: Credentials | undefined,
|
||||
private readonly app: App,
|
||||
private readonly databaseManager: DatabaseManager,
|
||||
private readonly databaseStoragePath: string | undefined,
|
||||
@@ -388,9 +386,9 @@ export class SkeletonQueryWizard {
|
||||
|
||||
await downloadGitHubDatabase(
|
||||
chosenRepo,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.databaseStoragePath,
|
||||
this.credentials,
|
||||
progress,
|
||||
this.cliServer,
|
||||
this.language,
|
||||
|
||||
@@ -917,10 +917,9 @@ export class ModelEditorView extends AbstractWebview<
|
||||
// imported to the query server, so we need to register it to our workspace.
|
||||
const makeSelected = false;
|
||||
const addedDatabase = await promptImportGithubDatabase(
|
||||
this.app.commands,
|
||||
this.app,
|
||||
this.databaseManager,
|
||||
this.app.workspaceStoragePath ?? this.app.globalStoragePath,
|
||||
this.app.credentials,
|
||||
progress,
|
||||
this.cliServer,
|
||||
this.databaseItem.language,
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
removeSync,
|
||||
} from "fs-extra";
|
||||
import { dirname, join } from "path";
|
||||
import { testCredentialsWithStub } from "../../../factories/authentication";
|
||||
import type {
|
||||
DatabaseItem,
|
||||
DatabaseManager,
|
||||
@@ -69,7 +68,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
typeof CodeQLCliServer.prototype.resolveQlpacks
|
||||
>;
|
||||
|
||||
const credentials = testCredentialsWithStub();
|
||||
const chosenLanguage = "ruby";
|
||||
const selectedItems: QueryTreeViewItem[] = [];
|
||||
|
||||
@@ -145,7 +143,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
@@ -173,7 +170,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
@@ -322,7 +318,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManagerWithItems,
|
||||
storagePath,
|
||||
@@ -372,7 +367,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManagerWithItems,
|
||||
storagePath,
|
||||
@@ -508,7 +502,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
@@ -730,7 +723,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
@@ -760,7 +752,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
@@ -794,7 +785,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
@@ -838,7 +828,6 @@ describe("SkeletonQueryWizard", () => {
|
||||
wizard = new SkeletonQueryWizard(
|
||||
mockCli,
|
||||
jest.fn(),
|
||||
credentials,
|
||||
mockApp,
|
||||
mockDatabaseManager,
|
||||
storagePath,
|
||||
|
||||
Reference in New Issue
Block a user