Skip to content

Commit b84466b

Browse files
committed
Add CmdletInfoHandler
1 parent 3eb1938 commit b84466b

File tree

19 files changed

+85
-25
lines changed

19 files changed

+85
-25
lines changed

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ protected override void BeginProcessing()
218218
ProductInfoHeaderValue userAgentValue = new ProductInfoHeaderValue(
219219
ModuleName, string.Format("v{0}", ModuleVersion));
220220
AzureSession.ClientFactory.UserAgents.Add(userAgentValue);
221+
AzureSession.ClientFactory.AddHandler(new CmdletInfoHandler(this.CommandRuntime.ToString(), this.ParameterSetName));
221222

222223
base.BeginProcessing();
223224
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.Net.Http;
16+
using System.Threading;
17+
using System.Threading.Tasks;
18+
19+
namespace Microsoft.WindowsAzure.Commands.Common
20+
{
21+
/// <summary>
22+
/// A delegating handler that writes the current cmdlet info into request headers.
23+
/// </summary>
24+
public class CmdletInfoHandler : DelegatingHandler
25+
{
26+
private string _cmdlet;
27+
private string _parameterSet;
28+
29+
/// <summary>
30+
/// Initializes an instance of a CmdletInfoHandler with the name of the cmdlet and the parameter set.
31+
/// </summary>
32+
/// <param name="cmdlet">the name of the cmdlet</param>
33+
/// <param name="parameterSet">the name of the parameter set specified by user</param>
34+
public CmdletInfoHandler(string cmdlet, string parameterSet)
35+
{
36+
this._cmdlet = cmdlet;
37+
this._parameterSet = parameterSet;
38+
}
39+
40+
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
41+
{
42+
request.Headers.Add("CommandName", _cmdlet);
43+
request.Headers.Add("ParameterSetName", _parameterSet);
44+
return base.SendAsync(request, cancellationToken);
45+
}
46+
}
47+
}

src/Common/Commands.Common/Commands.Common.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
<HintPath>..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
6464
</Reference>
6565
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
67-
<Private>True</Private>
66+
<SpecificVersion>False</SpecificVersion>
67+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.3.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6868
</Reference>
6969
<Reference Include="Microsoft.Azure.Common.NetFramework">
7070
<SpecificVersion>False</SpecificVersion>
@@ -154,6 +154,7 @@
154154
</Compile>
155155
<Compile Include="PublishSettingsImporter.cs" />
156156
<Compile Include="MetricHelper.cs" />
157+
<Compile Include="CmdletInfoHandler.cs" />
157158
<Compile Include="SecureStringExtensions.cs" />
158159
<Compile Include="ConversionUtilities.cs" />
159160
<Compile Include="DebugStreamTraceListener.cs" />

src/Common/Commands.Common/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Microsoft.ApplicationInsights" version="1.1.1-beta" targetFramework="net45" />
55
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Common.Authentication" version="1.3.1-preview" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Common.Authentication" version="1.3.2-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
1010
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

src/ResourceManager/Common/Commands.ResourceManager.Common/Commands.ResourceManager.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
6262
</Reference>
6363
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
64-
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
65-
<Private>True</Private>
64+
<SpecificVersion>False</SpecificVersion>
65+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6666
</Reference>
6767
<Reference Include="Microsoft.Azure.Common.NetFramework">
6868
<SpecificVersion>False</SpecificVersion>

src/ResourceManager/Common/Commands.ResourceManager.Common/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Microsoft.ApplicationInsights" version="1.1.1-beta" targetFramework="net45" />
55
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Common.Authentication" version="1.3.1-preview" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Common.Authentication" version="1.3.2-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
99
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
1010
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Commands.ScenarioTests.ResourceManager.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
4747
</Reference>
4848
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
49-
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
50-
<Private>True</Private>
49+
<SpecificVersion>False</SpecificVersion>
50+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
5151
</Reference>
5252
<Reference Include="Microsoft.Azure.Common.NetFramework">
5353
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Mocks/MockClientFactory.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ public void RemoveAction(Type actionType)
165165
// Do nothing
166166
}
167167

168+
public void AddHandler(DelegatingHandler handler)
169+
{
170+
// Do nothing
171+
}
172+
173+
public void RemoveHandler(Type handlerType)
174+
{
175+
// Do nothing
176+
}
177+
168178
public void AddUserAgent(string productName, string productVersion)
169179
{
170180
throw new NotImplementedException();

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Common.Authentication" version="1.3.1-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.3.2-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Test.Framework" version="1.0.5715.36130-prerelease" targetFramework="net45" />

src/ResourceManager/Profile/Commands.Profile/Commands.Profile.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5555
</Reference>
5656
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57-
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
58-
<Private>True</Private>
57+
<SpecificVersion>False</SpecificVersion>
58+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
5959
</Reference>
6060
<Reference Include="Microsoft.Azure.Common.NetFramework">
6161
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>

src/ResourceManager/Profile/Commands.Profile/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Common.Authentication" version="1.3.1-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.3.2-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
88
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
<SpecificVersion>False</SpecificVersion>
5555
<HintPath>..\..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5656
</Reference>
57-
<Reference Include="Microsoft.Azure.Common.Authentication">
58-
<HintPath>..\..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
59-
<Private>True</Private>
57+
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
58+
<SpecificVersion>False</SpecificVersion>
59+
<HintPath>..\..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6060
</Reference>
6161
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.18.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6262
<HintPath>..\..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.18.206251556\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Common.Authentication" version="1.3.1-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.3.2-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
88
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5252
</Reference>
5353
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
54-
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
55-
<Private>True</Private>
54+
<SpecificVersion>False</SpecificVersion>
55+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
5656
</Reference>
5757
<Reference Include="Microsoft.Azure.Common.NetFramework">
5858
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
@@ -244,6 +244,7 @@
244244
</ProjectReference>
245245
</ItemGroup>
246246
<ItemGroup>
247+
<None Include="app.config" />
247248
<None Include="Build2014_Website_App.json">
248249
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
249250
</None>

src/ResourceManager/Resources/Commands.Resources.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Common.Authentication" version="1.3.1-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.3.2-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.0-preview" targetFramework="net45" />

src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5656
</Reference>
5757
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
58-
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
59-
<Private>True</Private>
58+
<SpecificVersion>False</SpecificVersion>
59+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6060
</Reference>
6161
<Reference Include="Microsoft.Azure.Common.NetFramework">
6262
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>

src/ResourceManager/Resources/Commands.Resources/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Common.Authentication" version="1.3.1-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.3.2-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Graph.RBAC" version="1.7.1-preview" targetFramework="net45" />

src/ResourceManager/Tags/Commands.Tags/Commands.Tags.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5656
</Reference>
5757
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
58-
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
59-
<Private>True</Private>
58+
<SpecificVersion>False</SpecificVersion>
59+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.3.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6060
</Reference>
6161
<Reference Include="Microsoft.Azure.Common.NetFramework">
6262
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>

src/ResourceManager/Tags/Commands.Tags/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Common.Authentication" version="1.3.1-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.3.2-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.18.7-preview" targetFramework="net45" />
88
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

0 commit comments

Comments
 (0)