Skip to content

Commit bdc66f7

Browse files
committed
Updated docs and fixed comments
1 parent caf31a9 commit bdc66f7

File tree

11 files changed

+228
-143
lines changed

11 files changed

+228
-143
lines changed

src/Sql/Sql/ChangeLog.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21-
* Updated `New-AzSqlInstance` to support retention
22-
- Added `EnableSoftDeleteRetention` parameter to `New-AzSqlInstance` to enable the creation of instances with retention period enabled
23-
- Added `SoftDeleteRetentionInDays` parameter to `New-AzSqlInstance` to enable the creation of instances with custom retention period
24-
* Updated `Set-AzSqlInstance` to support retention
25-
- Added `EnableSoftDeleteRetention` parameter to `Set-AzSqlInstance` to enable/disable retention period on existing instances
26-
- Added `SoftDeleteRetentionInDays` parameter to `Set-AzSqlInstance` to enable the update of retention period on existing instances
27-
* Added `Restore-AzSqlServer` cmdlet to restore a deleted Azure Sql servers within the retention period
21+
* Updated `New-AzSqlServer` to support soft-delete retention
22+
- Added `EnableSoftDeleteRetention` parameter to `New-AzSqlServer` to enable creation of a server with soft-delete retention
23+
- Added `SoftDeleteRetentionDays` parameter to `New-AzSqlServer` to set the soft-delete retention period (in days)
24+
* Updated `Set-AzSqlServer` to support soft-delete retention
25+
- Added `EnableSoftDeleteRetention` parameter to `Set-AzSqlServer` to enable or disable soft-delete retention on an existing server
26+
- Added `SoftDeleteRetentionDays` parameter to `Set-AzSqlServer` to update the soft-delete retention period (in days) on an existing server
27+
* Added `Restore-AzSqlServer` cmdlet to restore a deleted Azure SQL server within the retention period
2828

2929
## Version 6.1.0
3030
* Fixed `New-AzSqlDatabaseExport` and `New-AzSqlDatabaseImport` to use SQL Authentication with ManagedIdentity without any mandatory password

src/Sql/Sql/Properties/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Sql/Sql/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@
670670
<data name="MissingSQLAdministratorCredentials" xml:space="preserve">
671671
<value>SQL Administrator Credentials are only optional when Azure Active Directory Only Authentication is enabled via -EnableActiveDirectoryOnlyAuthentication.</value>
672672
</data>
673+
<data name="MissingEnableSoftDeleteRetention" xml:space="preserve">
674+
<value>EnableSoftDeleteRetention must be provided when SoftDeleteRetentionDays is set to a value greater than 0.</value>
675+
</data>
673676
<data name="RemoveAzureSqlServerOutboundFirewallRuleDescription" xml:space="preserve">
674677
<value>Permanently removing allowed FQDN '{0}' from the list of Outbound Firewall Rules (Allowed FQDNs) for Azure Sql Database Server '{1}'.</value>
675678
</data>
@@ -766,4 +769,7 @@
766769
<data name="ForwardMigrationWithGeoDRInfo" xml:space="preserve">
767770
<value>Changing the service tier to Hyperscale also converts the geo-secondary replica to Hyperscale. For more information, see https://go.microsoft.com/fwlink/?linkid=2314103</value>
768771
</data>
772+
<data name="DeletedServerNotFound" xml:space="preserve">
773+
<value>No deleted server named '{0}' found in resource group '{1}' that can be restored.</value>
774+
</data>
769775
</root>

src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,26 +159,20 @@ public class NewAzureSqlServer : AzureSqlServerCmdletBase
159159
public Guid? FederatedClientId { get; set; }
160160

161161
/// <summary>
162-
/// Soft-delete retention days for the server
162+
/// Boolean Value for enabling Soft Delete Retention for server
163163
/// </summary>
164164
[Parameter(Mandatory = false,
165-
HelpMessage = "Specifies whether or not soft-delete retention is enabled for the server.")]
165+
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.")]
166166
public bool EnableSoftDeleteRetention { get; set; } = false;
167167

168168
/// <summary>
169169
/// Soft-delete retention days for the server
170170
/// </summary>
171171
[Parameter(Mandatory = false,
172-
HelpMessage = "Specifies the soft-delete retention days for the server.")]
172+
HelpMessage = "Specifies the number of days to retain a deleted server for possible restoration. Valid values are 0-35. A value of 0 disables soft-delete retention. If EnableSoftDeleteRetention is set without an explicit value, the default retention is 7 days.")]
173+
[ValidateRange(0, 35)]
173174
public int? SoftDeleteRetentionDays { get; set; }
174175

