From 56931ab0125a2923d7c7d77c60f7ef94b00ade9f Mon Sep 17 00:00:00 2001 From: Sevo Kukol Date: Wed, 20 Nov 2024 20:25:38 +0100 Subject: [PATCH] Enable Attach Emulator on Linux --- src/constants.ts | 1 + src/extension.ts | 7 ++++--- src/tree/AttachedAccountsTreeItem.ts | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 97c59147a..17e7ba379 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ export const isWindows: boolean = /^win/.test(process.platform); +export const isLinux: boolean = /^linux/.test(process.platform); import * as fs from 'fs'; import assert from 'node:assert'; diff --git a/src/extension.ts b/src/extension.ts index 3f769b93d..cf2232de2 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -24,7 +24,6 @@ import { type ITreeItemPickerContext, } from '@microsoft/vscode-azext-utils'; import { AzExtResourceType, getAzureResourcesExtensionApi } from '@microsoft/vscode-azureresources-api'; -import { platform } from 'os'; import * as vscode from 'vscode'; import { findTreeItem } from './commands/api/findTreeItem'; import { pickTreeItem } from './commands/api/pickTreeItem'; @@ -36,6 +35,8 @@ import { cosmosMongoFilter, cosmosTableFilter, doubleClickDebounceDelay, + isLinux, + isWindows, sqlFilter, } from './constants'; import { DatabasesFileSystem } from './DatabasesFileSystem'; @@ -142,10 +143,10 @@ export async function activateInternal( }, ); registerCommandWithTreeNodeUnwrapping('cosmosDB.attachEmulator', async (actionContext: IActionContext) => { - if (platform() !== 'win32') { + if (!isWindows && !isLinux) { actionContext.errorHandling.suppressReportIssue = true; throw new Error( - localize('emulatorNotSupported', 'The Cosmos DB emulator is only supported on Windows.'), + localize('emulatorNotSupported', 'The Cosmos DB emulator is only supported on Windows and Linux.'), ); } diff --git a/src/tree/AttachedAccountsTreeItem.ts b/src/tree/AttachedAccountsTreeItem.ts index e815f397b..451b0f6c0 100644 --- a/src/tree/AttachedAccountsTreeItem.ts +++ b/src/tree/AttachedAccountsTreeItem.ts @@ -16,7 +16,7 @@ import { type MongoClient } from 'mongodb'; import * as vscode from 'vscode'; import { API, getExperienceFromApi, getExperienceQuickPick, getExperienceQuickPicks } from '../AzureDBExperiences'; import { removeTreeItemFromCache } from '../commands/api/apiCache'; -import { emulatorPassword, isWindows } from '../constants'; +import { emulatorPassword, isLinux, isWindows } from '../constants'; import { parseDocDBConnectionString } from '../docdb/docDBConnectionStrings'; import { type CosmosDBCredential } from '../docdb/getCosmosClient'; import { DocDBAccountTreeItem } from '../docdb/tree/DocDBAccountTreeItem'; @@ -47,7 +47,8 @@ export const MONGO_CONNECTION_EXPECTED: string = 'Connection string must start w const localMongoConnectionString: string = 'mongodb://127.0.0.1:27017'; export class AttachedAccountsTreeItem extends AzExtParentTreeItem { - public static contextValue: string = 'cosmosDBAttachedAccounts' + (isWindows ? 'WithEmulator' : 'WithoutEmulator'); + public static contextValue: string = + 'cosmosDBAttachedAccounts' + (isWindows || isLinux ? 'WithEmulator' : 'WithoutEmulator'); public readonly contextValue: string = AttachedAccountsTreeItem.contextValue; public readonly label: string = 'Attached Database Accounts'; public childTypeLabel: string = 'Account'; @@ -141,7 +142,7 @@ export class AttachedAccountsTreeItem extends AzExtParentTreeItem { commandId: 'cosmosDB.attachEmulator', includeInTreeItemPicker: true, }); - return isWindows ? [attachDatabaseAccount, attachEmulator] : [attachDatabaseAccount]; + return isWindows || isLinux ? [attachDatabaseAccount, attachEmulator] : [attachDatabaseAccount]; } public isAncestorOfImpl(contextValue: string): boolean {