Skip to content
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

[Port] improve account and tenant selection error handling (#17476) #17489

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/sql-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"aiKey": "AIF-37eefaf0-8022-4671-a3fb-64752724682e",
"engines": {
"vscode": "*",
"azdata": ">=1.29.0"
"azdata": ">=1.33.0"
},
"activationEvents": [
"onDashboardOpen",
Expand Down
2 changes: 1 addition & 1 deletion extensions/sql-migration/src/api/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type AzureProduct = azureResource.AzureGraphResource;

export async function getResourceGroups(account: azdata.Account, subscription: Subscription): Promise<azureResource.AzureResourceResourceGroup[]> {
const api = await getAzureCoreAPI();
const result = await api.getResourceGroups(account, subscription, false);
const result = await api.getResourceGroups(account, subscription, true);
sortResourceArrayByName(result.resourceGroups);
return result.resourceGroups;
}
Expand Down
13 changes: 11 additions & 2 deletions extensions/sql-migration/src/constants/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,19 @@ export function accountLinkedMessage(count: number): string {
}
export const AZURE_TENANT = localize('sql.migration.azure.tenant', "Azure AD tenant");
export function ACCOUNT_STALE_ERROR(account: AzureAccount) {
return localize('azure.accounts.accountStaleError', "The access token for selected account '{0}' is no longer valid. Select 'Link account' and refresh the account, or select a different account.", `${account.displayInfo.displayName} (${account.displayInfo.userId})`);
return localize(
'azure.accounts.accountStaleError',
"The access token for selected account '{0}' and tenant '{1}' is no longer valid. Select 'Link account' and refresh the account, or select a different account.",
`${account?.displayInfo?.displayName} (${account?.displayInfo?.userId})`,
`${account?.properties?.tenants[0]?.displayName} (${account?.properties?.tenants[0]?.userId})`);
}
export function ACCOUNT_ACCESS_ERROR(account: AzureAccount, error: Error) {
return localize('azure.accounts.accountAccessError', "An error occurred while accessing the selected account '{0}'. Select 'Link account' and refresh the account, or select a different account. Error '{1}'", `${account.displayInfo.displayName} (${account.displayInfo.userId})`, error.message);
return localize(
'azure.accounts.accountAccessError',
"An error occurred while accessing the selected account '{0}' and tenant '{1}'. Select 'Link account' and refresh the account, or select a different account. Error '{2}'",
`${account?.displayInfo?.displayName} (${account?.displayInfo?.userId})`,
`${account?.properties?.tenants[0]?.displayName} (${account?.properties?.tenants[0]?.userId})`,
error.message);
}

// database backup page
Expand Down
17 changes: 12 additions & 5 deletions extensions/sql-migration/src/wizard/accountsSelectionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class AccountsSelectionPage extends MigrationWizardPage {
}
if (this.migrationStateModel._azureAccount?.isStale) {
this.wizard.message = {
level: azdata.window.MessageLevel.Error,
text: constants.ACCOUNT_STALE_ERROR(this.migrationStateModel._azureAccount)
};
return false;
Expand Down Expand Up @@ -193,8 +194,6 @@ export class AccountsSelectionPage extends MigrationWizardPage {
this.migrationStateModel._targetSubscription = undefined!;
this.migrationStateModel._databaseBackup.subscription = undefined!;
}
const selectedAzureAccount = this.migrationStateModel.getAccount(selectedIndex);
this.migrationStateModel._azureAccount = deepClone(selectedAzureAccount);

}));

Expand Down Expand Up @@ -233,16 +232,24 @@ export class AccountsSelectionPage extends MigrationWizardPage {
public async onPageEnter(pageChangeInfo: azdata.window.WizardPageChangeInfo): Promise<void> {
this.wizard.registerNavigationValidator(async pageChangeInfo => {
try {
if (!this.migrationStateModel._azureAccount?.isStale) {
this.wizard.message = { text: '', };

if (this.migrationStateModel._azureAccount && !this.migrationStateModel._azureAccount?.isStale) {
const subscriptions = await getSubscriptions(this.migrationStateModel._azureAccount);
if (subscriptions?.length > 0) {
return true;
}
}

this.wizard.message = { text: constants.ACCOUNT_STALE_ERROR(this.migrationStateModel._azureAccount) };
this.wizard.message = {
level: azdata.window.MessageLevel.Error,
text: constants.ACCOUNT_STALE_ERROR(this.migrationStateModel._azureAccount),
};
} catch (error) {
this.wizard.message = { text: constants.ACCOUNT_ACCESS_ERROR(this.migrationStateModel._azureAccount, error) };
this.wizard.message = {
level: azdata.window.MessageLevel.Error,
text: constants.ACCOUNT_ACCESS_ERROR(this.migrationStateModel._azureAccount, error),
};
}

return false;
Expand Down