175-
/// <summary>
176-
/// Soft-delete retention days for the server
177-
/// </summary>
178-
[Parameter(Mandatory = false,
179-
HelpMessage = "Specifies the create mode for the server, valid values for this parameter are \"Normal\" and \"Restore\".")]
180-
public string CreateMode { get; set; } = "Normal";
181-
182176
/// <summary>
183177
/// Overriding to add warning message
184178
/// </summary>
@@ -194,6 +188,12 @@ public override void ExecuteCmdlet()
194188
throw new PSArgumentException(Properties.Resources.MissingSQLAdministratorCredentials, "SqlAdministratorCredentials");
195189
}
196190

191+
// SoftDeleteRetentionDays depends on EnableSoftDeleteRetention; if days are provided but soft-delete is not enabled, fail early.
192+
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays > 0 && !this.EnableSoftDeleteRetention)
193+
{
194+
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDeleteRetention, "EnableSoftDeleteRetention");
195+
}
196+
197197
base.ExecuteCmdlet();
198198
}
199199

@@ -260,7 +260,7 @@ public override void ExecuteCmdlet()
260260
Login = this.ExternalAdminName,
261261
Sid = this.ExternalAdminSID
262262
},
263-
RetentionDays = (this.EnableSoftDeleteRetention && !this.SoftDeleteRetentionDays.HasValue) ? 7 : this.SoftDeleteRetentionDays
263+
SoftDeleteRetentionDays = (this.EnableSoftDeleteRetention && !this.SoftDeleteRetentionDays.HasValue) ? 7 : this.SoftDeleteRetentionDays
264264
});
265265
return newEntity;
266266
}

src/Sql/Sql/Server/Cmdlet/RestoreAzureSqlServer.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,6 @@ public class RestoreAzureSqlServer : AzureSqlServerCmdletBase
4949
[ValidateNotNullOrEmpty]
5050
public string Location { get; set; }
5151

