mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Rename 'body' to 'data' to prevent breaking change (#22761)
This commit is contained in:
@@ -473,7 +473,7 @@ export abstract class AzureAuth implements vscode.Disposable {
|
||||
}
|
||||
});
|
||||
|
||||
const data = tenantResponse.body;
|
||||
const data = tenantResponse.data;
|
||||
if (data.error) {
|
||||
Logger.error(`Error fetching tenants :${data.error.code} - ${data.error.message}`);
|
||||
throw new Error(`${data.error.code} - ${data.error.message}`);
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
import { INetworkModule, NetworkRequestOptions, NetworkResponse } from '@azure/msal-common';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
import { TextEncoder } from 'util';
|
||||
import { getNetworkResponse, urlToHttpOptions } from './networkUtils';
|
||||
import { getNetworkResponse, NetworkRequestOptions, NetworkResponse, urlToHttpOptions } from './networkUtils';
|
||||
|
||||
/**
|
||||
* http methods
|
||||
@@ -39,7 +37,7 @@ export enum ProxyStatus {
|
||||
/**
|
||||
* This class implements the API for network requests.
|
||||
*/
|
||||
export class HttpClient implements INetworkModule {
|
||||
export class HttpClient {
|
||||
private proxyUrl: string;
|
||||
private customAgentOptions: http.AgentOptions | https.AgentOptions;
|
||||
static readonly AUTHORIZATION_PENDING: string = 'authorization_pending';
|
||||
@@ -59,12 +57,13 @@ export class HttpClient implements INetworkModule {
|
||||
*/
|
||||
async sendGetRequestAsync<T>(
|
||||
url: string,
|
||||
options?: NetworkRequestOptions
|
||||
options?: NetworkRequestOptions,
|
||||
cancellationToken?: number | undefined
|
||||
): Promise<NetworkResponse<T>> {
|
||||
if (this.proxyUrl) {
|
||||
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.GET, options, this.customAgentOptions as http.AgentOptions);
|
||||
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.GET, options, this.customAgentOptions as http.AgentOptions, cancellationToken);
|
||||
} else {
|
||||
return networkRequestViaHttps(url, HttpMethod.GET, options, this.customAgentOptions as https.AgentOptions);
|
||||
return networkRequestViaHttps(url, HttpMethod.GET, options, this.customAgentOptions as https.AgentOptions, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +256,7 @@ const networkRequestViaProxy = <T>(
|
||||
if (((httpStatusCode < HttpStatus.SUCCESS_RANGE_START) || (httpStatusCode > HttpStatus.SUCCESS_RANGE_END)) &&
|
||||
// do not destroy the request for the device code flow
|
||||
// @ts-ignore
|
||||
networkResponse.body['error'] !== HttpClient.AUTHORIZATION_PENDING) {
|
||||
networkResponse.data['error'] !== HttpClient.AUTHORIZATION_PENDING) {
|
||||
request.destroy();
|
||||
}
|
||||
resolve(networkResponse);
|
||||
@@ -352,7 +351,7 @@ const networkRequestViaHttps = <T>(
|
||||
if (((statusCode < HttpStatus.SUCCESS_RANGE_START) || (statusCode > HttpStatus.SUCCESS_RANGE_END)) &&
|
||||
// do not destroy the request for the device code flow
|
||||
// @ts-ignore
|
||||
networkResponse.body['error'] !== HttpClient.AUTHORIZATION_PENDING) {
|
||||
networkResponse.data['error'] !== HttpClient.AUTHORIZATION_PENDING) {
|
||||
request.destroy();
|
||||
}
|
||||
resolve(networkResponse);
|
||||
|
||||
@@ -4,17 +4,27 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { NetworkResponse } from '@azure/msal-common';
|
||||
import * as https from 'https';
|
||||
|
||||
export function getNetworkResponse<Body>(headers: Record<string, string>, body: Body, statusCode: number): NetworkResponse<Body> {
|
||||
return {
|
||||
headers: headers,
|
||||
body: body,
|
||||
data: body,
|
||||
status: statusCode
|
||||
};
|
||||
}
|
||||
|
||||
export declare type NetworkResponse<T> = {
|
||||
headers: Record<string, string>;
|
||||
data: T;
|
||||
status: number;
|
||||
};
|
||||
|
||||
export declare type NetworkRequestOptions = {
|
||||
headers?: Record<string, string>;
|
||||
body?: string;
|
||||
};
|
||||
|
||||
/*
|
||||
* Utility function that converts a URL object into an ordinary options object as expected by the
|
||||
* http.request and https.request APIs.
|
||||
|
||||
@@ -171,7 +171,7 @@ export async function getLocations(appContext: AppContext, account?: AzureAccoun
|
||||
const path = `/subscriptions/${subscription.id}/locations?api-version=2020-01-01`;
|
||||
const host = getProviderMetadataForAccount(account).settings.armResource.endpoint;
|
||||
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors, host);
|
||||
result.locations.push(...response.response.body.value);
|
||||
result.locations.push(...response.response.data.value);
|
||||
result.errors.push(...response.errors);
|
||||
} catch (err) {
|
||||
const error = new Error(localize('azure.accounts.getLocations.queryError', "Error fetching locations for account {0} ({1}) subscription {2} ({3}) tenant {4} : {5}",
|
||||
@@ -448,8 +448,8 @@ export async function makeHttpRequest(account: AzureAccount, subscription: azure
|
||||
} else if (response.status < 200 || response.status > 299) {
|
||||
let errorMessage: string[] = [];
|
||||
errorMessage.push(response.status.toString());
|
||||
if (response.body && response.body.error) {
|
||||
errorMessage.push(`${response.body.error.code} : ${response.body.error.message}`);
|
||||
if (response.data && response.data.error) {
|
||||
errorMessage.push(`${response.data.error.code} : ${response.data.error.message}`);
|
||||
}
|
||||
const error = new Error(errorMessage.join(EOL));
|
||||
if (!ignoreErrors) {
|
||||
@@ -468,7 +468,7 @@ export async function getManagedDatabases(account: AzureAccount, subscription: a
|
||||
const host = getProviderMetadataForAccount(account).settings.armResource.endpoint;
|
||||
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors, host);
|
||||
return {
|
||||
databases: response?.response?.body?.value ?? [],
|
||||
databases: response?.response?.data?.value ?? [],
|
||||
errors: response.errors ? response.errors : []
|
||||
};
|
||||
}
|
||||
@@ -478,7 +478,7 @@ export async function getBlobContainers(account: AzureAccount, subscription: azu
|
||||
const host = getProviderMetadataForAccount(account).settings.armResource.endpoint;
|
||||
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors, host);
|
||||
return {
|
||||
blobContainers: response?.response?.body?.value ?? [],
|
||||
blobContainers: response?.response?.data?.value ?? [],
|
||||
errors: response.errors ? response.errors : []
|
||||
};
|
||||
}
|
||||
@@ -488,7 +488,7 @@ export async function getFileShares(account: AzureAccount, subscription: azureRe
|
||||
const host = getProviderMetadataForAccount(account).settings.armResource.endpoint;
|
||||
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors, host);
|
||||
return {
|
||||
fileShares: response?.response?.body?.value ?? [],
|
||||
fileShares: response?.response?.data?.value ?? [],
|
||||
errors: response.errors ? response.errors : []
|
||||
};
|
||||
}
|
||||
@@ -501,7 +501,7 @@ export async function createResourceGroup(account: AzureAccount, subscription: a
|
||||
const host = getProviderMetadataForAccount(account).settings.armResource.endpoint;
|
||||
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.PUT, requestBody, ignoreErrors, host);
|
||||
return {
|
||||
resourceGroup: response?.response?.body,
|
||||
resourceGroup: response?.response?.data,
|
||||
errors: response.errors ? response.errors : []
|
||||
};
|
||||
}
|
||||
@@ -511,8 +511,8 @@ export async function getStorageAccountAccessKey(account: AzureAccount, subscrip
|
||||
const host = getProviderMetadataForAccount(account).settings.armResource.endpoint;
|
||||
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.POST, undefined, ignoreErrors, host);
|
||||
return {
|
||||
keyName1: response?.response?.body?.keys[0].value ?? '',
|
||||
keyName2: response?.response?.body?.keys[0].value ?? '',
|
||||
keyName1: response?.response?.data?.keys[0].value ?? '',
|
||||
keyName2: response?.response?.data?.keys[0].value ?? '',
|
||||
errors: response.errors ? response.errors : []
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export async function getLocations(account: azdata.Account, subscription: Subscr
|
||||
|
||||
const path = `/subscriptions/${subscription.id}/providers/Microsoft.DataMigration?api-version=${ARM_MGMT_API_VERSION}`;
|
||||
const host = api.getProviderMetadataForAccount(account).settings.armResource?.endpoint;
|
||||
const dataMigrationResourceProvider = (await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.GET, undefined, true, host))?.response?.body;
|
||||
const dataMigrationResourceProvider = (await api.makeAzureRestRequest(account, subscription, path, azurecore.HttpRequestMethod.GET, undefined, true, host))?.response?.data;
|
||||
const sqlMigratonResource = dataMigrationResourceProvider?.resourceTypes?.find((r: any) => r.resourceType === 'SqlMigrationServices');
|
||||
const sqlMigrationResourceLocations = sqlMigratonResource?.locations ?? [];
|
||||
if (response.errors?.length > 0) {
|
||||
@@ -245,8 +245,8 @@ export async function getAvailableSqlDatabaseServers(account: azdata.Account, su
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
sortResourceArrayByName(response.response.body.value);
|
||||
return response.response.body.value;
|
||||
sortResourceArrayByName(response.response.data.value);
|
||||
return response.response.data.value;
|
||||
}
|
||||
|
||||
export async function getAvailableSqlDatabases(account: azdata.Account, subscription: Subscription, resourceGroupName: string, serverName: string): Promise<AzureSqlDatabase[]> {
|
||||
@@ -260,8 +260,8 @@ export async function getAvailableSqlDatabases(account: azdata.Account, subscrip
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
sortResourceArrayByName(response.response.body.value);
|
||||
return response.response.body.value;
|
||||
sortResourceArrayByName(response.response.data.value);
|
||||
return response.response.data.value;
|
||||
}
|
||||
|
||||
export async function getAvailableSqlVMs(account: azdata.Account, subscription: Subscription): Promise<SqlVMServer[]> {
|
||||
@@ -276,8 +276,8 @@ export async function getAvailableSqlVMs(account: azdata.Account, subscription:
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
sortResourceArrayByName(response.response.body.value);
|
||||
return response.response.body.value;
|
||||
sortResourceArrayByName(response.response.data.value);
|
||||
return response.response.data.value;
|
||||
}
|
||||
|
||||
export async function getVMInstanceView(sqlVm: SqlVMServer, account: azdata.Account, subscription: Subscription): Promise<VirtualMachineInstanceView> {
|
||||
@@ -294,7 +294,7 @@ export async function getVMInstanceView(sqlVm: SqlVMServer, account: azdata.Acco
|
||||
|
||||
}
|
||||
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getAzureResourceGivenId(account: azdata.Account, subscription: Subscription, id: string, apiVersion: string): Promise<any> {
|
||||
@@ -311,7 +311,7 @@ export async function getAzureResourceGivenId(account: azdata.Account, subscript
|
||||
|
||||
}
|
||||
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getComputeVM(sqlVm: SqlVMServer, account: azdata.Account, subscription: Subscription): Promise<any> {
|
||||
@@ -367,8 +367,8 @@ export async function getSqlMigrationServiceById(account: azdata.Account, subscr
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
response.response.body.properties.resourceGroup = getResourceGroupFromId(response.response.body.id);
|
||||
return response.response.body;
|
||||
response.response.data.properties.resourceGroup = getResourceGroupFromId(response.response.data.id);
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getSqlMigrationServicesByResourceGroup(account: azdata.Account, subscription: Subscription, resouceGroupName: string): Promise<SqlMigrationService[]> {
|
||||
@@ -382,11 +382,11 @@ export async function getSqlMigrationServicesByResourceGroup(account: azdata.Acc
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
sortResourceArrayByName(response.response.body.value);
|
||||
response.response.body.value.forEach((sms: SqlMigrationService) => {
|
||||
sortResourceArrayByName(response.response.data.value);
|
||||
response.response.data.value.forEach((sms: SqlMigrationService) => {
|
||||
sms.properties.resourceGroup = getResourceGroupFromId(sms.id);
|
||||
});
|
||||
return response.response.body.value;
|
||||
return response.response.data.value;
|
||||
}
|
||||
|
||||
export async function getSqlMigrationServices(account: azdata.Account, subscription: Subscription): Promise<SqlMigrationService[]> {
|
||||
@@ -400,11 +400,11 @@ export async function getSqlMigrationServices(account: azdata.Account, subscript
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
sortResourceArrayByName(response.response.body.value);
|
||||
response.response.body.value.forEach((sms: SqlMigrationService) => {
|
||||
sortResourceArrayByName(response.response.data.value);
|
||||
response.response.data.value.forEach((sms: SqlMigrationService) => {
|
||||
sms.properties.resourceGroup = getResourceGroupFromId(sms.id);
|
||||
});
|
||||
return response.response.body.value;
|
||||
return response.response.data.value;
|
||||
}
|
||||
|
||||
export async function createSqlMigrationService(account: azdata.Account, subscription: Subscription, resourceGroupName: string, regionName: string, sqlMigrationServiceName: string, sessionId: string): Promise<SqlMigrationService> {
|
||||
@@ -428,7 +428,7 @@ export async function createSqlMigrationService(account: azdata.Account, subscri
|
||||
let i = 0;
|
||||
for (i = 0; i < maxRetry; i++) {
|
||||
const asyncResponse = await api.makeAzureRestRequest(account, subscription, asyncPath, azurecore.HttpRequestMethod.GET, undefined, true, host);
|
||||
const creationStatus = asyncResponse.response.body.status;
|
||||
const creationStatus = asyncResponse.response.data.status;
|
||||
if (creationStatus === constants.ProvisioningState.Succeeded) {
|
||||
break;
|
||||
} else if (creationStatus === constants.ProvisioningState.Failed) {
|
||||
@@ -439,7 +439,7 @@ export async function createSqlMigrationService(account: azdata.Account, subscri
|
||||
if (i === maxRetry) {
|
||||
throw new Error(constants.DMS_PROVISIONING_FAILED);
|
||||
}
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getSqlMigrationServiceAuthKeys(account: azdata.Account, subscription: Subscription, resourceGroupName: string, regionName: string, sqlMigrationServiceName: string): Promise<SqlMigrationServiceAuthenticationKeys> {
|
||||
@@ -454,8 +454,8 @@ export async function getSqlMigrationServiceAuthKeys(account: azdata.Account, su
|
||||
throw new Error(message);
|
||||
}
|
||||
return {
|
||||
authKey1: response?.response?.body?.authKey1 ?? '',
|
||||
authKey2: response?.response?.body?.authKey2 ?? ''
|
||||
authKey1: response?.response?.data?.authKey1 ?? '',
|
||||
authKey2: response?.response?.data?.authKey2 ?? ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -475,8 +475,8 @@ export async function regenerateSqlMigrationServiceAuthKey(account: azdata.Accou
|
||||
throw new Error(message);
|
||||
}
|
||||
return {
|
||||
authKey1: response?.response?.body?.authKey1 ?? '',
|
||||
authKey2: response?.response?.body?.authKey2 ?? ''
|
||||
authKey1: response?.response?.data?.authKey1 ?? '',
|
||||
authKey2: response?.response?.data?.authKey2 ?? ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ export async function getSqlMigrationServiceMonitoringData(account: azdata.Accou
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function startDatabaseMigration(
|
||||
@@ -532,7 +532,7 @@ export async function startDatabaseMigration(
|
||||
return {
|
||||
asyncUrl: asyncUrl,
|
||||
status: response.response.status,
|
||||
databaseMigration: response.response.body
|
||||
databaseMigration: response.response.data
|
||||
};
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ export async function getMigrationDetails(account: azdata.Account, subscription:
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getServiceMigrations(account: azdata.Account, subscription: Subscription, resourceId: string): Promise<DatabaseMigration[]> {
|
||||
@@ -567,7 +567,7 @@ export async function getServiceMigrations(account: azdata.Account, subscription
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return response.response.body.value;
|
||||
return response.response.data.value;
|
||||
}
|
||||
|
||||
export async function getMigrationTargetInstance(account: azdata.Account, subscription: Subscription, migration: DatabaseMigration): Promise<SqlManagedInstance | SqlVMServer> {
|
||||
@@ -583,7 +583,7 @@ export async function getMigrationTargetInstance(account: azdata.Account, subscr
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function getMigrationAsyncOperationDetails(account: azdata.Account, subscription: Subscription, url: string): Promise<AzureAsyncOperationResource> {
|
||||
@@ -597,7 +597,7 @@ export async function getMigrationAsyncOperationDetails(account: azdata.Account,
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function startMigrationCutover(account: azdata.Account, subscription: Subscription, migration: DatabaseMigration): Promise<any> {
|
||||
@@ -612,7 +612,7 @@ export async function startMigrationCutover(account: azdata.Account, subscriptio
|
||||
.join(', ');
|
||||
throw new Error(message);
|
||||
}
|
||||
return response.response.body.value;
|
||||
return response.response.data.value;
|
||||
}
|
||||
|
||||
export async function stopMigration(account: azdata.Account, subscription: Subscription, migration: DatabaseMigration): Promise<void> {
|
||||
@@ -718,7 +718,7 @@ export async function validateIrSqlDatabaseMigrationSettings(
|
||||
if (response.errors.length > 0) {
|
||||
throw new Error(response.errors.map(e => e.message).join(','));
|
||||
}
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
export async function validateIrDatabaseMigrationSettings(
|
||||
@@ -785,7 +785,7 @@ export async function validateIrDatabaseMigrationSettings(
|
||||
if (response.errors.length > 0) {
|
||||
throw new Error(response.errors.map(e => e.message).join(','));
|
||||
}
|
||||
return response.response.body;
|
||||
return response.response.data;
|
||||
}
|
||||
|
||||
type SortableAzureResources = AzureProduct | azurecore.azureResource.FileShare | azurecore.azureResource.BlobContainer | azurecore.azureResource.Blob | azurecore.azureResource.AzureResourceSubscription | SqlMigrationService;
|
||||
|
||||
Reference in New Issue
Block a user