Skip to content

Commit 1d42e41

Browse files
committed
Merge pull request Azure#364 from Azure/dev
HPF PR: dev <- Azure:dev
2 parents fc0027f + 1d15258 commit 1d42e41

File tree

9 files changed

+68
-2
lines changed

9 files changed

+68
-2
lines changed

src/Common/Commands.Common/ProfileClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,9 @@ private AzureSubscription MergeSubscriptionProperties(AzureSubscription subscrip
841841
Id = subscription1.Id,
842842
Name = subscription1.Name,
843843
Environment = subscription1.Environment,
844+
State = (subscription1.State != null &&
845+
subscription1.State.Equals(subscription2.State, StringComparison.OrdinalIgnoreCase)) ?
846+
subscription1.State: null,
844847
Account = subscription1.Account ?? subscription2.Account
845848
};
846849

src/ResourceManager/Profile/Commands.Profile/Context/SetAzureRMContext.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.Azure.Commands.ResourceManager.Common;
2121
using Microsoft.WindowsAzure.Commands.Common;
2222
using Microsoft.Azure.Commands.Profile.Properties;
23+
using System;
2324

2425
namespace Microsoft.Azure.Commands.Profile
2526
{
@@ -78,6 +79,18 @@ public override void ExecuteCmdlet()
7879
profileClient.SetCurrentContext(TenantId);
7980
}
8081
}
82+
83+
if (AzureRmProfileProvider.Instance.Profile.Context != null &&
84+
AzureRmProfileProvider.Instance.Profile.Context.Subscription != null &&
85+
AzureRmProfileProvider.Instance.Profile.Context.Subscription.State != null &&
86+
!AzureRmProfileProvider.Instance.Profile.Context.Subscription.State.Equals(
87+
"Enabled",
88+
StringComparison.OrdinalIgnoreCase))
89+
{
90+
WriteWarning(string.Format(
91+
Microsoft.Azure.Commands.Profile.Properties.Resources.SelectedSubscriptionNotActive,
92+
AzureRmProfileProvider.Instance.Profile.Context.Subscription.State));
93+
}
8194
WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context);
8295
}
8396
}

src/ResourceManager/Profile/Commands.Profile/Microsoft.Azure.Commands.Profile.format.ps1xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
<ListItem>
8686
<PropertyName>TenantId</PropertyName>
8787
</ListItem>
88+
<ListItem>
89+
<PropertyName>State</PropertyName>
90+
</ListItem>
8891
</ListItems>
8992
</ListEntry>
9093
</ListEntries>

src/ResourceManager/Profile/Commands.Profile/Models/ModelExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ internal static AzureSubscription ToAzureSubscription(this Subscription other, A
3131
subscription.Environment = context.Environment != null ? context.Environment.Name : EnvironmentName.AzureCloud;
3232
subscription.Id = new Guid(other.SubscriptionId);
3333
subscription.Name = other.DisplayName;
34+
subscription.State = other.State;
3435
subscription.SetProperty(AzureSubscription.Property.Tenants,
3536
context.Tenant.Id.ToString());
3637
return subscription;

src/ResourceManager/Profile/Commands.Profile/Models/PSAzureSubscription.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public static implicit operator PSAzureSubscription(AzureSubscription other)
3939
var subscription= new PSAzureSubscription
4040
{
4141
SubscriptionId = other.Id.ToString(),
42-
SubscriptionName = other.Name ,
42+
SubscriptionName = other.Name,
43+
State = other.State,
4344
TenantId = other.IsPropertySet(AzureSubscription.Property.Tenants)?
4445
other.GetProperty(AzureSubscription.Property.Tenants) : null
4546
};
@@ -89,6 +90,11 @@ public static implicit operator AzureSubscription(PSAzureSubscription other)
8990
result.Properties.SetProperty(AzureSubscription.Property.StorageAccount, other.CurrentStorageAccount);
9091
}
9192

