Skip to content

Commit 80acde2

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into hovsepmdev
2 parents 9a9b44f + 0b16a63 commit 80acde2

File tree

52 files changed

+3558
-3420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3558
-3420
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## 2015.09.03 version 0.9.8
2+
* Azure Redis Cache cmdlets
3+
* New-AzureRMRedisCache - 'RedisVersion' parameter is deprecated.
24
* Azure Compute (ARM) Cmdlets
35
* Added -Launch parameter for Get-AzureRemoteDesktopFile cmdlet
46
* Added Id parameter for VM cmdlets to support piping scenario without ResourceGroupName parameter

src/Common/Commands.Profile/Microsoft.WindowsAzure.Commands.Profile.dll-Help.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@
399399
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="7">
400400
<maml:name>GalleryEndpoint</maml:name>
401401
<maml:description>
402-
<maml:para>Specifies the endpoint for the Azure Resource Manager gallery, which stores resource group gallery templates. For more information about Azure resource groups and gallery templates, see the help topic for Get-AzureResourceGroupGalleryTemplate.</maml:para>
402+
<maml:para>Specifies the endpoint for the Azure Resource Manager gallery, which stores resource group gallery templates.</maml:para>
403403
</maml:description>
404404
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
405405
</command:parameter>
@@ -528,7 +528,7 @@
528528
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="7">
529529
<maml:name>GalleryEndpoint</maml:name>
530530
<maml:description>
531-
<maml:para>Specifies the endpoint for the Azure Resource Manager gallery, which stores resource group gallery templates. For more information about Azure resource groups and gallery templates, see the help topic for Get-AzureResourceGroupGalleryTemplate.</maml:para>
531+
<maml:para>Specifies the endpoint for the Azure Resource Manager gallery, which stores resource group gallery templates.</maml:para>
532532
</maml:description>
533533
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
534534
<dev:type>
@@ -3946,7 +3946,7 @@
39463946
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="7">
39473947
<maml:name>GalleryEndpoint</maml:name>
39483948
<maml:description>
3949-
<maml:para>Changes the endpoint for the Azure Resource Manager gallery to the specified value. The gallery endpoint is the location for resource group gallery templates. For more information about Azure resource groups and gallery templates, see the help topic for Get-AzureResourceGroupGalleryTemplate.</maml:para>
3949+
<maml:para>Changes the endpoint for the Azure Resource Manager gallery to the specified value. The gallery endpoint is the location for resource group gallery templates.</maml:para>
39503950
</maml:description>
39513951
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
39523952
</command:parameter>
@@ -4075,7 +4075,7 @@
40754075
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="7">
40764076
<maml:name>GalleryEndpoint</maml:name>
40774077
<maml:description>
4078-
<maml:para>Changes the endpoint for the Azure Resource Manager gallery to the specified value. The gallery endpoint is the location for resource group gallery templates. For more information about Azure resource groups and gallery templates, see the help topic for Get-AzureResourceGroupGalleryTemplate.</maml:para>
4078+
<maml:para>Changes the endpoint for the Azure Resource Manager gallery to the specified value. The gallery endpoint is the location for resource group gallery templates.</maml:para>
40794079
</maml:description>
40804080
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
40814081
<dev:type>

src/Common/Commands.ResourceManager.Common/RMProfileClient.cs

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
using Microsoft.Azure.Common.Authentication;
1717
using Microsoft.Azure.Common.Authentication.Factories;
1818
using Microsoft.Azure.Common.Authentication.Models;
19+
using Microsoft.Azure.Common.Authentication.Properties;
1920
using Microsoft.Azure.Subscriptions;
2021
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2122
using System;
2223
using System.Collections.Generic;
24+
using System.Diagnostics;
2325
using System.Linq;
2426
using System.Management.Automation;
2527
using System.Security;
@@ -60,9 +62,10 @@ public AzureRMProfile Login(AzureAccount account, AzureEnvironment environment,
6062
{
6163
foreach(var tenant in ListAccountTenants(account, environment, password, promptBehavior))
6264
{
63-
if (TryGetTenantSubscription(account, environment, tenant.Id.ToString(), subscriptionId, password, ShowDialog.Auto, out newSubscription, out newTenant))
65+
AzureTenant tempTenant;
66+
if (TryGetTenantSubscription(account, environment, tenant.Id.ToString(), subscriptionId, password, ShowDialog.Auto, out newSubscription, out tempTenant))
6467
{
65-
break;
68+
newTenant = tempTenant;
6669
}
6770
}
6871
}
@@ -140,6 +143,98 @@ public bool TryGetSubscription(string tenantId, string subscriptionId, out Azure
140143
tenantId, subscriptionId, null, ShowDialog.Never, out subscription, out tenant);
141144
}
142145

