Auto-Instrumentation - Enable AI SDK to honor repacked Azure.Identity assembly name (#2406)

* Redfield AAD change.

* Test changes

* PR Feedback

* azureCoreAssemblyName lowercase
This commit is contained in:
Rajkumar Rangaraj 2021-09-08 08:27:13 -07:00 коммит произвёл GitHub
Родитель d54bae8aea
Коммит b6483cd488
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 21 добавлений и 16 удалений

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

@ -1,4 +1,4 @@
#if !NET452 && !NET46
#if !NET452 && !NET46 && !REDFIELD
namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementation.Authentication
{
using System;
@ -302,7 +302,7 @@ namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementati
var test = compiledExpression2.DynamicInvoke(objAccessToken);
}
#region TestClasses
#region TestClasses
/// <summary>
/// This class inherits <see cref="MockCredential"/> which inherits <see cref="Azure.Core.TokenCredential"/>.

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

@ -1,4 +1,4 @@
#if !NET452 && !NET46
#if !NET452 && !NET46 && !REDFIELD
namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementation.Authentication
{
using System;

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

@ -1,4 +1,4 @@
#if !NET452 && !NET46
#if !NET452 && !NET46 && !REDFIELD
namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementation.Authentication
{
using System;

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

@ -1,4 +1,4 @@
#if !NET452 && !NET46
#if !NET452 && !NET46 && !REDFIELD
namespace Microsoft.ApplicationInsights.TestFramework.Implementation
{
using Microsoft.ApplicationInsights.Channel;

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

@ -19,6 +19,12 @@
/// </remarks>
internal class ReflectionCredentialEnvelope : CredentialEnvelope
{
#if REDFIELD
private static volatile string azureCoreAssemblyName = "Azure.Identity.ILRepack";
#else
private static volatile string azureCoreAssemblyName = "Azure.Core";
#endif
private readonly object tokenCredential;
private readonly object tokenRequestContext;
@ -102,8 +108,7 @@
/// </returns>
private static Type GetTokenCredentialType()
{
var typeName = "Azure.Core.TokenCredential, Azure.Core";
var assemblyName = "Azure.Core";
var typeName = $"Azure.Core.TokenCredential, {azureCoreAssemblyName}";
Type typeTokenCredential = null;
@ -118,7 +123,7 @@
if (typeTokenCredential == null)
{
if (AppDomain.CurrentDomain.GetAssemblies().Any(x => x.FullName.StartsWith(assemblyName)))
if (AppDomain.CurrentDomain.GetAssemblies().Any(x => x.FullName.StartsWith(azureCoreAssemblyName)))
{
throw new Exception("An unknown error has occurred. Failed to get type Azure.Core.TokenCredential. Detected that Azure.Core is loaded in AppDomain.CurrentDomain.");
}
@ -169,7 +174,7 @@
internal static object MakeTokenRequestContext(string[] scopes)
{
return Activator.CreateInstance(
type: Type.GetType("Azure.Core.TokenRequestContext, Azure.Core"),
type: Type.GetType($"Azure.Core.TokenRequestContext, {azureCoreAssemblyName}"),
args: new object[] { scopes, null, });
}
@ -183,7 +188,7 @@
/// </returns>
private static Delegate BuildDelegateAccessTokenToAuthToken()
{
Type typeAccessToken = Type.GetType("Azure.Core.AccessToken, Azure.Core");
Type typeAccessToken = Type.GetType($"Azure.Core.AccessToken, {azureCoreAssemblyName}");
var parameterExpression_AccessToken = Expression.Parameter(typeAccessToken, "parameterExpression_AccessToken");
@ -218,8 +223,8 @@
/// </returns>
private static Delegate BuildDelegateGetToken()
{
Type typeTokenCredential = Type.GetType("Azure.Core.TokenCredential, Azure.Core");
Type typeTokenRequestContext = Type.GetType("Azure.Core.TokenRequestContext, Azure.Core");
Type typeTokenCredential = Type.GetType($"Azure.Core.TokenCredential, {azureCoreAssemblyName}");
Type typeTokenRequestContext = Type.GetType($"Azure.Core.TokenRequestContext, {azureCoreAssemblyName}");
Type typeCancellationToken = typeof(CancellationToken);
var parameterExpression_tokenCredential = Expression.Parameter(type: typeTokenCredential, name: "parameterExpression_TokenCredential");
@ -255,8 +260,8 @@
/// </returns>
private static Delegate BuildDelegateGetTokenAsync()
{
Type typeTokenCredential = Type.GetType("Azure.Core.TokenCredential, Azure.Core");
Type typeTokenRequestContext = Type.GetType("Azure.Core.TokenRequestContext, Azure.Core");
Type typeTokenCredential = Type.GetType($"Azure.Core.TokenCredential, {azureCoreAssemblyName}");
Type typeTokenRequestContext = Type.GetType($"Azure.Core.TokenRequestContext, {azureCoreAssemblyName}");
Type typeCancellationToken = typeof(CancellationToken);
var parameterExpression_TokenCredential = Expression.Parameter(type: typeTokenCredential, name: "parameterExpression_TokenCredential");
@ -297,8 +302,8 @@
/// </returns>
private static Delegate BuildGetTaskResult()
{
Type typeTokenCredential = Type.GetType("Azure.Core.TokenCredential, Azure.Core");
Type typeTokenRequestContext = Type.GetType("Azure.Core.TokenRequestContext, Azure.Core");
Type typeTokenCredential = Type.GetType($"Azure.Core.TokenCredential, {azureCoreAssemblyName}");
Type typeTokenRequestContext = Type.GetType($"Azure.Core.TokenRequestContext, {azureCoreAssemblyName}");
Type typeCancellationToken = typeof(CancellationToken);
var methodInfo_GetTokenAsync = typeTokenCredential.GetMethod(name: "GetTokenAsync", types: new Type[] { typeTokenRequestContext, typeCancellationToken });
var methodInfo_AsTask = methodInfo_GetTokenAsync.ReturnType.GetMethod("AsTask");