Skip to content

Commit aee7b6b

Browse files
authored
Interface for collection parameter values (#376)
* interface for collecting parameters * API: Format parameters for telemetry
1 parent aaf9ff8 commit aee7b6b

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/Common/AzurePSCmdlet.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.Azure.ServiceManagement.Common.Models;
2020
using Microsoft.WindowsAzure.Commands.Common;
2121
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
22+
using Microsoft.WindowsAzure.Commands.Common.Utilities;
2223
using System;
2324
using System.Collections.Concurrent;
2425
using System.Collections.Generic;
@@ -702,9 +703,16 @@ protected virtual void InitializeQosEvent()
702703
if (this.MyInvocation != null && this.MyInvocation.BoundParameters != null
703704
&& this.MyInvocation.BoundParameters.Keys != null)
704705
{
705-
_qosEvent.Parameters = string.Join(" ",
706-
this.MyInvocation.BoundParameters.Keys.Select(
707-
s => string.Format(CultureInfo.InvariantCulture, "-{0} ***", s)));
706+
if (AzureSession.Instance.TryGetComponent<IParameterTelemetryFormatter>(nameof(IParameterTelemetryFormatter), out var formatter))
707+
{
708+
_qosEvent.Parameters = formatter.FormatParameters(MyInvocation);
709+
}
710+
else
711+
{
712+
_qosEvent.Parameters = string.Join(" ",
713+
this.MyInvocation.BoundParameters.Keys.Select(
714+
s => string.Format(CultureInfo.InvariantCulture, "-{0} ***", s)));
715+
}
708716
}
709717
}
710718

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.Collections.Generic;
16+
using System.Management.Automation;
17+
18+
namespace Microsoft.WindowsAzure.Commands.Common.Utilities
19+
{
20+
/// <summary>
21+
/// String formatter for bound parameters for telemetry purpose.
22+
/// </summary>
23+
public interface IParameterTelemetryFormatter
24+
{
25+
/// <summary>
26+
/// Format the bound parameters to a string without sensitive data.
27+
/// </summary>
28+
/// <param name="invocation">Info about cmdlet invocation</param>
29+
/// <returns>The formatted string.</returns>
30+
string FormatParameters(InvocationInfo invocation);
31+
}
32+
}

0 commit comments

Comments
 (0)