-
Notifications
You must be signed in to change notification settings - Fork 73
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
Conversation
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
…rameters in Azure resource revealing This change requires an upstream change: microsoft/vscode-azureresourcegroups#1107
…anchDataProvider and implement getParent to enable vscode.TreeView revealing of the children.
…rent retrieval functionality
…rameters in Workspace resource revealing This change requires an upstream change: microsoft/vscode-azureresourcegroups#1108
…nd progress indication
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.
6f71d5f
to
8663850
Compare
…rove parent-child relationship handling
…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.
The tree item is still being used, but a tree node search is performed internally. It's something that will be removed entirely in future releases as it's not bein used for an essential feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read all files, left comments. I will test saving/deleting connections in the workspace as I'm worried about it.
I suggested a change to the handling of the contextValue
in the BaseCachedBranchDataProvider.
* @returns The extracted MongoDB resource ID | ||
* @throws Error if the ID is not a valid workspace resource ID | ||
* | ||
* @remarks Long-term solution would be to avoid '/' characters within individual ID segments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used anymore 6c1311f, however in theory Attached Mongo accounts could still have an "/" in their IDs because we use parsedCS.username + '@' + parsedCS.redact().toString()
fir id
here:
id: parsedCS.username + '@' + parsedCS.redact().toString(), |
@tnaum-ms: can't we change that to use just the
username@hostname:port
instead of the full redacted string? I don't see any point in having all the other optional parameters being part of the ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sevoku I'm on it today. This is correct, it doesn't have to be the connection string. The rationale behind it was that the connection string can contain a database name so the current solution was the quick one. However, I'll improve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed here:
vscode-cosmosdb/src/commands/newConnection/MongoExecuteStep.ts
Lines 35 to 43 in 728401d
const hashedCS = randomUtils.getPseudononymousStringHash(connectionString, 'hex').substring(0, 24); | |
const storageId = `storageId-${parsedCS.hosts.join('_')}-${hashedCS}`; | |
const storageItem: StorageItem = { | |
id: storageId, | |
name: label, | |
properties: { isEmulator: false, api }, | |
secrets: [connectionString], | |
}; |
matching migration code is in place as well, so that now all entries are consistent.
I tried out creating/listing/deleting connections. I discovered only one failing scenario:
It will show the 'deleting' UI (aka the tree view node id is correct), but the actual entry won't be deleted (very likely due to incorrect workspace name or the id doesn't match the one in storage). @sevoku I can track it down / fix it sometime tomorrow in case you won't have time. |
This reverts commit 6f639e1.
fa5419c
to
4ac800b
Compare
✅ The issue no longer occurs. |
@sevoku I looked at the To get there faster, I asked Copilot to come up with some suggestions, for you to choose from :) Here are three better name suggestions that more accurately reflect the class's purpose: BaseNavigableBranchDataProvider BaseHierarchicalBranchDataProvider BaseStructuredBranchDataProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new URI handler along with several changes to support external requests for opening/attaching Cosmos DB accounts and launching the Query Editor. Key changes include:
- Adding a storageId property and related type/interfaces for attached accounts and tree elements.
- Refactoring account information and connection string parsing to support both attached accounts and connection string inputs.
- Updating various branch data providers and commands (including removal, query editor, and emulator connections) to integrate these new concepts.
Reviewed Changes
Copilot reviewed 30 out of 32 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/tree/workspace-view/cosmosdb/CosmosDBAttachedAccountModel.ts | Added storageId to the attached account model. |
src/tree/workspace-api/SharedWorkspaceResourceProvider.ts | Introduced helper methods for extracting workspace resource IDs. |
src/tree/documentdb/ClusterModel.ts | Added a new AttachedClusterModel type. |
src/tree/cosmosdb/CosmosDBAccountAttachedResourceItem.ts | Implemented storageId getter for attached account resource items. |
src/tree/cosmosdb/AccountInfo.ts | Refactored getAccountInfo to account for both attached accounts and connection string inputs. |
src/tree/azure-resources-view/documentdb/mongo-vcore/MongoVCoreBranchDataProvider.ts | Refactored to extend BaseCachedBranchDataProvider and removed redundant events. |
src/tree/azure-resources-view/cosmosdb/CosmosDBBranchDataProvider.ts | Refactored resource item creation and updated refresh to throw an error for unsupported cases. |
src/tree/TreeElementWithStorageId.ts | Added a new type and type guard for tree elements with storage IDs. |
src/services/storageService.ts | Updated to ensure the correct storage id is used when reading items from storage. |
src/extension.ts | Registered a global URI handler. |
src/cosmosdb/cosmosDBConnectionStrings.ts | Updated connection string parsing to use the URL constructor and include the port explicitly. |
src/cosmosdb/cosmosDBConnectionStrings.test.ts | Adjusted tests to account for the new connection string validation. |
src/commands/removeConnection/removeConnection.ts | Updated deletion logic and type usage for connection removal. |
src/commands/openNoSqlQueryEditor/openNoSqlQueryEditor.ts | Extended support to handle NoSqlQueryConnection inputs along with tree nodes. |
src/commands/openCollectionView/openCollectionView.ts | Updated parameters for opening a collection view. |
src/commands/newEmulatorConnection/ExecuteStep.ts | Utilized emulator utility functions for label and unique id generation. |
src/commands/newConnection/MongoExecuteStep.ts | Integrated pseudonymous hashing for storage id generation. |
src/ParsedConnectionString.ts | Added an accountName getter which returns the account identifier. |
Files not reviewed (2)
- l10n/bundle.l10n.json: Language not supported
- package.json: Language not supported
Comments suppressed due to low confidence (2)
src/commands/removeConnection/removeConnection.ts:100
- [nitpick] The confirmation logic within the showDeleting callback appears somewhat convoluted. Consider simplifying this flow by acquiring the confirmation result first before proceeding with deletion actions to improve readability.
if (!confirmed) { throw new UserCancelledError(); }
src/ParsedConnectionString.ts:25
- [nitpick] The getter 'accountName' simply returns 'accountId', which may be redundant. Consider consolidating these properties for clarity and to avoid potential confusion.
public get accountName(): string { return this.accountId; }
This PR adds a UriHandler with following features:
Following parameters are supported (with dependencies):
resourceId
: The full Azure Resource Id of the accountvscode://ms-azuretools.vscode-cosmosdb?resourceId=[accountResourceId]
cs
: The NoSQL/Mongo Connection String (For NoSQL optionally with or without theAccountKey
parameter,AccountEndpoint
is enough to authenticate with EntraID RBAC)subscriptionId
: Azure Subscription IDresourceGroup
: Azure Resource Group Name (required forcs
)tenantId
: Id of the tenant the resource belongs to (TODO: not yet implemented!)vscode://ms-azuretools.vscode-cosmosdb?subscriptionId=[subscriptionId]&resourceGroup=[resourceGroupName]&cs=AccountEndpoint=[connectionString]
database
: Database Namecontainer
: Container/Collection Namevscode://ms-azuretools.vscode-cosmosdb?resourceId=[accountResourceId]&database=[databaseName]&container=[containerName]
IMPORTANT: parameters – especially
cs
– must be encoded usingencodeURIComponent()
!Examples:
Dependency Updates:
package.json
to includeonView:azureResourceGroups
andonUri
.@microsoft/vscode-azext-utils
to version2.6.6
. [1]Function Enhancements:
openNoSqlQueryEditor
function to handle different input types and added a helper function to extract connections from container nodes insrc/commands/openNoSqlQueryEditor/openNoSqlQueryEditor.ts
.Cosmos DB Connection Handling:
accountName
getter toParsedConnectionString
class insrc/ParsedConnectionString.ts
.parseCosmosDBConnectionString
andParsedCosmosDBConnectionString
classes insrc/cosmosdb/cosmosDBConnectionStrings.ts
. [1] [2]getAccountInfo
function insrc/tree/cosmosdb/AccountInfo.ts
.Miscellaneous:
src/extension.ts
to handle URIs.TODO:
addShould be done separately as part of Add an UriHandler to handle external requests to open/attach a specific account and open the Query Editor #2635tenantId
parameter to support multi-tenant configsClustersWorkspaceBranchDataProvider.getParent()
similar toCosmosDBWorkspaceBranchDataProvider
MongoVCoreBranchDataProvider.getPArent()
similar toCosmosDBBranchDataProvider
openAppropriateEditorForConnection()
revealAttachedInWorkspaceExplorer
to userevealWorkspaceResource
once Add revealWorkspaceResource function to expose resources in Workspaces vscode-azureresourcegroups#1108 becomes available in @microsoft/vscode-azext-azureutils.BranchDataProvider.refresh()
is never called for root node, i.e. select to "Refresh" a resource group, it will callgetResourceItem(resource)
right away, so there is no way for us to cache root (account/cluster) nodes. We need to either patch this in Azure Resources or find another way to detect whether to invalidate cache or not (maybe a timestamp on the resource model?)Fixes #2532
Fixes partially #2620