Skip to content

Commit 9a27595

Browse files
authored
Merge pull request #7710 from cormacpayne/new-sp-cred-fix
Fix issue where EndDate parameter was not being honored for AD cmdlets
2 parents 5b23f0a + dcea2ff commit 9a27595

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADAppCredentialCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public override void ExecuteCmdlet()
8787
{
8888
if (!this.IsParameterBound(c => c.EndDate))
8989
{
90-
WriteVerbose("No value specified for -EndDate parameter; setting the value to one year after start date.");
90+
WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed);
9191
EndDate = StartDate.AddYears(1);
9292
}
9393

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADApplicationCommand.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
1616
using Microsoft.WindowsAzure.Commands.Common;
17+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1718
using System;
1819
using System.Management.Automation;
1920
using System.Security;
@@ -124,11 +125,16 @@ public NewAzureADApplicationCommand()
124125
{
125126
DateTime currentTime = DateTime.UtcNow;
126127
StartDate = currentTime;
127-
EndDate = currentTime.AddYears(1);
128128
}
129129

130130
public override void ExecuteCmdlet()
131131
{
132+
if (!this.IsParameterBound(c => c.EndDate))
133+
{
134+
WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed);
135+
EndDate = StartDate.AddYears(1);
136+
}
137+
132138
CreatePSApplicationParameters createParameters = new CreatePSApplicationParameters
133139
{
134140
DisplayName = DisplayName,
@@ -137,7 +143,7 @@ public override void ExecuteCmdlet()
137143
ReplyUrls = ReplyUrls,
138144
AvailableToOtherTenants = AvailableToOtherTenants
139145
};
140-
146+
141147
switch (ParameterSetName)
142148
{
143149
case ParameterSet.ApplicationWithPasswordPlain:

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADServicePrincipalCommand.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ public NewAzureADServicePrincipalCommand()
177177
{
178178
DateTime currentTime = DateTime.UtcNow;
179179
StartDate = currentTime;
180-
EndDate = currentTime.AddYears(1);
181180
}
182181

183182
public override void ExecuteCmdlet()
@@ -190,6 +189,12 @@ public override void ExecuteCmdlet()
190189
return;
191190
}
192191

192+
if (!this.IsParameterBound(c => c.EndDate))
193+
{
194+
WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed);
195+
EndDate = StartDate.AddYears(1);
196+
}
197+
193198
if (this.IsParameterBound(c => c.ApplicationObject))
194199
{
195200
ApplicationId = ApplicationObject.ApplicationId;
@@ -292,7 +297,7 @@ private void CreateSimpleServicePrincipal()
292297
if (!this.IsParameterBound(c => c.EndDate))
293298
{
294299
EndDate = StartDate.AddYears(1);
295-
WriteVerbose("No end date provided - using the default value of one year after the start date.");
300+
WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed);
296301
}
297302

298303
if (!this.IsParameterBound(c => c.DisplayName))

src/ResourceManager/Resources/Commands.Resources/ActiveDirectory/NewAzureADSpCredentialCommand.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ public override void ExecuteCmdlet()
8080
{
8181
ExecutionBlock(() =>
8282
{
83-
EndDate = StartDate.AddYears(1);
83+
if (!this.IsParameterBound(c => c.EndDate))
84+
{
85+
WriteVerbose(Resources.Properties.Resources.DefaultEndDateUsed);
86+
EndDate = StartDate.AddYears(1);
87+
}
88+
8489
if (this.IsParameterBound(c => c.ServicePrincipalObject))
8590
{
8691
ObjectId = ServicePrincipalObject.Id;

src/ResourceManager/Resources/Commands.Resources/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
## Current Release
2121
* Fix for https://github.com/Azure/azure-powershell/issues/7402
2222
- Allow listing resources using the `-ResourceId` parameter for `Get-AzureRmResource`
23+
* Fix for https://github.com/Azure/azure-powershell/issues/7700
24+
- Fix issue where `EndDate` parameter was not being honored for AD cmdlets
2325

2426
## Version 6.7.0
2527
* 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`.

src/ResourceManager/Resources/Commands.Resources/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/Resources/Commands.Resources/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,4 +417,7 @@
417417
<data name="ApplicationWithDisplayNameDoesntExist" xml:space="preserve">
418418
<value>Application with display name '{0}' does not exist.</value>
419419
</data>
420+
<data name="DefaultEndDateUsed" xml:space="preserve">
421+
<value>No value specified for -EndDate parameter; setting the value to one year after start date.</value>
422+
</data>
420423
</root>

0 commit comments

Comments
 (0)