Skip to content

Commit

Permalink
Enable Attach Emulator on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
sevoku committed Nov 20, 2024
1 parent a85ca62 commit 3162afe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -36,6 +35,8 @@ import {
cosmosMongoFilter,
cosmosTableFilter,
doubleClickDebounceDelay,
isLinux,
isWindows,
sqlFilter,
} from './constants';
import { DatabasesFileSystem } from './DatabasesFileSystem';
Expand Down Expand Up @@ -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.'),
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/tree/AttachedAccountsTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -47,7 +47,7 @@ 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';
Expand Down Expand Up @@ -141,7 +141,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 {
Expand Down

0 comments on commit 3162afe

Please sign in to comment.