Skip to content

Commit a58af04

Browse files
committed
Merge pull request #367 from amarzavery/dev
Fixes for github issues: 310, 329, 335.
2 parents e0f30d6 + e19b79d commit a58af04

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

src/Common/Commands.Profile/Models/PsAzureSubscription.cs

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

15+
using System.Linq;
16+
using Microsoft.Azure.Common.Authentication;
1517
using Microsoft.Azure.Common.Authentication.Models;
1618

1719
namespace Microsoft.WindowsAzure.Commands.Profile.Models
1820
{
1921
public class PSAzureSubscription
2022
{
23+
public PSAzureSubscription() {}
24+
public PSAzureSubscription(AzureSubscription subscription, AzureProfile profile)
25+
{
26+
SubscriptionId = subscription.Id.ToString();
27+
SubscriptionName = subscription.Name;
28+
Environment = subscription.Environment;
29+
SupportedModes = subscription.GetProperty(AzureSubscription.Property.SupportedModes);
30+
DefaultAccount = subscription.Account;
31+
Accounts = profile.Accounts.Values.Where(a => a.HasSubscription(subscription.Id)).ToArray();
32+
IsDefault = subscription.IsPropertySet(AzureSubscription.Property.Default);
33+
IsCurrent = profile.Context.Subscription != null && profile.Context.Subscription.Id == subscription.Id;
34+
CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount);
35+
TenantId = subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants).FirstOrDefault();
36+
}
37+
2138
public string SubscriptionId { get; set; }
2239
public string SubscriptionName { get; set; }
2340
public string Environment { get; set; }

src/Common/Commands.Profile/Models/PsAzureSubscriptionExtended.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public PSAzureSubscriptionExtended(PSAzureSubscription subscription)
2929
base.Accounts = subscription.Accounts;
3030
base.IsDefault = subscription.IsDefault;
3131
base.IsCurrent = subscription.IsCurrent;
32+
base.TenantId = subscription.TenantId;
3233
}
3334
public string ActiveDirectoryUserId { get; set; }
3435
public AzureAccount Account { get; set; }

src/Common/Commands.Profile/Subscription/GetAzureSubscription.cs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace Microsoft.WindowsAzure.Commands.Profile
3232
/// the AzureProfile layer.
3333
/// </summary>
3434
[Cmdlet(VerbsCommon.Get, "AzureSubscription", DefaultParameterSetName = "ByName")]
35-
[OutputType(typeof(AzureSubscription))]
35+
[OutputType(typeof(PSAzureSubscription))]
3636
public class GetAzureSubscriptionCommand : SubscriptionCmdletBase
3737
{
3838
public GetAzureSubscriptionCommand()
@@ -141,29 +141,12 @@ private void WriteSubscriptions(IEnumerable<AzureSubscription> subscriptions)
141141
}
142142
else
143143
{
144-
subscriptionOutput = subscriptions.Select(ConstructPsAzureSubscription);
144+
subscriptionOutput = subscriptions.Select(s => new PSAzureSubscription(s, ProfileClient.Profile));
145145
}
146146

147147
WriteObject(subscriptionOutput, true);
148148
}
149149

150-
private PSAzureSubscription ConstructPsAzureSubscription(AzureSubscription subscription)
151-
{
152-
PSAzureSubscription psObject = new PSAzureSubscription();
153-
154-
psObject.SubscriptionId = subscription.Id.ToString();
155-
psObject.SubscriptionName = subscription.Name;
156-
psObject.Environment = subscription.Environment;
157-
psObject.SupportedModes = subscription.GetProperty(AzureSubscription.Property.SupportedModes);
158-
psObject.DefaultAccount = subscription.Account;
159-
psObject.Accounts = ProfileClient.Profile.Accounts.Values.Where(a => a.HasSubscription(subscription.Id)).ToArray();
160-
psObject.IsDefault = subscription.IsPropertySet(AzureSubscription.Property.Default);
161-
psObject.IsCurrent = Profile.Context.Subscription != null && Profile.Context.Subscription.Id == subscription.Id;
162-
psObject.CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount);
163-
psObject.TenantId = subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants).FirstOrDefault();
164-
return psObject;
165-
}
166-
167150
private PSAzureSubscriptionExtended ConstructPsAzureSubscriptionExtended(AzureSubscription subscription, IClientFactory clientFactory)
168151
{
169152
using (var client = clientFactory.CreateClient<ManagementClient>(Profile, subscription, AzureEnvironment.Endpoint.ServiceManagement))
@@ -172,8 +155,8 @@ private PSAzureSubscriptionExtended ConstructPsAzureSubscriptionExtended(AzureSu
172155
var environment = ProfileClient.GetEnvironmentOrDefault(subscription.Environment);
173156
var account = ProfileClient.Profile.Accounts[subscription.Account];
174157
bool isCert = account.Type == AzureAccount.AccountType.Certificate;
175-
176-
PSAzureSubscriptionExtended result = new PSAzureSubscriptionExtended(ConstructPsAzureSubscription(subscription))
158+
var psAzureSubscription = new PSAzureSubscription(subscription, ProfileClient.Profile);
159+
PSAzureSubscriptionExtended result = new PSAzureSubscriptionExtended(psAzureSubscription)
177160
{
178161
AccountAdminLiveEmailId = response.AccountAdminLiveEmailId,
179162
ActiveDirectoryUserId = subscription.Account,

src/Common/Commands.Profile/Subscription/SelectAzureSubscription.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
using Microsoft.WindowsAzure.Commands.Common.Properties;
2121
using Microsoft.WindowsAzure.Commands.Utilities.Profile;
2222
using Microsoft.Azure.Common.Authentication;
23+
using Microsoft.WindowsAzure.Commands.Profile.Models;
2324

2425
namespace Microsoft.WindowsAzure.Commands.Profile
2526
{
2627

2728

2829
[Cmdlet(VerbsCommon.Select, "AzureSubscription", DefaultParameterSetName = SelectSubscriptionByNameParameterSet)]
29-
[OutputType(typeof(AzureSubscription))]
30+
[OutputType(typeof(PSAzureSubscription))]
3031
public class SelectAzureSubscriptionCommand : SubscriptionCmdletBase
3132
{
3233
private const string SelectSubscriptionByIdParameterSet = "SelectSubscriptionByIdParameterSet";
@@ -123,7 +124,7 @@ public override void ExecuteCmdlet()
123124

124125
if (PassThru.IsPresent && azureSubscription != null)
125126
{
126-
WriteObject(azureSubscription);
127+
WriteObject(new PSAzureSubscription(azureSubscription, ProfileClient.Profile));
127128
}
128129
}
129130

src/ServiceManagement/Services/Commands.Test/Profile/ProfileCmdltsTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Microsoft.WindowsAzure.Commands.Common;
2424
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2525
using Microsoft.WindowsAzure.Commands.Profile;
26+
using Microsoft.WindowsAzure.Commands.Profile.Models;
2627
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2728
using System;
2829
using System.Collections.Generic;
@@ -731,7 +732,7 @@ public void SelectAzureSubscriptionWithPassthroughPrintsSubscription()
731732

732733
// Verify
733734
Assert.Equal(1, commandRuntimeMock.OutputPipeline.Count);
734-
Assert.True(commandRuntimeMock.OutputPipeline[0] is AzureSubscription);
735+
Assert.True(commandRuntimeMock.OutputPipeline[0] is PSAzureSubscription);
735736
}
736737

737738
[Fact]

0 commit comments

Comments
 (0)