Skip to content

Commit e2ffb12

Browse files
author
Hao Chen
committed
Merge branch 'clu' of github.com:Azure/azure-powershell into hovsep-clu
2 parents 5024c50 + 6bede14 commit e2ffb12

File tree

17 files changed

+334
-16
lines changed

17 files changed

+334
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Azure PowerShell specific
22
src/Publish/
33
src/Package/
4+
drop/
45

56
obj
67
TestResults

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ private AuthenticationResult AcquireToken(AdalConfiguration config, Authenticati
130130

131131
try
132132
{
133-
UserCredential credential = new UserCredential(userId, password);
134-
135133
DeviceCodeResult codeResult = context.AcquireDeviceCodeAsync(
136134
config.ResourceClientUri,
137135
config.ClientId)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public IAccessToken Authenticate(
6565
}
6666
else
6767
{
68+
if (account.IsPropertySet(AzureAccount.Property.ApplicationSecret))
69+
{
70+
password = password ?? account.GetProperty(AzureAccount.Property.ApplicationSecret);
71+
}
6872
token = TokenProvider.GetAccessToken(configuration, behavior, account.Id, password, account.Type);
6973
}
7074

src/CLU/Commands.Common/AzurePSCmdlet.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ protected virtual T GetSessionVariableValue<T>(string name, T defaultValue) wher
107107
{
108108
try
109109
{
110-
returnValue = SessionState.PSVariable.Get<T>(name)?? defaultValue ;
110+
returnValue = SessionState.PSVariable.Get<T>(name) ?? defaultValue;
111+
}
112+
catch
113+
{
114+
}
115+
}
116+
else
117+
{
118+
try
119+
{
111120
var variablePath = GetPath(name);
112121
var fileText = DataStore.ReadFileAsText(variablePath);
113122
if (!string.IsNullOrEmpty(fileText))
@@ -117,6 +126,7 @@ protected virtual T GetSessionVariableValue<T>(string name, T defaultValue) wher
117126
}
118127
catch
119128
{
129+
120130
}
121131
}
122132

@@ -127,11 +137,15 @@ protected virtual string GetPath(string variableName)
127137
{
128138
return Path.Combine(Directory.GetCurrentDirectory(), "sessions", variableName);
129139
}
140+
130141
protected virtual void SetSessionVariable<T>(string name, T value) where T : class
131142
{
132143
if (SessionState != null)
133144
{
134145
SessionState.PSVariable.Set(name, value);
146+
}
147+
else
148+
{
135149
var variablePath = GetPath(name);
136150
DataStore.WriteFile(variablePath, JsonConvert.SerializeObject(value));
137151
}
@@ -270,7 +284,7 @@ protected override void BeginProcessing()
270284
WriteDebugWithTimestamp(string.Format("using account id '{0}'...", DefaultContext.Account.Id));
271285
}
272286

273-
DataStore = GetSessionVariableValue<IDataStore>(AzurePowerShell.DataStoreVariable, new DiskDataStore());
287+
DataStore = DataStore?? GetSessionVariableValue<IDataStore>(AzurePowerShell.DataStoreVariable, new DiskDataStore());
274288
_adalListener = _adalListener ?? new DebugStreamTraceListener(_debugMessages);
275289
DebugStreamTraceListener.AddAdalTracing(_adalListener);
276290

@@ -339,11 +353,7 @@ protected bool IsVerbose()
339353
protected new void WriteObject(object sendToPipeline)
340354
{
341355
FlushDebugMessages();
342-
#if DEBUG
343-
CommandRuntime.WriteObject(sendToPipeline);
344-
#else
345356
base.WriteObject(sendToPipeline);
346-
#endif
347357
}
348358

349359
protected new void WriteObject(object sendToPipeline, bool enumerateCollection)

src/CLU/Commands.Common/Models/PSAzureRmAccount.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ public static implicit operator PSAzureRmAccount(AzureAccount account)
5757
result.CertificateThumbprint = account.GetProperty(AzureAccount.Property.CertificateThumbprint);
5858
}
5959

60-
return result;
60+
if (account.IsPropertySet(AzureAccount.Property.ApplicationSecret))
61+
{
62+
result.ApplicationSecret = account.GetProperty(AzureAccount.Property.ApplicationSecret);
63+
}
64+
65+
return result;
6166
}
6267

