Skip to content

Commit 2b8928d

Browse files
committed
Merge pull request Azure#1520 from markcowl/addLogging
Fixing resource string for log in and add logging and environment cha…
2 parents d027a29 + 1b4c5e4 commit 2b8928d

File tree

23 files changed

+82
-43
lines changed

23 files changed

+82
-43
lines changed

src/CLU/Commands.Common.Authentication/Authentication/AdalTokenProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Commands.Common.Authentication.Properties;
1615
using Microsoft.Azure.Commands.Common.Authentication.Models;
1716
using System;
17+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
1818

1919
namespace Microsoft.Azure.Commands.Common.Authentication
2020
{

src/CLU/Commands.Common.Authentication/Authentication/ServicePrincipalTokenProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Commands.Common.Authentication.Properties;
1615
using Microsoft.Azure.Commands.Common.Authentication.Models;
1716
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1817
using Microsoft.Rest;
1918
using System;
19+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
2020

2121
namespace Microsoft.Azure.Commands.Common.Authentication
2222
{

src/CLU/Commands.Common.Authentication/Authentication/UserTokenProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using System.Runtime.InteropServices;
2020
using Microsoft.Rest.Azure.Authentication;
2121
using System.Management.Automation;
22-
using Commands.Common.Authentication.Properties;
22+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
2323

2424
namespace Microsoft.Azure.Commands.Common.Authentication
2525
{

src/CLU/Commands.Common.Authentication/AuthenticationFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2020
using Microsoft.Rest;
2121
using Microsoft.Rest.Azure.Authentication;
22-
using Commands.Common.Authentication.Properties;
22+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
2323

2424
namespace Microsoft.Azure.Commands.Common.Authentication.Factories
2525
{

src/CLU/Commands.Common.Authentication/ClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Commands.Common.Authentication.Properties;
1615
using Microsoft.Azure.Commands.Common.Authentication.Models;
1716
using Microsoft.Rest;
1817
using System;
@@ -23,6 +22,7 @@
2322
using System.Net.Http;
2423
using System.Net.Http.Headers;
2524
using System.Reflection;
25+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
2626

2727
namespace Microsoft.Azure.Commands.Common.Authentication.Factories
2828
{

src/CLU/Commands.Common.Authentication/JsonUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Commands.Common.Authentication.Properties;
1615
using Newtonsoft.Json;
1716
using Newtonsoft.Json.Linq;
1817
using System;
1918
using System.Collections.Generic;
2019
using System.Diagnostics.CodeAnalysis;
20+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
2121

2222
namespace Microsoft.Azure.Commands.Common.Authentication
2323
{

src/CLU/Commands.Common.Authentication/Models/AzureEnvironment.Methods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Commands.Common.Authentication.Properties;
1615
using System;
1716
using System.Collections.Generic;
17+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
1818

1919
namespace Microsoft.Azure.Commands.Common.Authentication.Models
2020
{

src/CLU/Commands.Common.Authentication/Models/AzureSMProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Commands.Common.Authentication.Properties;
1615
using Microsoft.Rest;
1716
using Newtonsoft.Json;
1817
using System;
1918
using System.Collections.Generic;
2019
using System.Linq;
20+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
2121

2222
namespace Microsoft.Azure.Commands.Common.Authentication.Models
2323
{

src/CLU/Commands.Common.Authentication/Models/DiskDataStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Commands.Common.Authentication.Properties;
1615
using System;
1716
using System.IO;
1817
using System.Security.Cryptography.X509Certificates;
1918
using System.Text;
19+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
2020

2121
namespace Microsoft.Azure.Commands.Common.Authentication.Models
2222
{

src/CLU/Commands.Common.Authentication/Properties/Resources.Designer.cs

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

src/CLU/Commands.Common.Authentication/Properties/Resources.resx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
<value>The environment name '{0}' is not found.</value>
140140
</data>
141141
<data name="ExpiredRefreshToken" xml:space="preserve">
142-
<value>Your Microsoft Azure credential in the Windows PowerShell session has expired. Please log in again. In PowerShell, execute Login-AzureRMAccount for Azure Resource Manager cmdlets or Add-AzureAccount for service management cmdlets.</value>
142+
<value>Your Microsoft Azure credential has expired. Please log in again.</value>
143143
</data>
144144
<data name="FilePathIsNotValid" xml:space="preserve">
145145
<value>File path is not valid</value>
@@ -190,7 +190,7 @@
190190
<value>Removing public environment is not supported.</value>
191191
</data>
192192
<data name="ServiceKeyNotFound" xml:space="preserve">
193-
<value>Unable to retrieve service key for ServicePrincipal account {0}. Please log in again to supply the credentials for this service principal. In PowerShell, execute Login-AzureRMAccount for Azure Resource Manager cmdlets or Add-AzureAccount for service management cmdlets.</value>
193+
<value>Unable to retrieve service key for ServicePrincipal account {0}. Please add your account again to supply the credentials for this service principal.</value>
194194
</data>
195195
<data name="ServiceNameExists" xml:space="preserve">
196196
<value>The provided service name {0} already exists, please pick another name</value>
@@ -256,7 +256,7 @@
256256
<value>Multiple tokens were found for this user. Please clear your token cache using, Clear-AzureProfile and try this command again.</value>
257257
</data>
258258
<data name="AdalUserInteractionRequired" xml:space="preserve">
259-
<value>User Interaction is required to authenticate this user. Please authenticate using the log in dialog. In PowerShell, execute Login-AzureRMAccount for Azure Resource Manager cmdlets or Add-AzureAccount for service management cmdlets.</value>
259+
<value>User Interaction is required to authenticate this user. Please authenticate using device authentication, by adding an account without providing credentials on the command line.</value>
260260
</data>
261261
<data name="TenantNotFound" xml:space="preserve">
262262
<value>No tenant was found for this subscription. Please execute Clear-AzureProfile and then execute Add-AzureAccount.</value>
@@ -280,19 +280,19 @@
280280
<value>[Common.Authentication]: Authenticating for account {0} with single tenant {1}</value>
281281
</data>
282282
<data name="ArmAccountNotFound" xml:space="preserve">
283-
<value>No account found in the context. Please login using Login-AzureRMAccount.</value>
283+
<value>No account found in the context. Please add your account again.</value>
284284
</data>
285285
<data name="ArmUserInteractionRequired" xml:space="preserve">
286-
<value>User Interaction is required to authenticate this user. Please execute Login-AzureRMAccount without parameters and enter your credentials.</value>
286+
<value>User Interaction is required to authenticate this user. Please login using device authentication by adding your account without providing credentials on the command line.</value>
287287
</data>
288288
<data name="InvalidArmContext" xml:space="preserve">
289-
<value>Your Azure credentials have not been set up or have expired, please run Login-AzureRMAccount to set up your Azure credentials.</value>
289+
<value>Your Azure credentials have not been set up or have expired, please add an account to set up your Azure credentials.</value>
290290
</data>
291291
<data name="NoSubscriptionInContext" xml:space="preserve">
292-
<value>No subscription found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Login-AzureRMAccount to login.</value>
292+
<value>No subscription found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then radd your account again.</value>
293293
</data>
294294
<data name="NoTenantInContext" xml:space="preserve">
295-
<value>No tenant found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Login-AzureRMAccount to login.</value>
295+
<value>No tenant found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then add your account again.</value>
296296
</data>
297297
<data name="UnsupportedCredentialType" xml:space="preserve">
298298
<value>Certificate authentication is not supported for account type {0}.</value>

src/CLU/Commands.Common.Authentication/Validate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Commands.Common.Authentication.Properties;
1615
using System;
1716
using System.IO;
1817
using System.Linq;
18+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
1919

2020
namespace Microsoft.Azure.Commands.Common.Authentication
2121
{

src/CLU/Commands.Common.ScenarioTest/ExampleScriptRunner.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public ExampleScriptRunner(Random generator, string sessionId)
5454
{
5555
_generator = generator;
5656
_sessionId = sessionId;
57+
EnvironmentVariables = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
5758
}
5859

5960
public IClientFactory ClientFactory
@@ -68,6 +69,8 @@ public TestContext TestContext
6869
set { _context = value; }
6970
}
7071

72+
public IDictionary<string, string> EnvironmentVariables { get; private set; }
73+
7174
public string ScriptOutput { get; protected set; }
7275

7376
public string RunScript(string testName)
@@ -105,6 +108,12 @@ public string RunScript(string testName)
105108
{
106109
helper.TrySetupScriptEnvironment(_context, _clientFactory, process.EnvironmentVariables);
107110
}
111+
112+
foreach (var environmentVar in EnvironmentVariables.Keys)
113+
{
114+
process.EnvironmentVariables.Add(environmentVar, EnvironmentVariables[environmentVar]);
115+
}
116+
108117
int statusCode = process.StartAndWaitForExit();
109118
Assert.Equal(0, statusCode);
110119
return process.Output;
@@ -136,7 +145,12 @@ public void DeployTemplate(string deploymentTemplatePath, string resourceGroupNa
136145

137146
public string CreateRandomName()
138147
{
139-
return "clutst" + _generator.Next(10000, 99999);
148+
return GenerateName("clutst");
149+
}
150+
151+
public string GenerateName(string prefix)
152+
{
153+
return $"{prefix}{_generator.Next(10000, 99999)}";
140154
}
141155

142156
private void EnsureClient()

src/CLU/Commands.Common.ScenarioTest/Logger.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
1516
using System.Diagnostics;
17+
using Microsoft.Extensions.Logging;
1618

1719
namespace Microsoft.Azure.Commands.Common.ScenarioTest
1820
{
@@ -26,17 +28,39 @@ static Logger()
2628

2729
private Logger()
2830
{
31+
var factory = new LoggerFactory();
32+
_consoleLogger = factory.CreateLogger<Logger>();
33+
factory.AddConsole();
2934
}
3035

36+
private ILogger _consoleLogger;
3137

3238
public void WriteMessage(string message)
3339
{
3440
Trace.WriteLine(message);
41+
LogMessageInChunks(message);
42+
}
43+
44+
/// <summary>
45+
/// The dnx logger fails with large messages
46+
/// </summary>
47+
/// <param name="message"></param>
48+
/// <returns></returns>
49+
private void LogMessageInChunks(string message, int chunkSize = 5000)
50+
{
51+
if (!string.IsNullOrWhiteSpace(message))
52+
{
53+
for (int i = 0; i < message.Length; i += Math.Min(chunkSize, message.Length - i))
54+
{
55+
_consoleLogger.LogInformation(message.Substring(i, Math.Min(chunkSize, message.Length - i)));
56+
}
57+
}
3558
}
3659

3760
public void WriteError(string message)
3861
{
3962
Trace.WriteLine($"Error: {message}");
63+
LogMessageInChunks($"Error: {message}");
4064
}
4165
}
4266
}

src/CLU/Commands.Common.ScenarioTest/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Commands.ScenarioTests.ResourceManager.Common": "",
2424
"Microsoft.Azure.Commands.Profile": "",
2525
"Microsoft.Azure.Management.Resources": "3.3.0-preview",
26+
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
2627
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
2728
"Microsoft.Rest.ClientRuntime": "1.8.0",
2829
"Microsoft.Rest.ClientRuntime.Azure": "2.5.1",

src/CLU/Commands.Common/Properties/Resources.Designer.cs

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

0 commit comments

Comments
 (0)