Skip to content

Commit a018b7d

Browse files
committed
Merge branch 'dev' of https://github.com/huangpf/azure-powershell into dev
2 parents 7cc421d + 3d542f7 commit a018b7d

File tree

10 files changed

+251
-129
lines changed

10 files changed

+251
-129
lines changed

setup/azurecmd.wxs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
<RegistrySearch Id="PSCOMPATIBLEVERSION" Root="HKLM" Key="SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine" Name="PSCompatibleVersion" Type="raw" />
3232
</Property>
3333

34-
<SetProperty Action="SetBase64" Id="BaseModulesFolder" Value="[ProgramFiles64Folder]WindowsPowerShell\Modules" Before="AppSearch">
34+
<SetProperty Action="SetBase64" Id="BaseModulesFolder" Value="[ProgramFiles64Folder]WindowsPowerShell\Modules\" Before="AppSearch">
3535
VersionNT64
3636
</SetProperty>
3737

38-
<SetProperty Action="SetBase32" Id="BaseModulesFolder" Value="[ProgramFilesFolder]WindowsPowerShell\Modules" Before="AppSearch">
38+
<SetProperty Action="SetBase32" Id="BaseModulesFolder" Value="[ProgramFilesFolder]WindowsPowerShell\Modules\" Before="AppSearch">
3939
NOT VersionNT64
4040
</SetProperty>
4141

@@ -81,7 +81,7 @@
8181
<Component Id="PSModulePath.System" Guid="273525B9-7AAB-421A-90C8-8E50A1840B8D">
8282
<CreateFolder />
8383
<!-- Work around bug that PowerShell does not always consider default module paths. -->
84-
<Environment Id="PSModulePath.SystemAppRoot" Action="set" Name="PSMODULEPATH" Part="last" Value="[BaseModulesFolder];[PowerShellFolder]ResourceManager\AzureResourceManager;[PowerShellFolder]ServiceManagement" System="yes" />
84+
<Environment Id="PSModulePath.SystemAppRoot" Action="set" Name="PSMODULEPATH" Part="last" Value="[BaseModulesFolder];[PowerShellFolder]ResourceManager\AzureResourceManager\;[PowerShellFolder]ServiceManagement\" System="yes" />
8585
</Component>
8686
</DirectoryRef>
8787

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using System.Text;
2828
using System.Linq;
2929
using System.Threading;
30+
using Microsoft.Rest;
3031