6368
/// <summary>
@@ -99,6 +104,11 @@ public static implicit operator AzureAccount(PSAzureRmAccount account)
99104
{
100105
result.SetProperty(AzureAccount.Property.CertificateThumbprint, account.CertificateThumbprint);
101106
}
107+
108+
if (!string.IsNullOrWhiteSpace(account.ApplicationSecret))
109+
{
110+
result.SetProperty(AzureAccount.Property.ApplicationSecret, account.ApplicationSecret);
111+
}
102112
return result;
103113
}
104114

@@ -126,6 +136,8 @@ public static implicit operator AzureAccount(PSAzureRmAccount account)
126136
/// </summary>
127137
public string CertificateThumbprint { get; set; }
128138

139+
public string ApplicationSecret { get; set; }
140+
129141
public override string ToString()
130142
{
131143
return this.Id;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RtPackage: Microsoft.CLU.Commands
2+
RtEntry: Microsoft.CLU.CommandModel.CmdletCommandModel.Run
3+
RtAssembly: Microsoft.CLU.dll
4+
Modules: Microsoft.Azure.Commands.Resources.Cmdlets
5+
NounPrefix: AzureRm
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Name: Microsoft.Azure.Commands.Resources.Cmdlets
2+
CommandAssemblies: Commands.ResourceManager.Cmdlets.dll
3+
NounPrefix: AzureRm
4+
NounFirst: true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Threading.Tasks;
19+
20+
namespace Microsoft.Azure.Commands
21+
{
22+
public class EntryStub
23+
{
24+
public static void Main(string[] args)
25+
{
26+
// empty entry point
27+
}
28+
}
29+
}

src/CLU/Commands.ResourceManager.Cmdlets/Extensions/ResourceExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ internal static PSObject ToPsObject(this Resource<JToken> resource)
5353
{ "Location", resource.Location },
5454
{ "SubscriptionId", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetSubscriptionId(resource.Id) },
5555
{ "Tags", TagsHelper.GetTagsHashtables(resource.Tags) },
56-
{ "Plan", resource.Plan.ToJToken().ToPsObject() },
56+
{ "Plan", resource.Plan == null ? null : resource.Plan.ToJToken().ToPsObject() },
5757
{ "Properties", ResourceExtensions.GetProperties(resource) },
5858
{ "CreatedTime", resource.CreatedTime },
5959
{ "ChangedTime", resource.ChangedTime },
6060
{ "ETag", resource.ETag },
61-
{ "Sku", resource.Sku.ToJToken().ToPsObject() },
61+
{ "Sku", resource.Sku == null ? null : resource.Sku.ToJToken().ToPsObject() },
6262
};
6363

6464
var resourceTypeName = resourceType == null && extensionResourceType == null
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
3+
<metadata minClientVersion="2.5">
4+
<id>Microsoft.Azure.Commands.Resources.Cmdlets</id>
5+
<title>Microsoft Azure Resources Cmdlets</title>
6+
<version>%PackageVersion%</version>
7+
<authors>Microsoft</authors>
8+
<owners>azure-sdk, PowerShell, Microsoft</owners>
9+
<licenseUrl>http://aka.ms/windowsazureapache2</licenseUrl>
10+
<projectUrl>https://github.com/Azure/azure-powershell</projectUrl>
11+
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</iconUrl>
12+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
13+
<summary>Cross-Platform cmdlets for Microsoft Azure Resources management.</summary>
14+
<description>
15+
Cross-Platform cmdlets for Microsoft Azure Resources management.
16+
17+
Supported Library Platforms:
18+
- .NET Framework 5.0
19+
</description>
20+
<copyright>Copyright © Microsoft Corporation</copyright>
21+
<tags>Microsoft "Microsoft Azure" Azure cloud PowerShell WMF Windows Management Framework azureofficial windowsazureofficial</tags>
22+
<references>
23+
<group targetFramework="dnxcore50">
24+
%ReferenceFiles% </group>
25+
</references>
26+
<dependencies/>
27+
</metadata>
28+
<files>
29+
%SourceFiles%%ContentFiles% </files>
30+
</package>

src/CLU/Commands.ScenarioTests.ResourceManager.Common/Mocks/MockCommandRuntime.cs