146+
public AzureEnvironment AddOrSetEnvironment(AzureEnvironment environment)
147+
{
148+
if (environment == null)
149+
{
150+
throw new ArgumentNullException("environment", Resources.EnvironmentNeedsToBeSpecified);
151+
}
152+
153+
if (AzureEnvironment.PublicEnvironments.ContainsKey(environment.Name))
154+
{
155+
throw new ArgumentException(Resources.ChangingDefaultEnvironmentNotSupported, "environment");
156+
}
157+
158+
if (_profile.Environments.ContainsKey(environment.Name))
159+
{
160+
_profile.Environments[environment.Name] =
161+
MergeEnvironmentProperties(environment, _profile.Environments[environment.Name]);
162+
}
163+
else
164+
{
165+
_profile.Environments[environment.Name] = environment;
166+
}
167+
168+
return _profile.Environments[environment.Name];
169+
}
170+
171+
public List<AzureEnvironment> ListEnvironments(string name)
172+
{
173+
var result = new List<AzureEnvironment>();
174+
175+
if (string.IsNullOrWhiteSpace(name))
176+
{
177+
result.AddRange(_profile.Environments.Values);
178+
}
179+
else if (_profile.Environments.ContainsKey(name))
180+
{
181+
result.Add(_profile.Environments[name]);
182+
}
183+
184+
return result;
185+
}
186+
187+
public AzureEnvironment RemoveEnvironment(string name)
188+
{
189+
if (string.IsNullOrEmpty(name))
190+
{
191+
throw new ArgumentNullException("name", Resources.EnvironmentNameNeedsToBeSpecified);
192+
}
193+
if (AzureEnvironment.PublicEnvironments.ContainsKey(name))
194+
{
195+
throw new ArgumentException(Resources.RemovingDefaultEnvironmentsNotSupported, "name");
196+
}
197+
198+
if (_profile.Environments.ContainsKey(name))
199+
{
200+
var environment = _profile.Environments[name];
201+
_profile.Environments.Remove(name);
202+
return environment;
203+
}
204+
else
205+
{
206+
throw new ArgumentException(string.Format(Resources.EnvironmentNotFound, name), "name");
207+
}
208+
}
209+
210+
private AzureEnvironment MergeEnvironmentProperties(AzureEnvironment environment1, AzureEnvironment environment2)
211+
{
212+
if (environment1 == null || environment2 == null)
213+
{
214+
throw new ArgumentNullException("environment1");
215+
}
216+
if (!string.Equals(environment1.Name, environment2.Name, StringComparison.InvariantCultureIgnoreCase))
217+
{
218+
throw new ArgumentException("Environment names do not match.");
219+
}
220+
AzureEnvironment mergedEnvironment = new AzureEnvironment
221+
{
222+
Name = environment1.Name
223+
};
224+
225+
// Merge all properties
226+
foreach (AzureEnvironment.Endpoint property in Enum.GetValues(typeof(AzureEnvironment.Endpoint)))
227+
{
228+
string propertyValue = environment1.GetEndpoint(property) ?? environment2.GetEndpoint(property);
229+
if (propertyValue != null)
230+
{
231+
mergedEnvironment.Endpoints[property] = propertyValue;
232+
}
233+
}
234+
235+
return mergedEnvironment;
236+
}
237+
143238
private bool TryGetTenantSubscription(
144239
AzureAccount account,
145240
AzureEnvironment environment,
@@ -251,7 +346,8 @@ private IEnumerable<AzureSubscription> ListSubscriptionsForTenant(AzureAccount a
251346
environment,
252347
tenantId,
253348
password,
254-
promptBehavior);
349+
promptBehavior,
350+
TokenCache.DefaultShared);
255351
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
256352
new TokenCloudCredentials(accessToken.AccessToken),
257353
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
</ItemGroup>
184184
<ItemGroup>
185185
<Compile Include="AzureRMProfileTests.cs" />
186+
<Compile Include="EnvironmentCmdletTests.cs" />
186187
<Compile Include="MockSubscriptionClientFactory.cs" />
187188
<Compile Include="ProfileController.cs" />
188189
<Compile Include="SubscriptionCmdletTests.cs" />

0 commit comments

Comments
 (0)