3132
namespace Microsoft.WindowsAzure.Commands.Utilities.Common
3233
{
@@ -40,6 +41,9 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
4041
private RecordingTracingInterceptor _httpTracingInterceptor;
4142

4243
private DebugStreamTraceListener _adalListener;
44+
45+
private ServiceClientTracingInterceptor _serviceClientTracingInterceptor;
46+
4347
protected static AzurePSDataCollectionProfile _dataCollectionProfile = null;
4448
protected static string _errorRecordFolderPath = null;
4549
protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff";
@@ -95,12 +99,12 @@ protected static void InitializeDataCollectionProfile()
9599
{
96100
if (string.Equals(value, bool.FalseString, StringComparison.OrdinalIgnoreCase))
97101
{
98-
// Disable data collection only if it is explictly set to 'false'.
102+
// Disable data collection only if it is explicitly set to 'false'.
99103
_dataCollectionProfile = new AzurePSDataCollectionProfile(true);
100104
}
101105
else if (string.Equals(value, bool.TrueString, StringComparison.OrdinalIgnoreCase))
102106
{
103-
// Enable data collection only if it is explictly set to 'true'.
107+
// Enable data collection only if it is explicitly set to 'true'.
104108
_dataCollectionProfile = new AzurePSDataCollectionProfile(false);
105109
}
106110
}
@@ -216,8 +220,10 @@ protected override void BeginProcessing()
216220

217221
_httpTracingInterceptor = _httpTracingInterceptor ?? new RecordingTracingInterceptor(_debugMessages);
218222
_adalListener = _adalListener ?? new DebugStreamTraceListener(_debugMessages);
223+
_serviceClientTracingInterceptor = _serviceClientTracingInterceptor ?? new ServiceClientTracingInterceptor(_debugMessages);
219224
RecordingTracingInterceptor.AddToContext(_httpTracingInterceptor);
220225
DebugStreamTraceListener.AddAdalTracing(_adalListener);
226+
ServiceClientTracing.AddTracingInterceptor(_serviceClientTracingInterceptor);
221227

222228
ProductInfoHeaderValue userAgentValue = new ProductInfoHeaderValue(
223229
ModuleName, string.Format("v{0}", ModuleVersion));
@@ -237,6 +243,7 @@ protected override void EndProcessing()
237243

238244
RecordingTracingInterceptor.RemoveFromContext(_httpTracingInterceptor);
239245
DebugStreamTraceListener.RemoveAdalTracing(_adalListener);
246+
ServiceClientTracingInterceptor.RemoveTracingInterceptor(_serviceClientTracingInterceptor);
240247
FlushDebugMessages();
241248

242249
AzureSession.ClientFactory.UserAgents.RemoveWhere(u => u.Product.Name == ModuleName);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<Compile Include="ProfileClientExtensions.cs" />
171171
<Compile Include="ClientCreatedArgs.cs" />
172172
<Compile Include="CmdletExtensions.cs" />
173+
<Compile Include="ServiceClientTracingInterceptor.cs" />
173174
<Compile Include="TestMockSupport.cs" />
174175
<Compile Include="PSAzureAccount.cs" />
175176
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.Rest;
16+
using System;
17+
using System.Collections.Concurrent;
18+
using System.Collections.Generic;
19+
using System.Diagnostics;
20+
using System.Linq;
21+
using System.Text;
22+
using System.Threading.Tasks;
23+
24+
namespace Microsoft.WindowsAzure.Commands.Common
25+
{
26+
class ServiceClientTracingInterceptor : IServiceClientTracingInterceptor
27+
{
28+
public ServiceClientTracingInterceptor(ConcurrentQueue<string> queue)
29+
{
30+
MessageQueue = queue;
31+
}
32+
33+
public ConcurrentQueue<string> MessageQueue { get; private set; }
34+
35+
public void Configuration(string source, string name, string value)
36+
{
37+
// Ignore
38+
}
39+
40+
public void EnterMethod(string invocationId, object instance, string method, IDictionary<string, object> parameters)
41+
{
42+
// Ignore
43+
}
44+
45+
public void ExitMethod(string invocationId, object returnValue)
46+
{
47+
// Ignore
48+
}
49+
50+
public void Information(string message)
51+
{
52+
MessageQueue.Enqueue(message);
53+
}
54+
55+
public void ReceiveResponse(string invocationId, System.Net.Http.HttpResponseMessage response)
56+
{
57+
string responseAsString = response == null ? string.Empty : response.AsFormattedString();
58+
MessageQueue.Enqueue(responseAsString);
59+
}
60+
61+
public void SendRequest(string invocationId, System.Net.Http.HttpRequestMessage request)
62+
{
63+
string requestAsString = request == null ? string.Empty : request.AsFormattedString();
64+
MessageQueue.Enqueue(requestAsString);
65+
}
66+
67+
public void TraceError(string invocationId, Exception exception)
68+
{
69+
// Ignore
70+
}
71+
72+
public static void RemoveTracingInterceptor(ServiceClientTracingInterceptor interceptor)
73+
{
74+
if (interceptor != null)
75+
{
76+
ServiceClientTracing.RemoveTracingInterceptor(interceptor);
77+
}
78+
}
79+
}
80+
}

src/ResourceManager/Profile/Commands.Profile.Test/AzureRMProfileTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,40 @@ public void TokenIdAndAccountIdMismatch()
116116
Assert.Equal(1, tenantsInAccount.Length);
117117
Assert.Equal(tenants.First(), tenantsInAccount[0]);
118118
}
119+
120+
[Fact]
121+
[Trait(Category.AcceptanceType, Category.CheckIn)]
122+
public void AdalExceptionsArePropagatedToCaller()
123+
{
124+
var tenants = new List<string> { Guid.NewGuid().ToString(), DefaultTenant.ToString() };
125+
var secondsubscriptionInTheFirstTenant = Guid.NewGuid().ToString();
126+
var firstList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
127+
var secondList = new List<string> { Guid.NewGuid().ToString() };
128+
var thirdList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
129+
var fourthList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
130+
var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList, fourthList);
131+
132+
var tokens = new Queue<MockAccessToken>();
133+
tokens.Enqueue(new MockAccessToken
134+
{
135+
UserId = "[email protected]",
136+
LoginType = LoginType.OrgId,
137+
AccessToken = "bbb"
138+
});
139+
140+
((MockTokenAuthenticationFactory)AzureSession.AuthenticationFactory).TokenProvider = (account, environment, tenant) =>
141+
{
142+
throw new AadAuthenticationCanceledException("Login window was closed", null);
143+
};
144+
145+
Assert.Throws<AadAuthenticationCanceledException>( () => client.Login(
146+
Context.Account,
147+
Context.Environment,
148+
null,
149+
secondsubscriptionInTheFirstTenant,
150+
null,
151+
null));
152+
}
119153

