Skip to content

Commit

Permalink
Revise the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msJinLei committed Aug 21, 2024
1 parent b5b77e1 commit 9415a08
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 26 deletions.
27 changes: 19 additions & 8 deletions src/Authentication.Abstractions/AuthTelemetryRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,44 @@
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
{
/// <summary>
/// A model class for authenction telemetry record.
/// Represents a telemetry record for authentication.
/// </summary>
public class AuthTelemetryRecord : IAuthTelemetryRecord
{
/// <summary>
/// Class name of the TokenCredential, stands for the authentication method
/// Gets or sets the class name of the TokenCredential, which stands for the authentication method.
/// </summary>
public string TokenCredentialName { get; set; }

/// <summary>
/// Authentication process succeed or not.
/// Gets or sets a value indicating whether the authentication process succeeded or not.
/// </summary>
public bool AuthenticationSuccess { get; set; } = false;

public bool correlationId { get; set; }
/// <summary>
/// Gets or sets the correlation ID for the authentication.
/// </summary>
public string CorrelationId { get; set; }

/// <summary>
/// Additional properties for AuthenticationInfo
/// Gets the additional properties for AuthenticationInfo.
/// </summary>
[JsonIgnore]
public IDictionary<string, string> ExtendedProperties { get; } = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Initializes a new instance of the <see cref="AuthTelemetryRecord"/> class.
/// </summary>
public AuthTelemetryRecord()
{
TokenCredentialName = null;
}

/// <summary>
/// Initializes a new instance of the <see cref="AuthTelemetryRecord"/> class based on another instance of <see cref="IAuthTelemetryRecord"/>.
/// </summary>
/// <param name="other">The other instance of <see cref="IAuthTelemetryRecord"/>.</param>
/// <param name="isSuccess">A value indicating whether the authentication was successful or not.</param>
public AuthTelemetryRecord(IAuthTelemetryRecord other, bool? isSuccess = null)
{
this.TokenCredentialName = other.TokenCredentialName;
Expand All @@ -59,17 +70,17 @@ public AuthTelemetryRecord(IAuthTelemetryRecord other, bool? isSuccess = null)
}

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

/// <summary>
/// Prefix of properties of the first record of authentication telemetry record.
/// Represents the prefix of properties of the first record of authentication telemetry record.
/// </summary>
public const string AuthTelemetryPropertyHeadPrefix = "auth-info-head";

/// <summary>
/// Key of the left records of authentication telemetry.
/// Represents the key of the left records of authentication telemetry.
/// </summary>
public const string AuthTelemetryPropertyTailKey = "auth-info-tail";
}
Expand Down
10 changes: 7 additions & 3 deletions src/Authentication.Abstractions/AuthenticationTelemetryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
{
/// <summary>
/// A model class for a list of authenction telemetry records.
/// Represents the telemetry data for authentication.
/// </summary>
public class AuthenticationTelemetryData
{
/// <summary>
/// The first record of authentication telemetry data, usually describes the main method of this authentication process.
/// Gets the first record of authentication telemetry data, usually describing the main method of the authentication process.
/// </summary>
public IAuthTelemetryRecord Head { get; } = null;

/// <summary>
/// The left part of authentication telemetry records.
/// Gets the remaining authentication telemetry records.
/// </summary>
public IList<IAuthTelemetryRecord> Tail { get; } = new List<IAuthTelemetryRecord>();

/// <summary>
/// Initializes a new instance of the <see cref="AuthenticationTelemetryData"/> class with the specified authentication telemetry records.
/// </summary>
/// <param name="records">The authentication telemetry records.</param>
public AuthenticationTelemetryData(IEnumerable<IAuthTelemetryRecord> records)
{
var enumerator = records.GetEnumerator();
Expand Down
31 changes: 28 additions & 3 deletions src/Authentication.Abstractions/AzureCmdletContext.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Interfaces;
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Interfaces;

using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
{
/// <summary>
/// Represents the context for an Azure cmdlet.
/// </summary>
public class AzureCmdletContext : ICmdletContext
{
private string cmdletId;

public const ICmdletContext CmdletNone = null;

/// <summary>
/// Initializes a new instance of the <see cref="AzureCmdletContext"/> class with the specified ID.
/// </summary>
/// <param name="id">The ID of the cmdlet.</param>
public AzureCmdletContext(string id)
{
cmdletId = id;
}

/// <summary>
/// Gets or sets the ID of the cmdlet.
/// </summary>
public string CmdletId
{
get => cmdletId;
set => cmdletId = value;
}

/// <summary>
/// Gets a value indicating whether the cmdlet context is valid.
/// </summary>
public bool IsValid
{
get => !string.IsNullOrEmpty(cmdletId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@

namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Extensions
{
/// <summary>
/// Provides extension methods for the <see cref="ICmdletContext"/> interface.
/// </summary>
public static class CmdletContextExtension
{
/// <summary>
/// Converts the <see cref="ICmdletContext"/> object to a dictionary of extensible parameters.
/// </summary>
/// <param name="cmdletContext">The <see cref="ICmdletContext"/> object to convert.</param>
/// <returns>A dictionary of extensible parameters.</returns>
public static IDictionary<string, object> ToExtensibleParameters(this ICmdletContext cmdletContext)
{
if (cmdletContext != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions
{
/// <summary>
/// Representation of an authentication telemetry record
/// Represents a telemetry record for authentication.
/// </summary>
public interface IAuthTelemetryRecord : IExtensibleModel
{
/// <summary>
/// Class name of the TokenCredential, stands for the authentication method
/// Gets or sets the class name of the TokenCredential, which stands for the authentication method.
/// </summary>
string TokenCredentialName { get; set; }

/// <summary>
/// Authentication process succeed or not.
/// Gets or sets a value indicating whether the authentication process succeeded or not.
/// </summary>
bool AuthenticationSuccess { get; set; }

bool correlationId { get; set; }
/// <summary>
/// Gets or sets the correlation ID for the authentication process.
/// </summary>
string CorrelationId { get; set; }
}
}
29 changes: 28 additions & 1 deletion src/Authentication.Abstractions/Interfaces/IAzureTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,44 @@

namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Interfaces
{
public abstract class IAzureTelemetry <T>
/// <summary>
/// Represents an abstract class for Azure telemetry.
/// </summary>
/// <typeparam name="T">The type of telemetry record.</typeparam>
public abstract class IAzureTelemetry<T>
{
private ConcurrentDictionary<string, IList<T>> telemetryDataAccquirer = new ConcurrentDictionary<string, IList<T>>();

protected int historyKeyCount = 0;
/// <summary>
/// Gets the total count of all keys in the telemetry data.
/// </summary>
public int KeysAllCount { get => historyKeyCount; }

/// <summary>
/// Gets the current count of keys in the telemetry data.
/// </summary>
protected int currentKeyCount = 0;
/// <summary>
/// Gets the count of empty commandlet contexts in the telemetry data.
/// </summary>
public int KeysCurrentCount { get => currentKeyCount; }

protected int nullCmdletContextCount = 0;
public int EmptyCmdletContextCount { get => nullCmdletContextCount; }

protected int keyNotFoundCount = 0;
/// <summary>
/// Gets the count of key not found occurrences in the telemetry data.
/// </summary>
public int KeyNotFoundCount { get => keyNotFoundCount; }

/// <summary>
/// Pushes a telemetry record to the telemetry data.
/// </summary>
/// <param name="cmdletContext">The commandlet context.</param>
/// <param name="record">The telemetry record.</param>
/// <returns><c>true</c> if the telemetry record was successfully pushed; otherwise, <c>false</c>.</returns>
public bool PushTelemetryRecord(ICmdletContext cmdletContext, T record)
{
if (cmdletContext != null && cmdletContext.IsValid && record != null)
Expand All @@ -38,6 +60,11 @@ public bool PushTelemetryRecord(ICmdletContext cmdletContext, T record)
return false;
}

/// <summary>
/// Pops a telemetry record from the telemetry data.
/// </summary>
/// <param name="cmdletContext">The commandlet context.</param>
/// <returns>The telemetry records associated with the commandlet context, or <c>null</c> if not found.</returns>
public IList<T> PopTelemetryRecord(ICmdletContext cmdletContext)
{
if (cmdletContext != null && cmdletContext.IsValid)
Expand Down
9 changes: 9 additions & 0 deletions src/Authentication.Abstractions/Interfaces/ICmdletContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@
// ----------------------------------------------------------------------------------
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Interfaces
{
/// <summary>
/// Represents the context of a cmdlet.
/// </summary>
public interface ICmdletContext
{
/// <summary>
/// Gets the ID of the cmdlet.
/// </summary>
string CmdletId { get; }

/// <summary>
/// Gets a value indicating whether the cmdlet context is valid.
/// </summary>
bool IsValid { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public class ActiveDirectoryClient
public GraphRbacManagementClient GraphClient { get; private set; }

/// <summary>
/// Creates new ActiveDirectoryClient using WindowsAzureSubscription.
/// Creates new ActiveDirectoryClient using Azure Subscription.
/// </summary>
/// <param name="context"></param>
/// <param name="context">The Azure context</param>
/// <param name="cmdletContext">The cmdlet context</param>
public ActiveDirectoryClient(IAzureContext context, ICmdletContext cmdletContext)
{
Expand All @@ -49,9 +49,9 @@ public ActiveDirectoryClient(IAzureContext context, ICmdletContext cmdletContext
}

/// <summary>
/// Creates new ActiveDirectoryClient using WindowsAzureSubscription.
/// Creates new ActiveDirectoryClient using Azure Subscription.
/// </summary>
/// <param name="context"></param>
/// <param name="context">The Azure context</param>
public ActiveDirectoryClient(IAzureContext context)
{
GraphClient = AzureSession.Instance.ClientFactory.CreateArmClient<GraphRbacManagementClient>(
Expand Down
16 changes: 14 additions & 2 deletions src/Graph.Rbac/Version1_6/ActiveDirectory/ActiveDirectoryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public class ActiveDirectoryClient
public GraphRbacManagementClient GraphClient { get; private set; }

/// <summary>
/// Creates new ActiveDirectoryClient using WindowsAzureSubscription.
/// Creates new ActiveDirectoryClient using Azure Subscription.
/// </summary>
/// <param name="context"></param>
/// <param name="context">The Azure context</param>
/// <param name="cmdletContext">The cmdlet context</param>
public ActiveDirectoryClient(IAzureContext context, ICmdletContext cmdletContext)
{
Expand All @@ -48,6 +48,18 @@ public ActiveDirectoryClient(IAzureContext context, ICmdletContext cmdletContext
GraphClient.TenantID = context.Tenant.Id.ToString();
}

/// <summary>
/// Creates new ActiveDirectoryClient using Azure Subscription.
/// </summary>
/// <param name="context">The Azure context</param>
public ActiveDirectoryClient(IAzureContext context)
{
GraphClient = AzureSession.Instance.ClientFactory.CreateArmClient<GraphRbacManagementClient>(
context, AzureEnvironment.Endpoint.Graph);

GraphClient.TenantID = context.Tenant.Id.ToString();
}

public PSADObject GetADObject(ADObjectFilterOptions options)
{
PSADObject result = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
using System.Linq;
using System.Management.Automation;
using System.Collections.Concurrent;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Interfaces;


/// <summary>
Expand Down

0 comments on commit 9415a08

Please sign in to comment.