mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-10-13 23:38:45 +01:00
Added VS Code Exnteion for DE
This commit is contained in:
parent
cfb5db4df6
commit
d45e10f5ac
@ -44,6 +44,12 @@ export interface DatabaseAccountExtendedProperties {
|
|||||||
publicNetworkAccess?: string;
|
publicNetworkAccess?: string;
|
||||||
enablePriorityBasedExecution?: boolean;
|
enablePriorityBasedExecution?: boolean;
|
||||||
vcoreMongoEndpoint?: string;
|
vcoreMongoEndpoint?: string;
|
||||||
|
apiProperties?: ApiProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiProperties {
|
||||||
|
/* Describes the version of the MongoDB account. */
|
||||||
|
serverVersion?: "3.2" | "3.6" | "4.0" | "4.2" | "5.0" | "6.0" | "7.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DatabaseAccountResponseLocation {
|
export interface DatabaseAccountResponseLocation {
|
||||||
|
@ -18,6 +18,7 @@ import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility";
|
|||||||
import { acquireMsalTokenForAccount } from "Utils/AuthorizationUtils";
|
import { acquireMsalTokenForAccount } from "Utils/AuthorizationUtils";
|
||||||
import { allowedNotebookServerUrls, validateEndpoint } from "Utils/EndpointUtils";
|
import { allowedNotebookServerUrls, validateEndpoint } from "Utils/EndpointUtils";
|
||||||
import { featureRegistered } from "Utils/FeatureRegistrationUtils";
|
import { featureRegistered } from "Utils/FeatureRegistrationUtils";
|
||||||
|
import { getVSCodeUrl } from "Utils/VSCodeExtensionUtils";
|
||||||
import { update } from "Utils/arm/generatedClients/cosmos/databaseAccounts";
|
import { update } from "Utils/arm/generatedClients/cosmos/databaseAccounts";
|
||||||
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
||||||
import * as ko from "knockout";
|
import * as ko from "knockout";
|
||||||
@ -289,40 +290,8 @@ export default class Explorer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a VS Code DocumentDB connection URL using the current user's MongoDB connection parameters.
|
|
||||||
* Double-encodes the updated connection string for safe usage in VS Code URLs.
|
|
||||||
*
|
|
||||||
* The DocumentDB VS Code extension requires double encoding for connection strings.
|
|
||||||
* See: https://microsoft.github.io/vscode-documentdb/manual/how-to-construct-url.html#double-encoding
|
|
||||||
*
|
|
||||||
* @returns {string} The encoded VS Code DocumentDB connection URL.
|
|
||||||
*/
|
|
||||||
private getDocumentDbUrl() {
|
|
||||||
const { adminLogin: adminLoginuserName = "", connectionString = "" } = userContext.vcoreMongoConnectionParams;
|
|
||||||
const updatedConnectionString = connectionString.replace(/<(user|username)>:<password>/i, adminLoginuserName);
|
|
||||||
const encodedUpdatedConnectionString = encodeURIComponent(encodeURIComponent(updatedConnectionString));
|
|
||||||
const documentDbUrl = `vscode://ms-azuretools.vscode-documentdb?connectionString=${encodedUpdatedConnectionString}`;
|
|
||||||
return documentDbUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getCosmosDbUrl() {
|
|
||||||
const activeTab = useTabs.getState().activeTab;
|
|
||||||
const resourceId = encodeURIComponent(userContext.databaseAccount.id);
|
|
||||||
const database = encodeURIComponent(activeTab?.collection?.databaseId);
|
|
||||||
const container = encodeURIComponent(activeTab?.collection?.id());
|
|
||||||
const baseUrl = `vscode://ms-azuretools.vscode-cosmosdb?resourceId=${resourceId}`;
|
|
||||||
const vscodeUrl = activeTab ? `${baseUrl}&database=${database}&container=${container}` : baseUrl;
|
|
||||||
return vscodeUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getVSCodeUrl(): string {
|
|
||||||
const isvCore = (userContext.apiType || userContext.databaseAccount.kind) === "VCoreMongo";
|
|
||||||
return isvCore ? this.getDocumentDbUrl() : this.getCosmosDbUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
public openInVsCode(): void {
|
public openInVsCode(): void {
|
||||||
const vscodeUrl = this.getVSCodeUrl();
|
const vscodeUrl = getVSCodeUrl();
|
||||||
const openVSCodeDialogProps: DialogProps = {
|
const openVSCodeDialogProps: DialogProps = {
|
||||||
linkProps: {
|
linkProps: {
|
||||||
linkText: "Download Visual Studio Code",
|
linkText: "Download Visual Studio Code",
|
||||||
|
54
src/Utils/VSCodeExtensionUtils.ts
Normal file
54
src/Utils/VSCodeExtensionUtils.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { useTabs } from "hooks/useTabs";
|
||||||
|
import { userContext } from "UserContext";
|
||||||
|
import { getHostFromUrl } from "./../Explorer/Tabs/CloudShellTab/Utils/CommonUtils";
|
||||||
|
|
||||||
|
export const DOCUMENTDB_VSCODE_EXTENSION_BASEURL = "vscode://ms-azuretools.vscode-documentdb";
|
||||||
|
export const COSMOSDB_VSCODE_EXTENSION_BASEURL = "vscode://ms-azuretools.vscode-cosmosdb";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a VS Code DocumentDB connection URL using the current user's MongoDB connection parameters.
|
||||||
|
* Double-encodes the updated connection string for safe usage in VS Code URLs.
|
||||||
|
*
|
||||||
|
* The DocumentDB VS Code extension requires double encoding for connection strings.
|
||||||
|
* See: https://microsoft.github.io/vscode-documentdb/manual/how-to-construct-url.html#double-encoding
|
||||||
|
*
|
||||||
|
* @returns {string} The encoded VS Code DocumentDB connection URL.
|
||||||
|
*/
|
||||||
|
export const getVSCodeUrl = (): string => {
|
||||||
|
const isvCore = (userContext.apiType || userContext.databaseAccount.kind) === "VCoreMongo";
|
||||||
|
const isMongo = userContext.apiType === "Mongo";
|
||||||
|
return isvCore ? getDocumentDbUrl() : isMongo ? getMongoRUUrl() : getCosmosDbUrl();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCosmosDbUrl = () => {
|
||||||
|
const activeTab = useTabs.getState().activeTab;
|
||||||
|
const resourceId = encodeURIComponent(userContext.databaseAccount.id);
|
||||||
|
const database = encodeURIComponent(activeTab?.collection?.databaseId);
|
||||||
|
const container = encodeURIComponent(activeTab?.collection?.id());
|
||||||
|
const baseUrl = `${COSMOSDB_VSCODE_EXTENSION_BASEURL}?resourceId=${resourceId}`;
|
||||||
|
const vscodeUrl = activeTab ? `${baseUrl}&database=${database}&container=${container}` : baseUrl;
|
||||||
|
return vscodeUrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getMongoRUUrl = () => {
|
||||||
|
const activeTab = useTabs.getState().activeTab;
|
||||||
|
const databaseAccount = userContext.databaseAccount;
|
||||||
|
const host = getHostFromUrl(databaseAccount.properties?.mongoEndpoint);
|
||||||
|
const port = 10255;
|
||||||
|
const database = activeTab?.collection?.databaseId;
|
||||||
|
const container = activeTab?.collection?.id();
|
||||||
|
const encodedUpdatedConnectionString = encodeURIComponent(`mongodb://${databaseAccount?.name}@${host}:${port}`);
|
||||||
|
const documentDbUrl = `${DOCUMENTDB_VSCODE_EXTENSION_BASEURL}?connectionString=${encodedUpdatedConnectionString}${
|
||||||
|
database ? `&database=${database}` : ""
|
||||||
|
}${container ? `&collection=${container}` : ""}`;
|
||||||
|
|
||||||
|
return documentDbUrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDocumentDbUrl = () => {
|
||||||
|
const { adminLogin: adminLoginuserName = "", connectionString = "" } = userContext.vcoreMongoConnectionParams;
|
||||||
|
const updatedConnectionString = connectionString.replace(/<(user|username)>:<password>/i, adminLoginuserName);
|
||||||
|
const encodedUpdatedConnectionString = encodeURIComponent(encodeURIComponent(updatedConnectionString));
|
||||||
|
const documentDbUrl = `${DOCUMENTDB_VSCODE_EXTENSION_BASEURL}?connectionString=${encodedUpdatedConnectionString}`;
|
||||||
|
return documentDbUrl;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user