Skip to content

Commit 65aded7

Browse files
authored
Add PSAzureSubscriptionPolicy for PSAzureSubScription. (#12569)
* Add PSAzureSubscriptionPolicy for PSAzureSubScription. * Update ChangeLog.md * Issue fix * Change constructor of PSAzureSubscriptionPolicy * remove localfeed and and test cases * Update Common.Netcore.Dependencies.targets
1 parent eadbb6e commit 65aded7

File tree

8 files changed

+302
-265
lines changed

8 files changed

+302
-265
lines changed

src/Accounts/Accounts.Test/SessionRecords/Microsoft.Azure.Commands.Profile.Test.SubscriptionCmdletTests/AllParameterSetsSucceed.json

Lines changed: 129 additions & 249 deletions
Large diffs are not rendered by default.

src/Accounts/Accounts.Test/SubscriptionCmdletTests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function Test-GetSubscriptionsEndToEnd
4545
Assert-True {$mostSubscriptions.Count -gt 0}
4646
$tenantSubscriptions = Get-AzSubscription -Tenant $tenant
4747
Assert-True {$tenantSubscriptions.Count -gt 0}
48+
Assert-NotNull $subscription.SubscriptionPolicies
4849
}
4950

5051
<#
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2+
using Microsoft.Azure.Commands.Profile.Models;
3+
using Microsoft.Azure.Internal.Subscriptions.Models;
4+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
5+
using Newtonsoft.Json;
6+
using System;
7+
using Xunit;
8+
9+
namespace Microsoft.Azure.Commands.Profile.Test.UnitTest
10+
{
11+
public class PSAzureSubscriptionTest
12+
{
13+
14+
[Fact]
15+
[Trait(Category.AcceptanceType, Category.CheckIn)]
16+
public void NewPSAzureSubscription()
17+
{
18+
string locationPlacementId = "Internal_2014-09-01";
19+
string quotaId= "Internal_2014-09-01";
20+
SpendingLimit spendingLimit = SpendingLimit.Off;
21+
var subscriptionPolicies = new SubscriptionPolicies(locationPlacementId, quotaId, spendingLimit);
22+
23+
// test PSAzureSubscriptionPolicies' constructors
24+
var psAzureSubscriptionPolicies = new PSAzureSubscriptionPolicy(subscriptionPolicies);
25+
Assert.Equal(psAzureSubscriptionPolicies.LocationPlacementId, locationPlacementId);
26+
Assert.Equal(psAzureSubscriptionPolicies.QuotaId, quotaId);
27+
Assert.Equal(psAzureSubscriptionPolicies.SpendingLimit, spendingLimit.ToString());
28+
29+
var psAzureSubscriptionPolicies2 = new PSAzureSubscriptionPolicy(JsonConvert.SerializeObject(subscriptionPolicies));
30+
Assert.Equal(psAzureSubscriptionPolicies2.LocationPlacementId, locationPlacementId);
31+
Assert.Equal(psAzureSubscriptionPolicies2.QuotaId, quotaId);
32+
Assert.Equal(psAzureSubscriptionPolicies2.SpendingLimit, spendingLimit.ToString());
33+
34+
var sub = new AzureSubscription
35+
{
36+
Id = new Guid().ToString(),
37+
Name = "Contoso Test Subscription",
38+
State = "Enabled",
39+
};
40+
sub.SetAccount("[email protected]");
41+
sub.SetEnvironment("testCloud");
42+
sub.SetTenant(new Guid("3c0ff8a7-e8bb-40e8-ae66-271343379af6").ToString());
43+
sub.SetSubscriptionPolicies(JsonConvert.SerializeObject(subscriptionPolicies));
44+
45+
// test PSAzureSubscription's constructor
46+
var psAzureSubscription = new PSAzureSubscription(sub);
47+
Assert.NotNull(psAzureSubscription.SubscriptionPolicies);
48+
Assert.Equal(psAzureSubscription.SubscriptionPolicies.LocationPlacementId, locationPlacementId);
49+
Assert.Equal(psAzureSubscription.SubscriptionPolicies.QuotaId, quotaId);
50+
Assert.Equal(psAzureSubscription.SubscriptionPolicies.SpendingLimit, spendingLimit.ToString());
51+
}
52+
}
53+
}

