Skip to content

Commit 07592f4

Browse files
OlegSternbergIBMOleg Sternbergisra-fel
authored
[Audit policy] Set-AzSqlDatabaseAudit - support Hyperscale database (#13290)
* Fix in Set-AzSqlDatabaseAudit - support Hyperscale database Show descriptive error when database edition cannot be determined * Update ChangeLog.md * Fix ChangeLog.md * Update changelog... ...move the changelog to the to of "upcoming release" to prevent merging issue in next sprint * Fix ChangeLog.md Co-authored-by: Oleg Sternberg <[email protected]> Co-authored-by: Yeming Liu <[email protected]>
1 parent 7b74eef commit 07592f4

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

src/Sql/Sql/Auditing/Services/SqlAuditAdapter.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2222
using System;
2323
using System.Collections.Generic;
24+
using System.Globalization;
2425
using System.Linq;
2526

2627
namespace Microsoft.Azure.Commands.Sql.Auditing.Services
@@ -257,10 +258,7 @@ private static void DetermineTargetsState(
257258

258259
private bool SetAudit(DatabaseAuditModel model)
259260
{
260-
if (!IsDatabaseInServiceTierForPolicy(model.ResourceGroupName, model.ServerName, model.DatabaseName))
261-
{
262-
throw new Exception(Properties.Resources.DatabaseNotInServiceTierForAuditingPolicy);
263-
}
261+
ValidateDatabaseInServiceTierForPolicy(model.ResourceGroupName, model.ServerName, model.DatabaseName);
264262

265263
if (string.IsNullOrEmpty(model.PredicateExpression))
266264
{
@@ -394,13 +392,21 @@ internal bool RemoveFirstDiagnosticSettings(dynamic model)
394392
return true;
395393
}
396394

397-
private bool IsDatabaseInServiceTierForPolicy(string resourceGroupName, string serverName, string databaseName)
395+
private void ValidateDatabaseInServiceTierForPolicy(string resourceGroupName, string serverName, string databaseName)
398396
{
399397
var dbCommunicator = new AzureSqlDatabaseCommunicator(Context);
400398
var database = dbCommunicator.Get(resourceGroupName, serverName, databaseName);
401-
Enum.TryParse(database.Edition, true, out Database.Model.DatabaseEdition edition);
402-
return edition != Database.Model.DatabaseEdition.None &&
403-
edition != Database.Model.DatabaseEdition.Free;
399+
400+
if (!Enum.TryParse(database.Edition, true, out Database.Model.DatabaseEdition edition))
401+
{
402+
throw new Exception(string.Format(CultureInfo.InvariantCulture,
403+
Properties.Resources.UnsupportedDatabaseEditionForAuditingPolicy, database.Edition));
404+
}
405+
406+
if (edition == Database.Model.DatabaseEdition.None || edition == Database.Model.DatabaseEdition.Free)
407+
{
408+
throw new Exception(Properties.Resources.DatabaseNotInServiceTierForAuditingPolicy);
409+
}
404410
}
405411

406412
private void PolicizeAuditModel(ServerAuditModel model, dynamic policy)

src/Sql/Sql/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed issues where Set-AzSqlDatabaseAudit were not support Hyperscale database and database edition cannot be determined
2122
* Added DiffBackupIntervalInHours to `Set-AzSqlDatabaseBackupShortTermRetentionPolicy`
2223
* Fixed issue where New-AzSqlDatabaseExport fails if networkIsolation not specified [#13097]
2324
* Fixed issue where New-AzSqlDatabaseExport and New-AzSqlDatabaseImport were not returning OperationStatusLink in the result object [#13097]
24-
* Update Azure Paired Regions URL in Backup Storage Redundancy Warnings
25+
* Update Azure Paired Regions URL in Backup Storage Redundancy Warnings
2526

2627
## Version 2.11.0
2728
* Added BackupStorageRedundancy to the following:

src/Sql/Sql/Database/Model/DatabaseEdition.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public enum DatabaseEdition
6868
/// Business Critical edition for SqlAzure database
6969
/// </summary>
7070
BusinessCritical = 11,
71+
72+
/// <summary>
73+
/// Hyperscale edition for SqlAzure database
74+
/// </summary>
75+
Hyperscale = 12
7176
}
7277
}
7378

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,4 +652,7 @@
652652
<data name="BackupRedundancyNotChosenTakeSourceWarning" xml:space="preserve">
653653
<value>You have not specified the value for backup storage redundancy which will default to the source's backup storage redundancy. To learn more about Azure Paired Regions visit aka.ms/azure-ragrs-regions.</value>
654654
</data>
655+
<data name="UnsupportedDatabaseEditionForAuditingPolicy" xml:space="preserve">
656+
<value>Auditing policy cannot be defined for database edition {0}</value>
657+
</data>
655658
</root>

0 commit comments

Comments
 (0)