Lines changed: 129 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Collections;
1717
using System.Collections.Generic;
18+
using System.Collections.ObjectModel;
1819
using System.Diagnostics.CodeAnalysis;
1920
using System.Globalization;
2021
using System.Management.Automation;
@@ -96,6 +97,7 @@ public override Version Version
9697
public List<string> WarningStream = new List<string>();
9798
public List<string> VerboseStream = new List<string>();
9899
public List<string> DebugStream = new List<string>();
100+
PSHost _host = new MockPSHost();
99101

100102
public override string ToString()
101103
{
@@ -105,11 +107,11 @@ public override string ToString()
105107

106108
[SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations",
107109
Justification = "Tests should not access this property")]
108-
public System.Management.Automation.Host.PSHost Host
110+
public PSHost Host
109111
{
110112
get
111113
{
112-
return null;
114+
return _host;
113115
}
114116
}
115117

@@ -219,5 +221,130 @@ public void ResetPipelines()
219221
WarningStream.Clear();
220222
VerboseStream.Clear();
221223
}
224+
225+
class MockPSHost : PSHost
226+
{
227+
PSHostUserInterface _hostUI = new MockPSHostUI();
228+
Version _version = new Version(1, 0, 0);
229+
Guid _instanceId = Guid.NewGuid();
230+
public override CultureInfo CurrentCulture
231+
{
232+
get { return CultureInfo.CurrentCulture; }
233+
}
234+
235+
public override CultureInfo CurrentUICulture
236+
{
237+
get
238+
{
239+
return CultureInfo.CurrentUICulture;
240+
}
241+
}
242+
243+
public override Guid InstanceId
244+
{
245+
get
246+
{
247+
return _instanceId;
248+
}
249+
}
250+
251+
public override bool IsInputRedirected
252+
{
253+
get
254+
{
255+
return false;
256+
}
257+
}
258+
259+
public override bool IsOutputRedirected
260+
{
261+
get
262+
{
263+
return true;
264+
}
265+
}
266+
267+
public override string Name
268+
{
269+
get
270+
{
271+
return "MockHost";
272+
}
273+
}
274+
275+
public override PSHostUserInterface UI
276+
{
277+
get { return _hostUI; }
278+
}
279+
280+
public override Version Version
281+
{
282+
get
283+
{
284+
return new Version(1, 0 , 0);
285+
}
286+
}
287+
288+
class MockPSHostUI : PSHostUserInterface
289+
{
290+
public override Dictionary<string, PSObject> Prompt(string caption, string message, Collection<FieldDescription> descriptions)
291+
{
292+
return new Dictionary<string, PSObject>();
293+
}
294+
295+
public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices, int defaultChoice)
296+
{
297+
return 0;
298+
}
299+
300+
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName)
301+
{
302+
return new PSCredential("[email protected]", "P@$$w0rd!");
303+
}
304+
305+
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName,
306+
PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options)
307+
{
308+
return new PSCredential("[email protected]", "P@$$w0rd!");
309+
}
310+
311+
public override string ReadLine()
312+
{
313+
return null;
314+
}
315+
316+
public override void Write(string value)
317+
{
318+
}
319+
320+
public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
321+
{
322+
}
323+
324+
public override void WriteDebugLine(string message)
325+
{
326+
}
327+
328+
public override void WriteErrorLine(string value)
329+
{
330+
}
331+
332+
public override void WriteLine(string value)
333+
{
334+
}
335+
336+
public override void WriteProgress(long sourceId, ProgressRecord record)
337+
{
338+
}
339+
340+
public override void WriteVerboseLine(string message)
341+
{
342+
}
343+
344+
public override void WriteWarningLine(string message)
345+
{
346+
}
347+
}
348+
}
222349
}
223350
}

src/CLU/Microsoft.Azure.Commands.Profile.Test/TenantCmdletTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ private void Login(string subscriptionId, string tenantId)
122122
cmdlt.TenantId = tenantId;
123123
cmdlt.DefaultProfile = _profile;
124124
cmdlt.AuthenticationFactory = _authFactory;
125+
cmdlt.Username = "[email protected]";
126+
cmdlt.Password = "Pa$$w0rd!";
125127

126128
// Act
127129
cmdlt.InvokeBeginProcessing();

0 commit comments

Comments
 (0)