Skip to content

Add an UriHandler to handle external requests to open/attach a specific account and open the Query Editor #2635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

sevoku
Copy link
Member

@sevoku sevoku commented Mar 29, 2025

This PR adds a UriHandler with following features:

  • Reveal an existing account in the Azure Resources tree
  • Attach the account to the Workspace if it is not an Azure Resource
  • Open the Query editor for the specified Collection/Container if available

Following parameters are supported (with dependencies):

  • resourceId: The full Azure Resource Id of the account
    • Pattern:vscode://ms-azuretools.vscode-cosmosdb?resourceId=[accountResourceId]
  • cs: The NoSQL/Mongo Connection String (For NoSQL optionally with or without the AccountKey parameter, AccountEndpoint is enough to authenticate with EntraID RBAC)
    • Optional Parameters (required to reveal the account in Azure Resources, will create an Attached Workspace Item otherwise)
      • subscriptionId: Azure Subscription ID
      • resourceGroup: Azure Resource Group Name (required for cs)
      • tenantId: Id of the tenant the resource belongs to (TODO: not yet implemented!)
    • Pattern:
      vscode://ms-azuretools.vscode-cosmosdb?subscriptionId=[subscriptionId]&resourceGroup=[resourceGroupName]&cs=AccountEndpoint=[connectionString]
  • (optional) required to open the Query Editor:
    • database: Database Name
    • container: Container/Collection Name
    • Pattern: vscode://ms-azuretools.vscode-cosmosdb?resourceId=[accountResourceId]&database=[databaseName]&container=[containerName]

IMPORTANT: parameters – especially cs – must be encoded using urlEncode()!

Examples:

vscode://ms-azuretools.vscode-cosmosdb?resourceId=/subscriptions/b15d5cd6-bff3-48c1-8d58-25eeb753034b/resourceGroups/my-resource-group/providers/Microsoft.DocumentDB/databaseAccounts/my-cosmosdb-account&database=Shop&container=Products
vscode://ms-azuretools.vscode-cosmosdb?subscriptionId=b15d5cd6-bff3-48c1-8d58-25eeb753034b&resourceGroup=my-resource-group&database=Shop&container=Products&cs=AccountEndpoint=https://cosmos.documents.azure.com:443/

Dependency Updates:

  • Updated activation events in package.json to include onView:azureResourceGroups and onUri.
  • Updated @microsoft/vscode-azext-utils to version 2.6.6. [1]

Function Enhancements:

  • Enhanced openNoSqlQueryEditor function to handle different input types and added a helper function to extract connections from container nodes in src/commands/openNoSqlQueryEditor/openNoSqlQueryEditor.ts.

Cosmos DB Connection Handling:

  • Added accountName getter to ParsedConnectionString class in src/ParsedConnectionString.ts.
  • Improved error handling and parsing logic in parseCosmosDBConnectionString and ParsedCosmosDBConnectionString classes in src/cosmosdb/cosmosDBConnectionStrings.ts. [1] [2]
  • Added support for handling connection strings in getAccountInfo function in src/tree/cosmosdb/AccountInfo.ts.

Miscellaneous:

  • Registered a global URI handler in src/extension.ts to handle URIs.

TODO:

Fixes #2532
Fixes partially #2620

sevoku added 7 commits March 29, 2025 11:08
This also allows attaching Cosmos DB accounts without an account key, Entra ID will be used instead automatically.
and extract the account name from the endpoint with ParsedCosmosDBConnectionString
…odes and by providing an existing NoSqlQueryConnection directly
…extension

Based on given parameters:
* Reveal a matching account node in the Azure Tree
* Attach the account if it is not an Azure resource
* Open the Query editor for a given collection
sevoku added 3 commits April 3, 2025 11:15
To enable TreeView.reveal we need all elements to have nested Ids separated by '/'.
Emulators were stored with their connection string as Id which can have '/' in it breaking
the convention. This changes emulators to always have a compatible Id and a unified
structure.
@sevoku sevoku force-pushed the dev/sevoku/open-from-url branch from 6f71d5f to 8663850 Compare April 3, 2025 14:33
tnaum-ms and others added 7 commits April 7, 2025 21:37
…CachedBranchDataProvider

- Introduced BaseCachedBranchDataProvider as a common base class for caching tree data.
- Updated CosmosDBBranchDataProvider to utilize the new base class, simplifying the implementation and enhancing caching logic.
- Refactored MongoVCoreBranchDataProvider to extend BaseCachedBranchDataProvider, improving code reuse and maintainability.
- Simplified CosmosDBWorkspaceBranchDataProvider and ClustersWorkspaceBranchDataProvider by extending BaseCachedBranchDataProvider, reducing boilerplate code and enhancing clarity.
- Removed redundant caching logic and event emitters in favor of the base class's functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support opening the Query Editor from outside (Portal, Fabric) using registerUriHandler
3 participants