mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -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 : []
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user