93+
if (other.State != null)
94+
{
95+
result.State = other.State;
96+
}
97+
9298
return result;
9399
}
94100

@@ -102,6 +108,11 @@ public static implicit operator AzureSubscription(PSAzureSubscription other)
102108
/// </summary>
103109
public string SubscriptionName { get; set; }
104110

111+
/// <summary>
112+
/// Gets or sets subscription State
113+
/// </summary>
114+
public string State { get; set; }
115+
105116
/// <summary>
106117
/// The tenant home for the subscription.
107118
/// </summary>

src/ResourceManager/Profile/Commands.Profile/Models/RMProfileClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ public AzureRMProfile Login(
143143
else
144144
{
145145
_profile.Context = new AzureContext(newSubscription, account, environment, newTenant);
146+
if (!newSubscription.State.Equals("Enabled", StringComparison.OrdinalIgnoreCase))
147+
{
148+
WriteWarningMessage(string.Format(
149+
Microsoft.Azure.Commands.Profile.Properties.Resources.SelectedSubscriptionNotActive,
150+
newSubscription.State));
151+
}
146152
}
147153

148154
_profile.Context.TokenCache = TokenCache.DefaultShared.Serialize();
@@ -222,7 +228,11 @@ private void SwitchSubscription(AzureSubscription subscription)
222228
_profile.Context.Subscription.Properties[AzureSubscription.Property.Tenants] = tenantId;
223229
}
224230

225-
var newSubscription = new AzureSubscription { Id = subscription.Id };
231+
var newSubscription = new AzureSubscription
232+
{
233+
Id = subscription.Id,
234+
State = subscription.State
235+
};
226236
if (_profile.Context.Subscription != null)
227237
{
228238
newSubscription.Account = _profile.Context.Subscription.Account;
@@ -523,6 +533,7 @@ private bool TryGetTenantSubscription(IAccessToken accessToken,
523533
Account = accessToken.UserId,
524534
Environment = environment.Name,
525535
Name = subscriptionFromServer.DisplayName,
536+
State = subscriptionFromServer.State,
526537
Properties = new Dictionary<AzureSubscription.Property, string> { { AzureSubscription.Property.Tenants, accessToken.TenantId } }
527538
};
528539

src/ResourceManager/Profile/Commands.Profile/Profile/SelectAzureRMProfile.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ public override void ExecuteCmdlet()
5858
throw new ArgumentException(Resources.AzureProfileMustNotBeNull);
5959
}
6060

61+
if (AzureRmProfileProvider.Instance.Profile.Context != null &&
62+
AzureRmProfileProvider.Instance.Profile.Context.Subscription != null &&
63+
AzureRmProfileProvider.Instance.Profile.Context.Subscription.State != null &&
64+
!AzureRmProfileProvider.Instance.Profile.Context.Subscription.State.Equals(
65+
"Enabled",
66+
StringComparison.OrdinalIgnoreCase))
67+
{
68+
WriteWarning(string.Format(
69+
Microsoft.Azure.Commands.Profile.Properties.Resources.SelectedSubscriptionNotActive,
70+
AzureRmProfileProvider.Instance.Profile.Context.Subscription.State));
71+
}
72+
6173
WriteObject((PSAzureProfile)AzureRmProfileProvider.Instance.Profile);
6274
}
6375
}

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
<data name="NoValidTenant" xml:space="preserve">
148148
<value>Please provide a valid tenant Id on the command line or execute Login-AzureRmAccount.</value>
149149
</data>
150+
<data name="SelectedSubscriptionNotActive" xml:space="preserve">
151+
<value>Selected subscription is in '{0}' state. </value>
152+
</data>
150153
<data name="SetAzureRmContextNoParameterSet" xml:space="preserve">
151154
<value>Please provide either a subscription ID, subscription name, tenant Id or domain.</value>
152155
</data>

0 commit comments

Comments
 (0)