120154
[Fact]
121155
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ResourceManager/Profile/Commands.Profile/Models/RMProfileClient.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ public IEnumerable<AzureSubscription> ListSubscriptions()
386386
}
387387
catch (AadAuthenticationException)
388388
{
389-
WriteWarningMessage(string.Format("Could not authenticate user account {0} with tenant {1}. " +
390-
"Subscriptions in this tenant will not be listed. Please login again using Login-AzureRmAccount " +
391-
"to view the subscriptions in this tenant.", _profile.Context.Account, tenant));
389+
WriteWarningMessage(string.Format(
390+
Microsoft.Azure.Commands.Profile.Properties.Resources.UnableToLogin,
391+
_profile.Context.Account,
392+
tenant));
392393
}
393394

394395
}
@@ -576,11 +577,12 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
576577
{
577578
result =
578579
account.GetPropertyAsArray(AzureAccount.Property.Tenants)
579-
.Select( ti => {
580+
.Select(ti =>
581+
{
580582
var tenant = new AzureTenant();
581-
583+
582584
Guid guid;
583-
if(Guid.TryParse(ti, out guid))
585+
if (Guid.TryParse(ti, out guid))
584586
{
585587
tenant.Id = guid;
586588
tenant.Domain = AccessTokenExtensions.GetDomain(account.Id);
@@ -593,8 +595,12 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
593595
return tenant;
594596
}).ToList();
595597
}
596-
597-
}
598+
if(!result.Any())
599+
{
600+
throw;
601+
}
602+
603+
}
598604

599605
return result;
600606
}
@@ -640,7 +646,7 @@ private void WriteWarningMessage(string message)
640646
WarningLog(message);
641647
}
642648
}
643-
649+
644650
private static AzureTenant CreateTenantFromString(string tenantOrDomain, string accessTokenTenantId)
645651
{
646652
AzureTenant result = new AzureTenant();

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@
168168
<data name="UnableToAqcuireToken" xml:space="preserve">
169169
<value>Unable to acquire token for tenant '{0}'</value>
170170
</data>
171+
<data name="UnableToLogin" xml:space="preserve">
172+
<value>Could not authenticate user account '{0}' with tenant '{1}'. Subscriptions in this tenant will not be listed. Please login again using Login-AzureRmAccount to view the subscriptions in this tenant.</value>
173+
</data>
171174
<data name="UnknownEnvironment" xml:space="preserve">
172175
<value>Unable to find environment with name '{0}'</value>
173176
</data>
174-
</root>
177+
</root>

0 commit comments

Comments
 (0)