Adding support for sending request headers in azure core rest request API (#16443)

* Adding support for sending additional headers in azure http requests

* Added session ids in all azure rest calls

* Fixed param name

* Adding default parameter value for request headers
This commit is contained in:
Aasim Khan
2021-07-27 12:36:50 -07:00
committed by GitHub
parent 35207a1e04
commit 7a35d4aeeb
11 changed files with 79 additions and 53 deletions

View File

@@ -333,8 +333,9 @@ export async function getSelectedSubscriptions(appContext: AppContext, account?:
* @param requestBody Optional request body to be used in PUT and POST requests.
* @param ignoreErrors When this flag is set the method will not throw any runtime or service errors and will return the errors in errors array.
* @param host Use this to override the host. The default host is https://management.azure.com
* @param requestHeaders Provide additional request headers
*/
export async function makeHttpRequest(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, path: string, requestType: HttpRequestMethod, requestBody?: any, ignoreErrors: boolean = false, host: string = 'https://management.azure.com'): Promise<AzureRestResponse> {
export async function makeHttpRequest(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, path: string, requestType: HttpRequestMethod, requestBody?: any, ignoreErrors: boolean = false, host: string = 'https://management.azure.com', requestHeaders: { [key: string]: string } = {}): Promise<AzureRestResponse> {
const result: AzureRestResponse = { response: {}, errors: [] };
if (!account?.properties?.tenants || !Array.isArray(account.properties.tenants)) {
@@ -375,11 +376,14 @@ export async function makeHttpRequest(account: azdata.Account, subscription: azu
return result;
}
const reqHeaders = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${securityToken.token}`,
...requestHeaders
};
const config: AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${securityToken.token}`
},
headers: reqHeaders,
validateStatus: () => true // Never throw
};

View File

@@ -271,8 +271,9 @@ declare module 'azurecore' {
* @param requestBody Optional request body to be used in PUT and POST requests.
* @param ignoreErrors When this flag is set the method will not throw any runtime or service errors and will return the errors in errors array.
* @param host Use this to override the host. The default host is https://management.azure.com
* @param requestHeaders Provide additional request headers
*/
makeAzureRestRequest(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, path: string, requestType: HttpRequestMethod, requestBody?: any, ignoreErrors?: boolean, host?: string): Promise<AzureRestResponse>;
makeAzureRestRequest(account: azdata.Account, subscription: azureResource.AzureResourceSubscription, path: string, requestType: HttpRequestMethod, requestBody?: any, ignoreErrors?: boolean, host?: string, requestHeaders?: { [key: string]: string }): Promise<AzureRestResponse>;
/**
* Converts a region value (@see AzureRegion) into the localized Display Name
* @param region The region value

View File

@@ -236,8 +236,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
requestType: azurecore.HttpRequestMethod,
requestBody: any,
ignoreErrors: boolean,
host: string = 'https://management.azure.com'): Promise<azurecore.AzureRestResponse> {
return azureResourceUtils.makeHttpRequest(account, subscription, path, requestType, requestBody, ignoreErrors, host);
host: string = 'https://management.azure.com',
requestHeaders: { [key: string]: string } = {}): Promise<azurecore.AzureRestResponse> {
return azureResourceUtils.makeHttpRequest(account, subscription, path, requestType, requestBody, ignoreErrors, host, requestHeaders);
},
getRegionDisplayName: utils.getRegionDisplayName,
runGraphQuery<T extends azureResource.AzureGraphResource>(account: azdata.Account,