Skip to content

Commit 3d48fc4

Browse files
committed
refine codes
1 parent a03fea2 commit 3d48fc4

15 files changed

+102
-64
lines changed

src/Authentication.Abstractions/Authentication.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
<ItemGroup>
5656
<None Include="..\..\LICENSE.txt" Link="LICENSE.txt" Pack="true" PackagePath="" />
57+
<Folder Include="Models\" />
5758
</ItemGroup>
5859

5960
</Project>

src/Authentication.Abstractions/Interfaces/IConfigManagerWithEvents.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models;
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// -------------------------------------
14+
15+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models;
216
using Microsoft.Azure.PowerShell.Common.Config;
317

418
using System;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// -------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
18+
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models
19+
{
20+
public class ConfigEventArgs : EventArgs, IExtensibleModel
21+
{
22+
public string ConfigKey { get; }
23+
24+
public string ConfigValue { get; }
25+
26+
public IDictionary<string, string> ExtendedProperties { get; } = new Dictionary<string, string>();
27+
28+
public ConfigEventArgs(string configKey, string configValue)
29+
{
30+
ConfigKey = configKey;
31+
ConfigValue = configValue;
32+
}
33+
}
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// -------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Common.Authentication.Abstractions.Models
16+
{
17+
public class ConfigReadEventArgs : ConfigEventArgs
18+
{
19+
public string ConfigTelemetryKey { get; }
20+
21+
public ConfigReadEventArgs(string configKey, string configValue) : this(configKey, configKey, configValue)
22+
{
23+
}
24+
25+
public ConfigReadEventArgs(string configKey, string configTelemetryKey, string configValue) : base(configKey, configValue)
26+
{
27+
ConfigTelemetryKey = configTelemetryKey;
28+
}
29+
}
30+
}

src/Authentication.Abstractions/Models/ConfigEventArgs .cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Authentication.Abstractions/Models/ConfigReadEventArgs.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Common/AzurePSCmdlet.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -524,25 +524,6 @@ protected void WriteSurvey()
524524
}
525525
}
526526

527-
528-
private void AddTelemetryForConfig()
529-
{
530-
// attach config read event handler to add config telemetry
531-
AzureSession.Instance.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var configManager);
532-
if (configManager is IConfigManagerWithEvents cm)
533-
{
534-
cm.ConfigRead += OnConfigReaded;
535-
}
536-
}
537-
538-
private void OnConfigReaded(object sender, ConfigEventArgs args)
539-
{
540-
if (!_qosEvent.ConfigMetrics.ContainsKey(args.ConfigKey) && args is ConfigReadEventArgs readEventArgs)
541-
{
542-
_qosEvent.ConfigMetrics[readEventArgs.ConfigKey] = new ConfigMetrics(readEventArgs.ConfigTelemetryKey, readEventArgs.ConfigValue.ToString());
543-
}
544-
}
545-
546527
protected new void ThrowTerminatingError(ErrorRecord errorRecord)
547528
{
548529
FlushDebugMessages();
@@ -567,8 +548,7 @@ private void OnConfigReaded(object sender, ConfigEventArgs args)
567548
base.WriteObject(sendToPipeline, enumerateCollection);
568549
}
569550

570-
571-
private void SanitizeOutput(object sendToPipeline)
551+
private void SanitizeOutput(object sendToPipeline)
572552
{
573553
if (OutputSanitizer?.RequireSecretsDetection == true)
574554
{
@@ -795,7 +775,27 @@ protected virtual void InitializeQosEvent()
795775

796776
_qosEvent.SanitizerInfo = new SanitizerTelemetry(OutputSanitizer?.RequireSecretsDetection == true);
797777

798-
AddTelemetryForConfig();
778+
AttachConfigReadHandlerForTelemetry();
779+
}
780+
781+
/// <summary>
782+
/// Attach config read event handler to add config telemetry
783+
/// </summary>
784+
private void AttachConfigReadHandlerForTelemetry()
785+
{
786+
AzureSession.Instance.TryGetComponent<IConfigManager>(nameof(IConfigManager), out var configManager);
787+
if (configManager is IConfigManagerWithEvents cm)
788+
{
789+
cm.ConfigRead += OnConfigRead;
790+
}
791+
}
792+
793+
private void OnConfigRead(object sender, ConfigEventArgs args)
794+
{
795+
if (!_qosEvent.ConfigMetrics.ContainsKey(args.ConfigKey) && args is ConfigReadEventArgs readEventArgs)
796+
{
797+
_qosEvent.ConfigMetrics[readEventArgs.ConfigKey] = new ConfigMetrics(readEventArgs.ConfigTelemetryKey, readEventArgs.ConfigValue.ToString());
798+
}
799799
}
800800

801801
private void RecordDebugMessages()

0 commit comments

Comments
 (0)