mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 01:25:38 -05:00
add delete migration method in migration list and details pages (#22243)
* add delete migraiton, fix stale token detection * address pr comments, fix api error response format
This commit is contained in:
@@ -286,7 +286,11 @@ export async function getVMInstanceView(sqlVm: SqlVMServer, account: azdata.Acco
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.GET, undefined, true, host);
|
||||
|
||||
if (response.errors.length > 0) {
|
||||
throw new Error(response.errors.toString());
|
||||
const message = response.errors
|
||||
.map(err => err.message)
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
|
||||
}
|
||||
|
||||
return response.response.data;
|
||||
@@ -299,7 +303,11 @@ export async function getAzureResourceGivenId(account: azdata.Account, subscript
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.GET, undefined, true, host);
|
||||
|
||||
if (response.errors.length > 0) {
|
||||
throw new Error(response.errors.toString());
|
||||
const message = response.errors
|
||||
.map(err => err.message)
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
|
||||
}
|
||||
|
||||
return response.response.data;
|
||||
@@ -620,6 +628,19 @@ export async function stopMigration(account: azdata.Account, subscription: Subsc
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteMigration(account: azdata.Account, subscription: Subscription, migrationId: string): Promise<void> {
|
||||
const api = await getAzureCoreAPI();
|
||||
const path = encodeURI(`${migrationId}?api-version=${DMSV2_API_VERSION}`);
|
||||
const host = api.getProviderMetadataForAccount(account).settings.armResource?.endpoint;
|
||||
const response = await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.DELETE, undefined, true, host);
|
||||
if (response.errors.length > 0) {
|
||||
const message = response.errors
|
||||
.map(err => err.message)
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getLocationDisplayName(location: string): Promise<string> {
|
||||
const api = await getAzureCoreAPI();
|
||||
return api.getRegionDisplayName(location);
|
||||
|
||||
@@ -26,6 +26,7 @@ export const MenuCommands = {
|
||||
ViewService: 'sqlmigration.view.service',
|
||||
CopyMigration: 'sqlmigration.copy.migration',
|
||||
CancelMigration: 'sqlmigration.cancel.migration',
|
||||
DeleteMigration: 'sqlmigration.delete.migration',
|
||||
RetryMigration: 'sqlmigration.retry.migration',
|
||||
StartMigration: 'sqlmigration.start',
|
||||
StartLoginMigration: 'sqlmigration.login.start',
|
||||
@@ -423,7 +424,7 @@ export async function getAzureAccountsDropdownValues(accounts: Account[]): Promi
|
||||
accounts.forEach((account) => {
|
||||
accountsValues.push({
|
||||
name: account.displayInfo.userId,
|
||||
displayName: account.isStale
|
||||
displayName: isAccountTokenStale(account)
|
||||
? constants.ACCOUNT_CREDENTIALS_REFRESH(account.displayInfo.displayName)
|
||||
: account.displayInfo.displayName
|
||||
});
|
||||
@@ -439,6 +440,10 @@ export async function getAzureAccountsDropdownValues(accounts: Account[]): Promi
|
||||
return accountsValues;
|
||||
}
|
||||
|
||||
export function isAccountTokenStale(account: Account | undefined): boolean {
|
||||
return account === undefined || account?.isStale === true;
|
||||
}
|
||||
|
||||
export function getAzureTenants(account?: Account): Tenant[] {
|
||||
return account?.properties.tenants || [];
|
||||
}
|
||||
@@ -446,9 +451,9 @@ export function getAzureTenants(account?: Account): Tenant[] {
|
||||
export async function getAzureSubscriptions(account?: Account): Promise<azureResource.AzureResourceSubscription[]> {
|
||||
let subscriptions: azureResource.AzureResourceSubscription[] = [];
|
||||
try {
|
||||
if (account) {
|
||||
subscriptions = !account.isStale ? await azure.getSubscriptions(account) : [];
|
||||
}
|
||||
subscriptions = account && !isAccountTokenStale(account)
|
||||
? await azure.getSubscriptions(account)
|
||||
: [];
|
||||
} catch (e) {
|
||||
logError(TelemetryViews.Utils, 'utils.getAzureSubscriptions', e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user