-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Improve validation for EnabledSoftDelete and SoftDeleteRetentionDay params #28619
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
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 | ||||
---|---|---|---|---|---|---|
|
@@ -163,7 +163,8 @@ public class NewAzureSqlServer : AzureSqlServerCmdletBase | |||||
/// </summary> | ||||||
[Parameter(Mandatory = false, | ||||||
HelpMessage = "Specify whether to enable soft-delete retention for the server. When enabled, a dropped server can be restored within the retention window (defaults to 7 days if not specified). To set a custom retention period use -SoftDeleteRetentionDays.")] | ||||||
public bool EnableSoftDelete { get; set; } | ||||||
[PSArgumentCompleter("true", "false")] | ||||||
public bool? EnableSoftDelete { get; set; } | ||||||
|
||||||
/// <summary> | ||||||
/// Soft-delete retention days for the server | ||||||
|
@@ -188,18 +189,27 @@ public override void ExecuteCmdlet() | |||||
throw new PSArgumentException(Properties.Resources.MissingSQLAdministratorCredentials, "SqlAdministratorCredentials"); | ||||||
} | ||||||
|
||||||
// if the user specified a retention days value, then they must also enable soft delete | ||||||
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays > 0 && !this.EnableSoftDelete) | ||||||
if (SoftDeleteRetentionDays.HasValue) | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDelete, "EnableSoftDelete"); | ||||||
} | ||||||
|
||||||
// if the user specified 0 retention days, then they must not enable soft delete | ||||||
if (this.EnableSoftDelete && this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays == 0) | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.InvalidSoftDeleteRetentionDays, "SoftDeleteRetentionDays"); | ||||||
if (EnableSoftDelete == true) | ||||||
{ | ||||||
if (SoftDeleteRetentionDays.Value < 1 || SoftDeleteRetentionDays.Value > 35) | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.InvalidSoftDeleteRetentionDaysRange, "SoftDeleteRetentionDays"); | ||||||
} | ||||||
} | ||||||
else if (EnableSoftDelete == false) | ||||||
{ | ||||||
if (SoftDeleteRetentionDays.Value != 0) | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.InvalidSoftDeleteRetentionDaysForDisablingSoftDelete, "SoftDeleteRetentionDays"); | ||||||
} | ||||||
} | ||||||
else | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDelete, "EnableSoftDelete"); | ||||||
} | ||||||
} | ||||||
|
||||||
base.ExecuteCmdlet(); | ||||||
} | ||||||
|
||||||
|
@@ -244,16 +254,19 @@ public override void ExecuteCmdlet() | |||||
} | ||||||
|
||||||
int? softDeleteRetentionDays; | ||||||
if (this.EnableSoftDelete) | ||||||
if (this.EnableSoftDelete == true) | ||||||
{ | ||||||
// If enabling soft-delete retention, use the explicitly provided value or default to 7 days if none provided. | ||||||
softDeleteRetentionDays = this.SoftDeleteRetentionDays ?? 7; | ||||||
} | ||||||
else if (this.EnableSoftDelete == false) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as in SetAzureSqlServer.cs - use direct boolean comparison instead of explicit comparison to true/false for nullable boolean values.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
{ | ||||||
// If disabling, explicitly set retention to 0. | ||||||
softDeleteRetentionDays = 0; | ||||||
} | ||||||
else | ||||||
{ | ||||||
// If not enabling, only explicitly set retention to 0 when the caller provided 0. | ||||||
// Otherwise, leave as null so the service preserves the existing retention setting. | ||||||
softDeleteRetentionDays = (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays.Value == 0) ? 0 : (int?)null; | ||||||
softDeleteRetentionDays = (int?)null; | ||||||
} | ||||||
|
||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -131,7 +131,7 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase | |||||
[Parameter(Mandatory = false, | ||||||
HelpMessage = "Specify whether to enable soft-delete retention for the server. When enabled, a dropped server can be restored within the retention window (defaults to 7 days if not specified). To set a custom retention period use -SoftDeleteRetentionDays.")] | ||||||
rambabu-yalla marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
[PSArgumentCompleter("true", "false")] | ||||||
public bool EnableSoftDelete { get; set; } | ||||||
public bool? EnableSoftDelete { get; set; } | ||||||
|
||||||
/// <summary> | ||||||
/// Value for soft-delete retention days for the server. | ||||||
|
@@ -152,18 +152,28 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase | |||||
/// </summary> | ||||||
public override void ExecuteCmdlet() | ||||||
{ | ||||||
// if the user specified a retention days value, then they must also enable soft delete | ||||||
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays > 0 && !this.EnableSoftDelete) | ||||||
if (SoftDeleteRetentionDays.HasValue) | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDelete, "EnableSoftDelete"); | ||||||
if (EnableSoftDelete == true) | ||||||
{ | ||||||
if (SoftDeleteRetentionDays.Value < 1 || SoftDeleteRetentionDays.Value > 35) | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.InvalidSoftDeleteRetentionDaysRange, "SoftDeleteRetentionDays"); | ||||||
} | ||||||
} | ||||||
else if (EnableSoftDelete == false) | ||||||
{ | ||||||
if (SoftDeleteRetentionDays.Value != 0) | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.InvalidSoftDeleteRetentionDaysForDisablingSoftDelete, "SoftDeleteRetentionDays"); | ||||||
} | ||||||
} | ||||||
else | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDelete, "EnableSoftDelete"); | ||||||
} | ||||||
} | ||||||
|
||||||
// if the user specified 0 retention days, then they must not enable soft delete | ||||||
if (this.EnableSoftDelete && this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays == 0) | ||||||
{ | ||||||
throw new PSArgumentException(Properties.Resources.InvalidSoftDeleteRetentionDays, "SoftDeleteRetentionDays"); | ||||||
} | ||||||
|
||||||
|
||||||
base.ExecuteCmdlet(); | ||||||
} | ||||||
/// <summary> | ||||||
|
@@ -204,16 +214,20 @@ public override void ExecuteCmdlet() | |||||
updateData[0].PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId; | ||||||
updateData[0].KeyId = this.KeyId ?? updateData[0].KeyId; | ||||||
updateData[0].FederatedClientId = this.FederatedClientId ?? updateData[0].FederatedClientId; | ||||||
if (this.EnableSoftDelete) | ||||||
if (this.EnableSoftDelete == true) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use direct boolean comparison instead of explicit comparison to true. This can be simplified to
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
{ | ||||||
// If enabling soft-delete retention, use the explicitly provided value or default to 7 days if none provided. | ||||||
updateData[0].SoftDeleteRetentionDays = this.SoftDeleteRetentionDays ?? 7; | ||||||
} | ||||||
else if (this.EnableSoftDelete == false) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use direct boolean comparison instead of explicit comparison to false. This can be simplified to
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
{ | ||||||
// if disabling soft-delete retention, set retention to 0 days. | ||||||
updateData[0].SoftDeleteRetentionDays = 0; | ||||||
} | ||||||
else | ||||||
{ | ||||||
// If not enabling, only explicitly set retention to 0 when the caller provided 0. | ||||||
// Otherwise, leave as null so the service preserves the existing retention setting. | ||||||
updateData[0].SoftDeleteRetentionDays = (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays.Value == 0) ? 0 : (int?)null; | ||||||
// If EnableSoftDelete is not specified, retain existing retention value. | ||||||
updateData[0].SoftDeleteRetentionDays = (int?)null; | ||||||
} | ||||||
|
||||||
return updateData; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in SetAzureSqlServer.cs - use direct boolean comparison instead of explicit comparison to true/false for nullable boolean values.
Copilot uses AI. Check for mistakes.