Skip to content

Commit aed0221

Browse files
Fixed SoftDeleteRetentionDays computation (#29038)
Co-authored-by: Yash <55773468+notyashhh@users.noreply.github.com>
1 parent 79844eb commit aed0221

3 files changed

Lines changed: 10 additions & 26 deletions

File tree

src/KeyVault/KeyVault/SecurityDomain/Models/CertKey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void Load(KeyPath path)
4949
public RSA GetKey() { return _key; }
5050
public X509Certificate2 GetCert() { return _cert; }
5151

52-
static RSAParameters RsaParamsFromPem(string path, string password) //CodeQL [SM02205] BouncyCastle is the only API available because we need to be at netstandard2.0
52+
static RSAParameters RsaParamsFromPem(string path, string password) // CodeQL [SM02205] BouncyCastle is the only API available because we need to be at netstandard2.0
5353
{
5454
using (var stream = File.OpenText(path))
5555
{

src/Sql/Sql/Server/Cmdlet/AzureSqlServerCmdletBase.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,16 @@ protected void ValidateSoftDeleteParameters(int? softDeleteRetentionDays, bool?
7272
/// </summary>
7373
/// <param name="softDeleteRetentionDays">The explicitly provided retention days</param>
7474
/// <param name="enableSoftDelete">The enable soft delete flag</param>
75-
/// <param name="existingValue">The existing retention days value (for Set operations)</param>
7675
/// <returns>The computed retention days value</returns>
77-
protected int? ComputeSoftDeleteRetentionDays(int? softDeleteRetentionDays, bool? enableSoftDelete, int? existingValue = null)
76+
protected int? ComputeSoftDeleteRetentionDays(int? softDeleteRetentionDays, bool? enableSoftDelete)
7877
{
7978
if (softDeleteRetentionDays.HasValue)
80-
{
81-
// SoftDeleteRetentionDays was explicitly provided, use it
8279
return softDeleteRetentionDays.Value;
83-
}
84-
else if (enableSoftDelete.HasValue)
85-
{
86-
// Only EnableSoftDelete was provided
87-
if (enableSoftDelete == true)
88-
{
89-
// Enabling soft-delete without specifying days, default to 7
90-
return SoftDeleteRetentionDaysMaximum;
91-
}
92-
else
93-
{
94-
// Disabling soft-delete, set to 0
95-
return SoftDeleteRetentionDaysDisabled;
96-
}
97-
}
98-
else
99-
{
100-
// Neither parameter specified, return existing value or null
101-
return existingValue;
102-
}
80+
81+
if (enableSoftDelete.HasValue)
82+
return enableSoftDelete.Value ? SoftDeleteRetentionDaysMaximum : SoftDeleteRetentionDaysDisabled;
83+
84+
return null;
10385
}
10486
}
10587
}

src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ public override void ExecuteCmdlet()
195195
updateData[0].PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId;
196196
updateData[0].KeyId = this.KeyId ?? updateData[0].KeyId;
197197
updateData[0].FederatedClientId = this.FederatedClientId ?? updateData[0].FederatedClientId;
198-
updateData[0].SoftDeleteRetentionDays = ComputeSoftDeleteRetentionDays(this.SoftDeleteRetentionDays, this.EnableSoftDelete, updateData[0].SoftDeleteRetentionDays);
198+
// Compute SoftDeleteRetentionDays from user input or null to preserve existing value.
199+
// Don't pass existing value back since API returns 0 for both null and explicitly disabled.
200+
updateData[0].SoftDeleteRetentionDays = ComputeSoftDeleteRetentionDays(this.SoftDeleteRetentionDays, this.EnableSoftDelete);
199201

200202
return updateData;
201203
}

0 commit comments

Comments
 (0)