52-
/// <summary>
53-
/// Overriding to add warning message
54-
/// </summary>
55-
public override void ExecuteCmdlet()
56-
{
57-
if (this.ServerName == "")
58-
{
59-
throw new PSArgumentException("Missing ServerName");
60-
}
61-
62-
base.ExecuteCmdlet();
63-
}
64-
6552
/// <summary>
6653
/// Check to see if the server already exists as a live server or if there's a deleted server to restore.
6754
/// </summary>
@@ -85,7 +72,7 @@ public override void ExecuteCmdlet()
8572
}
8673
catch (CloudException ex)
8774
{
88-
if (ex.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
75+
if (ex.Response?.StatusCode != System.Net.HttpStatusCode.NotFound)
8976
{
9077
// Unexpected exception encountered
9178
throw;
@@ -99,21 +86,21 @@ public override void ExecuteCmdlet()
9986
var deletedServer = ModelAdapter.GetDeletedServer(this.ResourceGroupName, this.ServerName);
10087
if (deletedServer == null)
10188
{
102-
throw new PSArgumentException(
103-
string.Format("No deleted server named '{0}' found in resource group '{1}' that can be restored.",
104-
this.ServerName, this.ResourceGroupName),
105-
"ServerName");
89+
throw new PSArgumentException(
90+
string.Format(Properties.Resources.DeletedServerNotFound,
91+
this.ServerName, this.ResourceGroupName),
92+
"ServerName");
10693
}
10794

10895
// Deleted server exists and can be restored
10996
return null;
11097
}
11198
catch (CloudException ex)
11299
{
113-
if (ex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
100+
if (ex.Response?.StatusCode == System.Net.HttpStatusCode.NotFound)
114101
{
115102
throw new PSArgumentException(
116-
string.Format("No deleted server named '{0}' found in resource group '{1}' that can be restored.",
103+
string.Format(Properties.Resources.DeletedServerNotFound,
117104
this.ServerName, this.ResourceGroupName),
118105
"ServerName");
119106
}

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,40 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
126126
public string IdentityType { get; set; }
127127

128128
/// <summary>
129-
/// Value for soft-delete retention days for the server.
129+
/// Boolean for enabling Soft Delete Retention for server
130130
/// </summary>
131131
[Parameter(Mandatory = false,
132-
HelpMessage = "Boolean value for whether or not to enable soft-delete for the server such that the server can be restored for a default of 7 days after dropping. If you want to specify a different retention period, use the RetentionDays parameter.")]
132+
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.")]
133133
[PSArgumentCompleter("true", "false")]
134134
public bool EnableSoftDeleteRetention { get; set; } = false;
135135

136136
/// <summary>
137137
/// Value for soft-delete retention days for the server.
138138
/// </summary>
139139
[Parameter(Mandatory = false,
140-
HelpMessage = "Value for soft-delete retention days for the server such that the server can be restored for the specified number of days after dropping. Only valid values are from 0 to 35. If set to 0, soft-delete retention is disabled.")]
141-
[PSArgumentCompleter("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35")]
142-
public int? RetentionDays { get; set; }
140+
HelpMessage = "Specifies the number of days to retain a deleted server for possible restoration. Valid values are 0-35. A value of 0 disables soft-delete retention. If EnableSoftDeleteRetention is set without an explicit value, the default retention is 7 days.")]
141+
[ValidateRange(0, 35)]
142+
public int? SoftDeleteRetentionDays { get; set; }
143143

144144
/// <summary>
145145
/// Defines whether it is ok to skip the requesting of rule removal confirmation
146146
/// </summary>
147147
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
148148
public SwitchParameter Force { get; set; }
149149

150+
/// <summary>
151+
/// Overriding to add warning message
152+
/// </summary>
153+
public override void ExecuteCmdlet()
154+
{
155+
// SoftDeleteRetentionDays depends on EnableSoftDeleteRetention; if days are provided but soft-delete is not enabled, fail early.
156+
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays > 0 && !this.EnableSoftDeleteRetention)
157+
{
158+
throw new PSArgumentException(Properties.Resources.MissingEnableSoftDeleteRetention, "EnableSoftDeleteRetention");
159+
}
160+
161+
base.ExecuteCmdlet();
162+
}
150163
/// <summary>
151164
/// Get the server to update
152165
/// </summary>
@@ -185,7 +198,24 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
185198
updateData[0].PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId;
186199
updateData[0].KeyId = this.KeyId ?? updateData[0].KeyId;
187200
updateData[0].FederatedClientId = this.FederatedClientId ?? updateData[0].FederatedClientId;
188-
updateData[0].RetentionDays = this.EnableSoftDeleteRetention ? (this.RetentionDays ?? 7) : (int?)null;
201+
if (this.EnableSoftDeleteRetention)
202+
{
203+
// If enabling soft-delete retention, use the explicitly provided value or default to 7 days if none provided.
204+
updateData[0].SoftDeleteRetentionDays = this.SoftDeleteRetentionDays ?? 7;
205+
}
206+
else
207+
{
208+
// If not enabling, only explicitly set retention to 0 when the caller provided 0.
209+
// Otherwise, leave as null so the service preserves the existing retention setting.
210+
if (this.SoftDeleteRetentionDays.HasValue && this.SoftDeleteRetentionDays.Value == 0)
211+
{
212+
updateData[0].SoftDeleteRetentionDays = 0;
213+
}
214+
else
215+
{
216+
updateData[0].SoftDeleteRetentionDays = null;
217+
}
218+
}
189219

190220
return updateData;
191221
}

src/Sql/Sql/Server/Model/AzureSqlServerModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public class AzureSqlServerModel
112112
/// <summary>
113113
/// Gets or sets a value for the soft-delete retention days for the server
114114
/// </summary>
115-
public int? RetentionDays { get; set; }
115+
public int? SoftDeleteRetentionDays { get; set; }
116116

117117
/// <summary>
118118
/// Sets a value for the create mode for the server

src/Sql/Sql/Server/Services/AzureSqlServerAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public AzureSqlServerModel UpsertServer(AzureSqlServerModel model)
143143
PrimaryUserAssignedIdentityId = model.PrimaryUserAssignedIdentityId,
144144
KeyId = model.KeyId,
145145
FederatedClientId = model.FederatedClientId,
146-
RetentionDays = model.RetentionDays,
146+
RetentionDays = model.SoftDeleteRetentionDays,
147147
CreateMode = model.CreateMode,
148148
});
149149

@@ -195,7 +195,7 @@ private static AzureSqlServerModel CreateServerModelFromResponse(Management.Sql.
195195
server.PrimaryUserAssignedIdentityId = resp.PrimaryUserAssignedIdentityId;
196196
server.KeyId = resp.KeyId;
197197
server.FederatedClientId = resp.FederatedClientId;
198-
server.RetentionDays = resp.RetentionDays;
198+
server.SoftDeleteRetentionDays = resp.RetentionDays;
199199

200200
return server;
201201
}

0 commit comments

Comments
 (0)