Skip to content

[#111161894] Added warning if the selected Subscription is not in the Enabled state (PastDue feature) #1722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Common/Commands.Common/ProfileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ private AzureSubscription MergeSubscriptionProperties(AzureSubscription subscrip
Id = subscription1.Id,
Name = subscription1.Name,
Environment = subscription1.Environment,
State = (subscription1.State != null &&
subscription1.State.Equals(subscription2.State, StringComparison.OrdinalIgnoreCase)) ?
subscription1.State: null,
Account = subscription1.Account ?? subscription2.Account
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.Azure.Commands.Profile.Properties;
using System;

namespace Microsoft.Azure.Commands.Profile
{
Expand Down Expand Up @@ -78,6 +79,18 @@ public override void ExecuteCmdlet()
profileClient.SetCurrentContext(TenantId);
}
}

if (AzureRmProfileProvider.Instance.Profile.Context != null &&
AzureRmProfileProvider.Instance.Profile.Context.Subscription != null &&
AzureRmProfileProvider.Instance.Profile.Context.Subscription.State != null &&
!AzureRmProfileProvider.Instance.Profile.Context.Subscription.State.Equals(
"Enabled",
StringComparison.OrdinalIgnoreCase))
{
WriteWarning(string.Format(
Microsoft.Azure.Commands.Profile.Properties.Resources.SelectedSubscriptionNotActive,
AzureRmProfileProvider.Instance.Profile.Context.Subscription.State));
}
WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
<ListItem>
<PropertyName>TenantId</PropertyName>
</ListItem>
<ListItem>
<PropertyName>State</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal static AzureSubscription ToAzureSubscription(this Subscription other, A
subscription.Environment = context.Environment != null ? context.Environment.Name : EnvironmentName.AzureCloud;
subscription.Id = new Guid(other.SubscriptionId);
subscription.Name = other.DisplayName;
subscription.State = other.State;
subscription.SetProperty(AzureSubscription.Property.Tenants,
context.Tenant.Id.ToString());
return subscription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static implicit operator PSAzureSubscription(AzureSubscription other)
var subscription= new PSAzureSubscription
{
SubscriptionId = other.Id.ToString(),
SubscriptionName = other.Name ,
SubscriptionName = other.Name,
State = other.State,
TenantId = other.IsPropertySet(AzureSubscription.Property.Tenants)?
other.GetProperty(AzureSubscription.Property.Tenants) : null
};
Expand Down Expand Up @@ -89,6 +90,11 @@ public static implicit operator AzureSubscription(PSAzureSubscription other)
result.Properties.SetProperty(AzureSubscription.Property.StorageAccount, other.CurrentStorageAccount);
}

if (other.State != null)
{
result.State = other.State;
}

return result;
}

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

/// <summary>
/// Gets or sets subscription State
/// </summary>
public string State { get; set; }

/// <summary>
/// The tenant home for the subscription.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public AzureRMProfile Login(
else
{
_profile.Context = new AzureContext(newSubscription, account, environment, newTenant);
if (!newSubscription.State.Equals("Enabled", StringComparison.OrdinalIgnoreCase))
{
WriteWarningMessage(string.Format(
Microsoft.Azure.Commands.Profile.Properties.Resources.SelectedSubscriptionNotActive,
newSubscription.State));
}
}

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

var newSubscription = new AzureSubscription { Id = subscription.Id };
var newSubscription = new AzureSubscription
{
Id = subscription.Id,
State = subscription.State
};
if (_profile.Context.Subscription != null)
{
newSubscription.Account = _profile.Context.Subscription.Account;
Expand Down Expand Up @@ -523,6 +533,7 @@ private bool TryGetTenantSubscription(IAccessToken accessToken,
Account = accessToken.UserId,
Environment = environment.Name,
Name = subscriptionFromServer.DisplayName,
State = subscriptionFromServer.State,
Properties = new Dictionary<AzureSubscription.Property, string> { { AzureSubscription.Property.Tenants, accessToken.TenantId } }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public override void ExecuteCmdlet()
throw new ArgumentException(Resources.AzureProfileMustNotBeNull);
}

if (AzureRmProfileProvider.Instance.Profile.Context != null &&
AzureRmProfileProvider.Instance.Profile.Context.Subscription != null &&
AzureRmProfileProvider.Instance.Profile.Context.Subscription.State != null &&
!AzureRmProfileProvider.Instance.Profile.Context.Subscription.State.Equals(
"Enabled",
StringComparison.OrdinalIgnoreCase))
{
WriteWarning(string.Format(
Microsoft.Azure.Commands.Profile.Properties.Resources.SelectedSubscriptionNotActive,
AzureRmProfileProvider.Instance.Profile.Context.Subscription.State));
}

WriteObject((PSAzureProfile)AzureRmProfileProvider.Instance.Profile);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
<data name="NoValidTenant" xml:space="preserve">
<value>Please provide a valid tenant Id on the command line or execute Login-AzureRmAccount.</value>
</data>
<data name="SelectedSubscriptionNotActive" xml:space="preserve">
<value>Selected subscription is in '{0}' state. </value>
</data>
<data name="SetAzureRmContextNoParameterSet" xml:space="preserve">
<value>Please provide either a subscription ID, subscription name, tenant Id or domain.</value>
</data>
Expand Down