Skip to content

Commit

Permalink
Merge pull request #3 from Azure/dev
Browse files Browse the repository at this point in the history
u
  • Loading branch information
huangpf committed May 6, 2015
2 parents e8e669c + a58af04 commit 45dfa3b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<meta name="google-site-verification" content="tZgbB2s-hTI0IePQQRCjHqL_Vf0j_XJmehXAHJerrn4" />
# Microsoft Azure PowerShell

This repository contains a set of PowerShell cmdlets for developers and administrators to develop, deploy and manage Microsoft Azure applications.
Expand Down
17 changes: 17 additions & 0 deletions src/Common/Commands.Profile/Models/PsAzureSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,29 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Linq;
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Models;

namespace Microsoft.WindowsAzure.Commands.Profile.Models
{
public class PSAzureSubscription
{
public PSAzureSubscription() {}
public PSAzureSubscription(AzureSubscription subscription, AzureProfile profile)
{
SubscriptionId = subscription.Id.ToString();
SubscriptionName = subscription.Name;
Environment = subscription.Environment;
SupportedModes = subscription.GetProperty(AzureSubscription.Property.SupportedModes);
DefaultAccount = subscription.Account;
Accounts = profile.Accounts.Values.Where(a => a.HasSubscription(subscription.Id)).ToArray();
IsDefault = subscription.IsPropertySet(AzureSubscription.Property.Default);
IsCurrent = profile.Context.Subscription != null && profile.Context.Subscription.Id == subscription.Id;
CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount);
TenantId = subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants).FirstOrDefault();
}

public string SubscriptionId { get; set; }
public string SubscriptionName { get; set; }
public string Environment { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public PSAzureSubscriptionExtended(PSAzureSubscription subscription)
base.Accounts = subscription.Accounts;
base.IsDefault = subscription.IsDefault;
base.IsCurrent = subscription.IsCurrent;
base.TenantId = subscription.TenantId;
}
public string ActiveDirectoryUserId { get; set; }
public AzureAccount Account { get; set; }
Expand Down
25 changes: 4 additions & 21 deletions src/Common/Commands.Profile/Subscription/GetAzureSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Microsoft.WindowsAzure.Commands.Profile
/// the AzureProfile layer.
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureSubscription", DefaultParameterSetName = "ByName")]
[OutputType(typeof(AzureSubscription))]
[OutputType(typeof(PSAzureSubscription))]
public class GetAzureSubscriptionCommand : SubscriptionCmdletBase
{
public GetAzureSubscriptionCommand()
Expand Down Expand Up @@ -141,29 +141,12 @@ private void WriteSubscriptions(IEnumerable<AzureSubscription> subscriptions)
}
else
{
subscriptionOutput = subscriptions.Select(ConstructPsAzureSubscription);
subscriptionOutput = subscriptions.Select(s => new PSAzureSubscription(s, ProfileClient.Profile));
}

WriteObject(subscriptionOutput, true);
}

private PSAzureSubscription ConstructPsAzureSubscription(AzureSubscription subscription)
{
PSAzureSubscription psObject = new PSAzureSubscription();

psObject.SubscriptionId = subscription.Id.ToString();
psObject.SubscriptionName = subscription.Name;
psObject.Environment = subscription.Environment;
psObject.SupportedModes = subscription.GetProperty(AzureSubscription.Property.SupportedModes);
psObject.DefaultAccount = subscription.Account;
psObject.Accounts = ProfileClient.Profile.Accounts.Values.Where(a => a.HasSubscription(subscription.Id)).ToArray();
psObject.IsDefault = subscription.IsPropertySet(AzureSubscription.Property.Default);
psObject.IsCurrent = Profile.Context.Subscription != null && Profile.Context.Subscription.Id == subscription.Id;
psObject.CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount);
psObject.TenantId = subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants).FirstOrDefault();
return psObject;
}

private PSAzureSubscriptionExtended ConstructPsAzureSubscriptionExtended(AzureSubscription subscription, IClientFactory clientFactory)
{
using (var client = clientFactory.CreateClient<ManagementClient>(Profile, subscription, AzureEnvironment.Endpoint.ServiceManagement))
Expand All @@ -172,8 +155,8 @@ private PSAzureSubscriptionExtended ConstructPsAzureSubscriptionExtended(AzureSu
var environment = ProfileClient.GetEnvironmentOrDefault(subscription.Environment);
var account = ProfileClient.Profile.Accounts[subscription.Account];
bool isCert = account.Type == AzureAccount.AccountType.Certificate;

PSAzureSubscriptionExtended result = new PSAzureSubscriptionExtended(ConstructPsAzureSubscription(subscription))
var psAzureSubscription = new PSAzureSubscription(subscription, ProfileClient.Profile);
PSAzureSubscriptionExtended result = new PSAzureSubscriptionExtended(psAzureSubscription)
{
AccountAdminLiveEmailId = response.AccountAdminLiveEmailId,
ActiveDirectoryUserId = subscription.Account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
using Microsoft.WindowsAzure.Commands.Common.Properties;
using Microsoft.WindowsAzure.Commands.Utilities.Profile;
using Microsoft.Azure.Common.Authentication;
using Microsoft.WindowsAzure.Commands.Profile.Models;

namespace Microsoft.WindowsAzure.Commands.Profile
{


[Cmdlet(VerbsCommon.Select, "AzureSubscription", DefaultParameterSetName = SelectSubscriptionByNameParameterSet)]
[OutputType(typeof(AzureSubscription))]
[OutputType(typeof(PSAzureSubscription))]
public class SelectAzureSubscriptionCommand : SubscriptionCmdletBase
{
private const string SelectSubscriptionByIdParameterSet = "SelectSubscriptionByIdParameterSet";
Expand Down Expand Up @@ -123,7 +124,7 @@ public override void ExecuteCmdlet()

if (PassThru.IsPresent && azureSubscription != null)
{
WriteObject(azureSubscription);
WriteObject(new PSAzureSubscription(azureSubscription, ProfileClient.Profile));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
using Microsoft.WindowsAzure.Commands.Profile;
using Microsoft.WindowsAzure.Commands.Profile.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -731,7 +732,7 @@ public void SelectAzureSubscriptionWithPassthroughPrintsSubscription()

// Verify
Assert.Equal(1, commandRuntimeMock.OutputPipeline.Count);
Assert.True(commandRuntimeMock.OutputPipeline[0] is AzureSubscription);
Assert.True(commandRuntimeMock.OutputPipeline[0] is PSAzureSubscription);
}

[Fact]
Expand Down

0 comments on commit 45dfa3b

Please sign in to comment.