src/Accounts/Accounts/Accounts.format.ps1xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,45 @@
171171
</TableRowEntries>
172172
</TableControl>
173173
</View>
174+
<View>
175+
<Name>Microsoft.Azure.Commands.Profile.Models.PSAzureSubscriptionPolicy</Name>
176+
<ViewSelectedBy>
177+
<TypeName>Microsoft.Azure.Commands.Profile.Models.PSAzureSubscriptionPolicy</TypeName>
178+
</ViewSelectedBy>
179+
<TableControl>
180+
<TableHeaders>
181+
<TableColumnHeader>
182+
<Alignment>Left</Alignment>
183+
<Label>locationPlacementId</Label>
184+
</TableColumnHeader>
185+
<TableColumnHeader>
186+
<Alignment>Left</Alignment>
187+
<Label>QuotaId</Label>
188+
</TableColumnHeader>
189+
<TableColumnHeader>
190+
<Alignment>Left</Alignment>
191+
<Label>SpendingLimit</Label>
192+
</TableColumnHeader>
193+
</TableHeaders>
194+
<TableRowEntries>
195+
<TableRowEntry>
196+
<TableColumnItems>
197+
<TableColumnItem>
198+
<Alignment>Left</Alignment>
199+
<PropertyName>locationPlacementId</PropertyName>
200+
</TableColumnItem>
201+
<TableColumnItem>
202+
<Alignment>Left</Alignment>
203+
<PropertyName>QuotaId</PropertyName>
204+
</TableColumnItem>
205+
<TableColumnItem>
206+
<Alignment>Left</Alignment>
207+
<PropertyName>SpendingLimit</PropertyName>
208+
</TableColumnItem>
209+
</TableColumnItems>
210+
</TableRowEntry>
211+
</TableRowEntries>
212+
</TableControl>
213+
</View>
174214
</ViewDefinitions>
175215
</Configuration>

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Exposed SubscriptionPolicies in `Get-AzSubscription` [#12551]
2122

2223
## Version 1.9.2
2324
* Updated `Connect-AzAccount` to accept parameter `MaxContextPopulation` [#9865]

src/Accounts/Authentication.ResourceManager/Models/PSAzureSubscription.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ public string CurrentStorageAccountName
152152
}
153153
}
154154

155+
private PSAzureSubscriptionPolicy _subscriptionPolicies;
156+
157+
public PSAzureSubscriptionPolicy SubscriptionPolicies {
158+
get
159+
{
160+
if (this._subscriptionPolicies == null)
161+
{
162+
this._subscriptionPolicies= new PSAzureSubscriptionPolicy(this.GetSubscriptionPolicies());
163+
}
164+
return this._subscriptionPolicies;
165+
}
166+
}
167+
155168
public IDictionary<string, string> ExtendedProperties { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
156169

157170
public string CurrentStorageAccount
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Newtonsoft.Json;
2+
using Microsoft.Azure.Internal.Subscriptions.Models;
3+
4+
namespace Microsoft.Azure.Commands.Profile.Models
5+
{
6+
public class PSAzureSubscriptionPolicy
7+
{
8+
/// <summary>
9+
/// Default constructor
10+
/// </summary>
11+
public PSAzureSubscriptionPolicy()
12+
{
13+
14+
}
15+
16+
/// <summary>
17+
/// object constructor
18+
/// </summary>
19+
/// <param name="azureSubscriptionPolicies">Json string to convert</param>
20+
public PSAzureSubscriptionPolicy(SubscriptionPolicies subscriptionPolicies)
21+
{
22+
if (subscriptionPolicies != null)
23+
{
24+
this.LocationPlacementId = subscriptionPolicies.LocationPlacementId;
25+
this.QuotaId = subscriptionPolicies.QuotaId;
26+
this.SpendingLimit = subscriptionPolicies.SpendingLimit.ToString();
27+
}
28+
}
29+
30+
/// <summary>
31+
/// string constructor
32+
/// </summary>
33+
/// <param name="azureSubscriptionPolicies">Json string to convert</param>
34+
public PSAzureSubscriptionPolicy(string azureSubscriptionPolicies) : this(string.IsNullOrEmpty(azureSubscriptionPolicies)?null:JsonConvert.DeserializeObject<SubscriptionPolicies>(azureSubscriptionPolicies)) { }
35+
36+
public string LocationPlacementId { get; private set; }
37+
38+
public string QuotaId { get; private set; }
39+
40+
public string SpendingLimit { get; private set; }
41+
42+
public override string ToString()
43+
{
44+
return JsonConvert.SerializeObject(this, Formatting.Indented,
45+
new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
46+
}
47+
48+
}
49+
}

tools/Common.Netcore.Dependencies.targets

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
<ItemGroup>
44
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.20"/>
55
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19"/>
6-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.20-preview"/>
7-
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.20-preview"/>
8-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.20-preview"/>
9-
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.20-preview"/>
10-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.20-preview"/>
11-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.20-preview"/>
12-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.20-preview"/>
13-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.20-preview"/>
14-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.20-preview"/>
15-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.20-preview"/>
16-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.20-preview"/>
17-
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.20-preview"/>
18-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.20-preview"/>
19-
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.20-preview"/>
20-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.20-preview"/>
6+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.21-preview"/>
7+
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.21-preview"/>
8+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.21-preview"/>
9+
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.21-preview"/>
10+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.21-preview"/>
11+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.21-preview"/>
12+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.21-preview"/>
13+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.21-preview"/>
14+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.21-preview"/>
15+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.21-preview"/>
16+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.21-preview"/>
17+
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.21-preview"/>
18+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.21-preview"/>
19+
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.21-preview"/>
20+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.21-preview"/>
2121
</ItemGroup>
2222
<ItemGroup Condition="'$(IsTestProject)' != 'true'">
2323
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.4.0">
@@ -32,7 +32,7 @@
3232
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
3333
</ItemGroup>
3434
<PropertyGroup>
35-
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.20-preview\tools\</StorageToolsPath>
35+
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.21-preview\tools\</StorageToolsPath>
3636
</PropertyGroup>
3737
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
3838
<PackageReference Include="Newtonsoft.Json" Version="10.0.3"/>

0 commit comments

Comments
 (0)