Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msJinLei committed Jun 24, 2024
1 parent 3315532 commit f6a9cea
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
28 changes: 23 additions & 5 deletions src/Authentication.Abstractions/AuthenticationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using System.Collections.Concurrent;
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
{
Expand All @@ -25,11 +27,6 @@ public class AuthenticationInfo : IAuthenticationInfo
/// </summary>
public string TokenCredentialName { get; set; }

/// <summary>
/// Authority Uri to do the authentiation
/// </summary>
public string AuthorityUri { get; set; }

/// <summary>
/// Authentication process succeed or not.
/// </summary>
Expand All @@ -38,11 +35,32 @@ public class AuthenticationInfo : IAuthenticationInfo
/// <summary>
/// Additional properties for AuthenticationInfo
/// </summary>
[JsonIgnore]
[XmlIgnore]
public IDictionary<string, string> ExtendedProperties { get; } = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

public AuthenticationInfo()
{
TokenCredentialName = null;
}

public AuthenticationInfo(IAuthenticationInfo other, bool? isSuccess = null)
{
this.TokenCredentialName = other.TokenCredentialName;
this.AuthenticationSuccess = isSuccess ?? other.AuthenticationSuccess;
foreach(var property in other.ExtendedProperties)
{
this.SetProperty(property.Key, property.Value);
}
}

/// <summary>
/// Key to show whether token cache is enabled or not.
/// </summary>
public const string TokenCacheEnabled = "TokenCacheEnabled";

public const string AuthInfoTelemetryHeadKey = "auth-info-head";

public const string AuthInfoTelemetrySubsequentKey = "auth-info-sub";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Security;

namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
Expand Down Expand Up @@ -98,6 +99,6 @@ IAccessToken Authenticate(
/// <summary>
/// Get the information to be recorded in Telemetry
/// </summary>
IAuthenticationInfo GetDataForTelemetry();
IList<IAuthenticationInfo> GetDataForTelemetry();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public interface IAuthenticationInfo : IExtensibleModel
/// </summary>
string TokenCredentialName { get; set; }

/// <summary>
/// Authority Uri to do the authentiation
/// </summary>
string AuthorityUri { get; set; }

/// <summary>
/// Authentication process succeed or not.
/// </summary>
Expand Down
26 changes: 19 additions & 7 deletions src/Common/MetricHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,28 @@ public void SetPSHost(PSHost host)
{
}

private static void PopulateAuthenticationInfoFromQos(IAuthenticationInfo info, IDictionary<string, string> eventProperties)
private static void PopulateAuthenticationInfoFromQos(IEnumerable<IAuthenticationInfo> infos, IDictionary<string, string> eventProperties)
{
eventProperties[$"auth-info-{nameof(info.TokenCredentialName).ToLower()}"] = info.TokenCredentialName;
eventProperties[$"auth-info-{nameof(info.AuthorityUri).ToLower()}"] = info.AuthorityUri;
eventProperties[$"auth-info-{nameof(info.AuthenticationSuccess).ToLower()}"] = info.AuthenticationSuccess.ToString();
var enumerator = infos.GetEnumerator();
if (enumerator.MoveNext())
{
var info = enumerator.Current;
eventProperties[$"{AuthenticationInfo.AuthInfoTelemetryHeadKey}-{nameof(info.TokenCredentialName).ToLower()}"] = info.TokenCredentialName;
eventProperties[$"{AuthenticationInfo.AuthInfoTelemetryHeadKey}-{nameof(info.AuthenticationSuccess).ToLower()}"] = info.AuthenticationSuccess.ToString();

foreach (var property in info.ExtendedProperties)
{
eventProperties[$"{AuthenticationInfo.AuthInfoTelemetryHeadKey}-{property.Key.ToLower()}"] = property.Value;
}
}

foreach (var property in info.ExtendedProperties)
var subAuthInfos = new List<AuthenticationInfo>();
while (enumerator.MoveNext())
{
eventProperties[$"auth-info-{property.Key.ToLower()}"] = property.Value;
var info = enumerator.Current;
subAuthInfos.Add(info as AuthenticationInfo);
}
eventProperties[AuthenticationInfo.AuthInfoTelemetrySubsequentKey] = JsonConvert.SerializeObject(subAuthInfos);
}

private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string, string> eventProperties, bool populateException = false)
Expand Down Expand Up @@ -691,7 +703,7 @@ public class AzurePSQoSEvent

public SanitizerTelemetry SanitizerInfo { get; set; }

public IAuthenticationInfo AuthInfo { get; set; }
public IEnumerable<IAuthenticationInfo> AuthInfo { get; set; }

public AzurePSQoSEvent()
{
Expand Down

0 comments on commit f6a9cea

Please sign in to comment.