Migrate from @azure/core-http to @azure/core-rest-pipeline (#1040)

This commit is contained in:
Jeremy Meng 2022-11-28 10:43:16 -08:00 коммит произвёл GitHub
Родитель 2f626c2cfe
Коммит 358fbceef7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 500 добавлений и 608 удалений

Просмотреть файл

@ -1,4 +1,4 @@
import azureCore = require("@azure/core-http");
import * as azureCoreAuth from "@azure/core-auth";
import * as types from "../applicationinsights";
import * as Helpers from "./Helpers";
@ -45,7 +45,7 @@ export function setStatusLogger(statusLogger: StatusLogger) {
* Try to setup and start this app insights instance if attach is enabled.
* @param aadTokenCredential Optional AAD credential
*/
export function setupAndStart(aadTokenCredential?: azureCore.TokenCredential): typeof types | null {
export function setupAndStart(aadTokenCredential?: azureCoreAuth.TokenCredential): typeof types | null {
// If app already contains SDK, skip agent attach
if (!forceStart && Helpers.sdkAlreadyExists(_logger)) {
_statusLogger.logStatus({

Просмотреть файл

@ -1,6 +1,6 @@
import http = require("http");
import https = require("https");
import azureCore = require("@azure/core-http");
import * as azureCoreAuth from "@azure/core-auth";
import { DistributedTracingModes } from "../applicationinsights";
import { IDisabledExtendedMetrics } from "../AutoCollection/NativePerformance";
@ -216,5 +216,5 @@ export interface IConfig extends IBaseConfig {
/** An https.Agent to use for SDK HTTPS traffic (Optional, Default undefined) */
httpsAgent: https.Agent;
/** AAD TokenCredential to use to authenticate the app */
aadTokenCredential?: azureCore.TokenCredential;
aadTokenCredential?: azureCoreAuth.TokenCredential;
}

Просмотреть файл

@ -1,34 +1,34 @@
import http = require("http");
import https = require("https");
import azureCore = require("@azure/core-http");
import azureCoreAuth = require("@azure/core-auth");
import azureCore = require("@azure/core-rest-pipeline");
const applicationInsightsResource = "https://monitor.azure.com//.default";
function emptySendRequest(_request: azureCore.PipelineRequest): Promise<azureCore.PipelineResponse> {
return null;
}
class AuthorizationHandler {
private _azureTokenPolicy: azureCore.RequestPolicy;
private _azureTokenPolicy: azureCore.PipelinePolicy;
constructor(credential: azureCore.TokenCredential) {
constructor(credential: azureCoreAuth.TokenCredential) {
let scopes: string[] = [applicationInsightsResource];
let emptyPolicy: azureCore.RequestPolicy = {
sendRequest(httpRequest: azureCore.WebResourceLike): Promise<azureCore.HttpOperationResponse> {
return null;
}
};
this._azureTokenPolicy = azureCore.bearerTokenAuthenticationPolicy(credential, scopes).create(emptyPolicy, new azureCore.RequestPolicyOptions());
this._azureTokenPolicy = azureCore.bearerTokenAuthenticationPolicy({credential, scopes});
}
/**
* Applies the Bearer token to the request through the Authorization header.
*/
public async addAuthorizationHeader(requestOptions: http.RequestOptions | https.RequestOptions): Promise<void> {
let authHeaderName = azureCore.Constants.HeaderConstants.AUTHORIZATION;
let webResource = new azureCore.WebResource("https://");
await this._azureTokenPolicy.sendRequest(webResource);
let authHeaderName = "authorization";
let webResource = azureCore.createPipelineRequest({ url: "https://" });
await this._azureTokenPolicy.sendRequest(webResource, emptySendRequest);
console.log("#### webResource", webResource);
requestOptions.headers[authHeaderName] = webResource.headers.get(authHeaderName);
}
}
export = AuthorizationHandler;
export = AuthorizationHandler;

Просмотреть файл

@ -1,4 +1,4 @@
import azureCore = require("@azure/core-http");
import azureCoreAuth = require("@azure/core-auth");
import CorrelationIdManager = require("./CorrelationIdManager");
import ConnectionStringParser = require("./ConnectionStringParser");
@ -33,7 +33,7 @@ class Config implements IConfig {
public httpAgent: http.Agent;
public httpsAgent: https.Agent;
public ignoreLegacyHeaders: boolean;
public aadTokenCredential?: azureCore.TokenCredential;
public aadTokenCredential?: azureCoreAuth.TokenCredential;
public enableAutoCollectConsole: boolean;
public enableAutoCollectExceptions: boolean;
public enableAutoCollectPerformance: boolean;

Просмотреть файл

@ -1,6 +1,5 @@
import url = require("url");
import os = require("os");
import azureCore = require("@azure/core-http");
import Config = require("./Config");
import AuthorizationHandler = require("./AuthorizationHandler");
@ -273,4 +272,4 @@ class TelemetryClient {
}
}
export = TelemetryClient;
export = TelemetryClient;

Просмотреть файл

@ -1,13 +1,13 @@
import assert = require("assert");
import https = require("https");
import sinon = require("sinon");
import azureCore = require("@azure/core-http");
import azureCoreAuth = require("@azure/core-auth");
import AuthorizationHandler = require("../../Library/AuthorizationHandler");
import Config = require("../../Library/Config");
import Util = require("../../Library/Util");
class TestTokenCredential implements azureCore.TokenCredential {
class TestTokenCredential implements azureCoreAuth.TokenCredential {
private _expiresOn: Date;
private _numberOfRefreshs = 0;
@ -71,4 +71,4 @@ describe("Library/AuthorizationHandler", () => {
assert.equal(options.headers["authorization"], "Bearer testToken2");
});
});
});
});

Просмотреть файл

@ -3,7 +3,6 @@ import https = require("https");
import sinon = require("sinon");
import Sinon = require("sinon");
import eventEmitter = require('events');
import azureCore = require("@azure/core-http");
import AutoCollecPreAggregatedMetrics = require("../../AutoCollection/PreAggregatedMetrics");
import Client = require("../../Library/NodeClient");

1055
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -64,7 +64,8 @@
"typescript": "4.1.2"
},
"dependencies": {
"@azure/core-http": "^2.2.3",
"@azure/core-auth": "^1.4.0",
"@azure/core-rest-pipeline": "^1.10.0",
"@microsoft/applicationinsights-web-snippet": "^1.0.1",
"@opentelemetry/api": "^1.0.4",
"@opentelemetry/core": "^1.0.1",