Skip to content

Commit 6a467a9

Browse files
author
Hovsep Mkrtchyan
committed
Merge branch 'AuthenticationResources' of github.com:hovsepm/azure-powershell into dev
# Conflicts: # src/ResourceManager/Profile/Commands.Profile.Test/Commands.Profile.Test.csproj # src/ResourceManager/Profile/Commands.Profile.Test/packages.config # src/ResourceManager/Profile/Commands.Profile/Commands.Profile.csproj # src/ResourceManager/Profile/Commands.Profile/packages.config
2 parents 6ffd053 + 37ba219 commit 6a467a9

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/PermissiveRecordMatcherWithApiExclusion.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Linq;
1617
using System.Collections.Generic;
1718
using System.Text;
1819
using System.Text.RegularExpressions;
@@ -26,13 +27,24 @@ public class PermissiveRecordMatcherWithApiExclusion : IRecordMatcher
2627
{
2728
private bool _ignoreGenericResource;
2829
private Dictionary<string, string> _providersToIgnore;
30+
private Dictionary<string, string> _userAgentsToIgnore;
2931

3032
public PermissiveRecordMatcherWithApiExclusion(bool ignoreResourcesClient, Dictionary<string, string> providers)
3133
{
3234
_ignoreGenericResource = ignoreResourcesClient;
3335
_providersToIgnore = providers;
3436
}
3537

38+
public PermissiveRecordMatcherWithApiExclusion(
39+
bool ignoreResourcesClient,
40+
Dictionary<string, string> providers,
41+
Dictionary<string, string> userAgents)
42+
{
43+
_ignoreGenericResource = ignoreResourcesClient;
44+
_providersToIgnore = providers;
45+
_userAgentsToIgnore = userAgents;
46+
}
47+
3648
public string GetMatchingKey(System.Net.Http.HttpRequestMessage request)
3749
{
3850
var path = request.RequestUri.PathAndQuery;
@@ -46,6 +58,21 @@ public string GetMatchingKey(System.Net.Http.HttpRequestMessage request)
4658
{
4759
path = RemoveOrReplaceApiVersion(path, version);
4860
}
61+
else if (_userAgentsToIgnore != null && _userAgentsToIgnore.Any())
62+
{
63+
var agent = request.Headers.FirstOrDefault(h => h.Key.Equals("User-Agent"));
64+
if (agent.Key != null)
65+
{
66+
foreach (var userAgnet in _userAgentsToIgnore)
67+
{
68+
if (agent.Value.Any(v => v.StartsWith(userAgnet.Key, StringComparison.OrdinalIgnoreCase)))
69+
{
70+
path = RemoveOrReplaceApiVersion(path, userAgnet.Value);
71+
break;
72+
}
73+
}
74+
}
75+
}
4976

5077
var encodedPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(path));
5178
return string.Format("{0} {1}", request.Method, encodedPath);
@@ -108,7 +135,7 @@ private string RemoveOrReplaceApiVersion(string requestUri, string version)
108135
}
109136
else
110137
{
111-
var result= Regex.Replace(requestUri, @"&api-version=[^&]+", string.Empty);
138+
var result = Regex.Replace(requestUri, @"&api-version=[^&]+", string.Empty);
112139
return Regex.Replace(result, @"\?api-version=[^&]+[&]*", "?");
113140
}
114141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
</Reference>
7070
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7171
<SpecificVersion>False</SpecificVersion>
72-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.11-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
72+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.13-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
7373
</Reference>
7474
<Reference Include="Microsoft.Azure.Test.Framework">
7575
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5799.28345-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<package id="Microsoft.Azure.Common.Authentication" version="1.6.1-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
77
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
8-
<package id="Microsoft.Azure.Management.Resources" version="2.18.11-preview" targetFramework="net45" />
8+
<package id="Microsoft.Azure.Management.Resources" version="2.18.13-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.Test.Framework" version="1.0.5799.28345-prerelease" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5799.28345-prerelease" targetFramework="net45" />
1111
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</Reference>
6363
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6464
<SpecificVersion>False</SpecificVersion>
65-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.11-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
65+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.18.13-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
6666
</Reference>
6767
<Reference Include="Microsoft.Build" />
6868
<Reference Include="Microsoft.Build.Framework" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Microsoft.Azure.Common" version="2.1.0" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common.Authentication" version="1.6.1-preview" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Management.Resources" version="2.18.11-preview" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Management.Resources" version="2.18.13-preview" targetFramework="net45" />
88
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
99
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
1010
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />

0 commit comments

Comments
 (0)