From 7b74f752246477d4f2fcacd0f8b07091f16c0579 Mon Sep 17 00:00:00 2001 From: cormacpayne Date: Tue, 30 Oct 2018 17:21:31 -0700 Subject: [PATCH 1/3] Fix issue with EndDate for AD cmdlets not preserving value --- .../ActiveDirectory/NewAzureADApplicationCommand.cs | 10 ++++++++-- .../NewAzureADServicePrincipalCommand.cs | 7 ++++++- .../ActiveDirectory/NewAzureADSpCredentialCommand.cs | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs index d62ae4a6c88a..9f717ded1aa2 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs @@ -14,6 +14,7 @@ using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory; using Microsoft.WindowsAzure.Commands.Common; +using Microsoft.WindowsAzure.Commands.Utilities.Common; using System; using System.Management.Automation; using System.Security; @@ -124,11 +125,16 @@ public NewAzureADApplicationCommand() { DateTime currentTime = DateTime.UtcNow; StartDate = currentTime; - EndDate = currentTime.AddYears(1); } public override void ExecuteCmdlet() { + if (!this.IsParameterBound(c => c.EndDate)) + { + WriteVerbose("No value specified for -EndDate parameter; setting the value to one year after start date."); + EndDate = StartDate.AddYears(1); + } + CreatePSApplicationParameters createParameters = new CreatePSApplicationParameters { DisplayName = DisplayName, @@ -137,7 +143,7 @@ public override void ExecuteCmdlet() ReplyUrls = ReplyUrls, AvailableToOtherTenants = AvailableToOtherTenants }; - + switch (ParameterSetName) { case ParameterSet.ApplicationWithPasswordPlain: diff --git a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs index 03cee18a4739..ebc7d4912545 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs @@ -177,7 +177,6 @@ public NewAzureADServicePrincipalCommand() { DateTime currentTime = DateTime.UtcNow; StartDate = currentTime; - EndDate = currentTime.AddYears(1); } public override void ExecuteCmdlet() @@ -190,6 +189,12 @@ public override void ExecuteCmdlet() return; } + if (!this.IsParameterBound(c => c.EndDate)) + { + WriteVerbose("No value specified for -EndDate parameter; setting the value to one year after start date."); + EndDate = StartDate.AddYears(1); + } + if (this.IsParameterBound(c => c.ApplicationObject)) { ApplicationId = ApplicationObject.ApplicationId; diff --git a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs index 4a08ab770e2d..041cf8b8f52a 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs @@ -80,7 +80,12 @@ public override void ExecuteCmdlet() { ExecutionBlock(() => { - EndDate = StartDate.AddYears(1); + if (!this.IsParameterBound(c => c.EndDate)) + { + WriteVerbose("No value specified for -EndDate parameter; setting the value to one year after start date."); + EndDate = StartDate.AddYears(1); + } + if (this.IsParameterBound(c => c.ServicePrincipalObject)) { ObjectId = ServicePrincipalObject.Id; From 992ade94d509076e87aa237988847b3597c0c8ba Mon Sep 17 00:00:00 2001 From: cormacpayne Date: Tue, 30 Oct 2018 17:33:49 -0700 Subject: [PATCH 2/3] Update Resources change log --- src/ResourceManager/Resources/Commands.Resources/ChangeLog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ResourceManager/Resources/Commands.Resources/ChangeLog.md b/src/ResourceManager/Resources/Commands.Resources/ChangeLog.md index c6f2a15cf7a5..34581d6a8d8c 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ChangeLog.md +++ b/src/ResourceManager/Resources/Commands.Resources/ChangeLog.md @@ -20,6 +20,8 @@ ## Current Release * Fix for https://github.com/Azure/azure-powershell/issues/7402 - Allow listing resources using the `-ResourceId` parameter for `Get-AzureRmResource` +* Fix for https://github.com/Azure/azure-powershell/issues/7700 + - Fix issue where `EndDate` parameter was not being honored for AD cmdlets ## Version 6.7.0 * Fix isssue where Get-AzureRMRoleDefinition throws an unintelligible exception (when the default profile has no subscription in it and no scope is specified) by adding a meaningful exception in the scenario. Also set the default param set to `RoleDefinitionNameParameterSet`. From dcea2ff5274e02801642b3d0c7c34da6c38f87d2 Mon Sep 17 00:00:00 2001 From: cormacpayne Date: Wed, 31 Oct 2018 12:40:55 -0700 Subject: [PATCH 3/3] Resolve review feedback (without tests) --- .../ActiveDirectory/NewAzureADAppCredentialCommand.cs | 2 +- .../ActiveDirectory/NewAzureADApplicationCommand.cs | 2 +- .../ActiveDirectory/NewAzureADServicePrincipalCommand.cs | 4 ++-- .../ActiveDirectory/NewAzureADSpCredentialCommand.cs | 2 +- .../Commands.Resources/Properties/Resources.Designer.cs | 9 +++++++++ .../Commands.Resources/Properties/Resources.resx | 3 +++ 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADAppCredentialCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADAppCredentialCommand.cs index 58f4edb4908f..d78923594d4c 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADAppCredentialCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADAppCredentialCommand.cs @@ -87,7 +87,7 @@ public override void ExecuteCmdlet() { if (!this.IsParameterBound(c => c.EndDate)) { - WriteVerbose("No value specified for -EndDate parameter; setting the value to one year after start date."); + WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed); EndDate = StartDate.AddYears(1); } diff --git a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs index 9f717ded1aa2..ebe8899c5405 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs @@ -131,7 +131,7 @@ public override void ExecuteCmdlet() { if (!this.IsParameterBound(c => c.EndDate)) { - WriteVerbose("No value specified for -EndDate parameter; setting the value to one year after start date."); + WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed); EndDate = StartDate.AddYears(1); } diff --git a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs index ebc7d4912545..b328f211492f 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs @@ -191,7 +191,7 @@ public override void ExecuteCmdlet() if (!this.IsParameterBound(c => c.EndDate)) { - WriteVerbose("No value specified for -EndDate parameter; setting the value to one year after start date."); + WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed); EndDate = StartDate.AddYears(1); } @@ -297,7 +297,7 @@ private void CreateSimpleServicePrincipal() if (!this.IsParameterBound(c => c.EndDate)) { EndDate = StartDate.AddYears(1); - WriteVerbose("No end date provided - using the default value of one year after the start date."); + WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed); } if (!this.IsParameterBound(c => c.DisplayName)) diff --git a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs index 041cf8b8f52a..1cf5228726be 100644 --- a/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs +++ b/src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs @@ -82,7 +82,7 @@ public override void ExecuteCmdlet() { if (!this.IsParameterBound(c => c.EndDate)) { - WriteVerbose("No value specified for -EndDate parameter; setting the value to one year after start date."); + WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed); EndDate = StartDate.AddYears(1); } diff --git a/src/ResourceManager/Resources/Commands.Resources/Properties/Resources.Designer.cs b/src/ResourceManager/Resources/Commands.Resources/Properties/Resources.Designer.cs index b4af28175e95..b4b50dc02959 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Resources/Commands.Resources/Properties/Resources.Designer.cs @@ -123,6 +123,15 @@ internal static string CreateServicePrincipalNotAllowedGuestUser { } } + /// + /// Looks up a localized string similar to No value specified for -EndDate parameter; setting the value to one year after start date.. + /// + internal static string DefaultEndDateUsed { + get { + return ResourceManager.GetString("DefaultEndDateUsed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Deleting the deployment .... /// diff --git a/src/ResourceManager/Resources/Commands.Resources/Properties/Resources.resx b/src/ResourceManager/Resources/Commands.Resources/Properties/Resources.resx index a8e6be8c068a..f2f09a8fa4d7 100644 --- a/src/ResourceManager/Resources/Commands.Resources/Properties/Resources.resx +++ b/src/ResourceManager/Resources/Commands.Resources/Properties/Resources.resx @@ -417,4 +417,7 @@ Application with display name '{0}' does not exist. + + No value specified for -EndDate parameter; setting the value to one year after start date. + \ No newline at end of file