-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Finalize migration plugins integration and introduce an internal plugin registry #207
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
Open
tnaum-ms
wants to merge
10
commits into
next
Choose a base branch
from
dev/tnaum/186-finalize-migration-plugins-integration-and-introduce-a-plugin-registry
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2d40e26
chore: renamed data migration commands internally, always showing the…
tnaum-ms 1ba41dd
feat: added `announcedClients` to the migration config
tnaum-ms d687cde
feat: added support for `announced migration providers`
tnaum-ms 2fffbdc
fix: improved client extension registration via getApi improvements
tnaum-ms 63311a5
updated migration api version
tnaum-ms ae60948
Updated api version
tnaum-ms 6f16915
fix: workaround for v0.2.0 API users
tnaum-ms 8918749
fix: typos detected by copilot
tnaum-ms 00db884
prettier-fix
tnaum-ms ca318b5
Merge branch 'next' into dev/tnaum/186-finalize-migration-plugins-int…
tnaum-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 214 additions & 0 deletions
214
src/commands/accessDataMigrationServices/accessDataMigrationServices.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { nonNullValue, type IActionContext } from '@microsoft/vscode-azext-utils'; | ||
| import * as l10n from '@vscode/l10n'; | ||
| import { commands, QuickPickItemKind, type QuickPickItem } from 'vscode'; | ||
| import { CredentialCache } from '../../documentdb/CredentialCache'; | ||
| import { MigrationService } from '../../services/migrationServices'; | ||
| import { type ClusterItemBase } from '../../tree/documentdb/ClusterItemBase'; | ||
| import { openUrl } from '../../utils/openUrl'; | ||
|
|
||
| const ANNOUNCED_PROVIDER_PREFIX = 'announced-provider'; | ||
|
|
||
| export async function accessDataMigrationServices(context: IActionContext, node: ClusterItemBase) { | ||
| const installedProviders: (QuickPickItem & { id: string })[] = MigrationService.listProviders() | ||
| // Map to QuickPickItem format | ||
| .map((provider) => ({ | ||
| id: provider.id, | ||
| label: provider.label, | ||
| detail: provider.description, | ||
| iconPath: provider.iconPath, | ||
|
|
||
| group: 'Installed Providers', | ||
| alwaysShow: true, | ||
| })) | ||
| // Sort alphabetically | ||
| .sort((a, b) => a.label.localeCompare(b.label)); | ||
|
|
||
| const announcedProviers: (QuickPickItem & { id: string })[] = MigrationService.listAnnouncedProviders(true) | ||
tnaum-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Map to QuickPickItem format | ||
| .map((provider) => ({ | ||
| id: `${ANNOUNCED_PROVIDER_PREFIX}-${provider.id}`, // please note, the prefix is a magic string here, and needed to correctly support vs code marketplace integration | ||
| label: `$(extensions) ${provider.name}`, | ||
| detail: `Open the VS Code Marketplace to learn more about "${provider.name}"`, | ||
| url: provider.url, | ||
|
|
||
| marketplaceId: provider.id, | ||
| group: 'Visit Marketplace', | ||
| alwaysShow: true, | ||
| })) | ||
| // Sort alphabetically | ||
| .sort((a, b) => a.label.localeCompare(b.label)); | ||
|
|
||
| const commonItems = [ | ||
| // { | ||
| // id: 'addMigrationProvider', | ||
| // label: l10n.t('Add New Migration Provider…'), | ||
| // detail: l10n.t('Explore more data migration providers.'), | ||
| // iconPath: new ThemeIcon('plus'), | ||
|
|
||
| // group: 'Migration Providers', | ||
| // alwaysShow: true, | ||
| // }, | ||
| { label: '', kind: QuickPickItemKind.Separator }, | ||
| { | ||
| id: 'learnMore', | ||
| label: l10n.t('Learn more…'), | ||
| detail: l10n.t('Learn more about DocumentDB and MongoDB migrations.'), | ||
|
|
||
| url: 'https://aka.ms/vscode-documentdb-migration-support', | ||
|
|
||
| group: 'Learn More', | ||
| alwaysShow: true, | ||
| }, | ||
| ]; | ||
|
|
||
| const selectedItem = await context.ui.showQuickPick([...installedProviders, ...announcedProviers, ...commonItems], { | ||
tnaum-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| enableGrouping: true, | ||
| placeHolder: l10n.t('Choose the data migration provider…'), | ||
| stepName: 'selectMigrationProvider', | ||
| suppressPersistence: true, | ||
| }); | ||
|
|
||
| context.telemetry.properties.connectionMode = selectedItem.id; | ||
|
|
||
| if (selectedItem.id === 'learnMore') { | ||
| context.telemetry.properties.migrationLearnMore = 'true'; | ||
| if ('url' in selectedItem && selectedItem.url) { | ||
| await openUrl(selectedItem.url); | ||
| } | ||
| } | ||
|
|
||
| if (selectedItem.id?.startsWith(ANNOUNCED_PROVIDER_PREFIX)) { | ||
| context.telemetry.properties.migrationAddProvider = 'true'; | ||
| if ('marketplaceId' in selectedItem && selectedItem.marketplaceId) { | ||
| commands.executeCommand('extension.open', selectedItem.marketplaceId); | ||
| } | ||
| } | ||
|
|
||
| // if (selectedItem.id === 'addMigrationProvider') { | ||
| // context.telemetry.properties.addMigrationProvider = 'true'; | ||
| // commands.executeCommand('workbench.extensions.search', '"DocumentDB Migration Plugin"'); | ||
| // return; | ||
| // } | ||
|
|
||
| if (installedProviders.some((provider) => provider.id === selectedItem.id)) { | ||
| const selectedProvider = MigrationService.getProvider(nonNullValue(selectedItem.id, 'selectedItem.id')); | ||
|
|
||
| if (!selectedProvider) { | ||
| return; | ||
| } | ||
|
|
||
| context.telemetry.properties.migrationProvider = selectedProvider.id; | ||
|
|
||
| // Check if the selected provider requires authentication for the default action | ||
| if (selectedProvider.requiresAuthentication) { | ||
| const authenticated = await ensureAuthentication(context, node); | ||
| if (!authenticated) { | ||
| void context.ui.showWarningMessage( | ||
| l10n.t('Authentication is required to use this migration provider.'), | ||
| { | ||
| modal: true, | ||
| detail: l10n.t('Please authenticate first by expanding the tree item of the selected cluster.'), | ||
| }, | ||
| ); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| // Construct the options object with available context | ||
| const options = { | ||
| connectionString: await node.getConnectionString(), | ||
| extendedProperties: { | ||
| clusterId: node.cluster.id, | ||
| }, | ||
| }; | ||
|
|
||
| // Get available actions from the provider | ||
| const availableActions = await selectedProvider.getAvailableActions(options); | ||
|
|
||
| if (availableActions.length === 0) { | ||
| // No actions available, execute default action | ||
| return selectedProvider.executeAction(options); | ||
| } | ||
|
|
||
| // Extend actions with Learn More option if provider has a learn more URL | ||
| const extendedActions: (QuickPickItem & { | ||
| id: string; | ||
| url?: string; | ||
| requiresAuthentication?: boolean; | ||
| })[] = [...availableActions]; | ||
|
|
||
| const url = selectedProvider.getLearnMoreUrl?.(); | ||
|
|
||
| if (url) { | ||
| extendedActions.push( | ||
| { id: 'separator', label: '', kind: QuickPickItemKind.Separator }, | ||
| { | ||
| id: 'learnMore', | ||
| label: l10n.t('Learn more…'), | ||
| detail: l10n.t('Learn more about {0}.', selectedProvider.label), | ||
| url, | ||
| alwaysShow: true, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| // Show action picker to user | ||
| const selectedAction = await context.ui.showQuickPick(extendedActions, { | ||
| placeHolder: l10n.t('Choose the migration action…'), | ||
| stepName: 'selectMigrationAction', | ||
| suppressPersistence: true, | ||
| }); | ||
|
|
||
| if (selectedAction.id === 'learnMore') { | ||
| context.telemetry.properties.migrationLearnMore = 'true'; | ||
| if (selectedAction.url) { | ||
| await openUrl(selectedAction.url); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Check if selected action requires authentication | ||
| if (selectedAction.requiresAuthentication) { | ||
| const authenticated = await ensureAuthentication(context, node); | ||
| if (!authenticated) { | ||
| void context.ui.showWarningMessage(l10n.t('Authentication is required to run this action.'), { | ||
| modal: true, | ||
| detail: l10n.t('Please authenticate first by expanding the tree item of the selected cluster.'), | ||
| }); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| context.telemetry.properties.migrationAction = selectedAction.id; | ||
|
|
||
| // Execute the selected action | ||
| await selectedProvider.executeAction(options, selectedAction.id); | ||
| } catch (error) { | ||
| // Log the error and re-throw to be handled by the caller | ||
| console.error('Error during migration provider execution:', error); | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Ensures the user is authenticated for migration operations. | ||
| * This function should be implemented to handle the specific authentication flow | ||
| * required by the host extension. | ||
| * | ||
| * @param context - The action context for UI operations and telemetry | ||
| * @returns Promise<boolean> - true if authentication succeeded, false otherwise | ||
| */ | ||
| async function ensureAuthentication(_context: IActionContext, _node: ClusterItemBase): Promise<boolean> { | ||
| if (CredentialCache.hasCredentials(_node.cluster.id)) { | ||
| return Promise.resolve(true); // Credentials already exist, no need to authenticate again | ||
| } | ||
|
|
||
| return Promise.resolve(false); // Return false until implementation is complete | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.