Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/Sql/Sql/Auditing/Services/SqlAuditAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

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

private bool SetAudit(DatabaseAuditModel model)
{
if (!IsDatabaseInServiceTierForPolicy(model.ResourceGroupName, model.ServerName, model.DatabaseName))
{
throw new Exception(Properties.Resources.DatabaseNotInServiceTierForAuditingPolicy);
}
ValidateDatabaseInServiceTierForPolicy(model.ResourceGroupName, model.ServerName, model.DatabaseName);

if (string.IsNullOrEmpty(model.PredicateExpression))
{
Expand Down Expand Up @@ -394,13 +392,21 @@ internal bool RemoveFirstDiagnosticSettings(dynamic model)
return true;
}

private bool IsDatabaseInServiceTierForPolicy(string resourceGroupName, string serverName, string databaseName)
private void ValidateDatabaseInServiceTierForPolicy(string resourceGroupName, string serverName, string databaseName)
{
var dbCommunicator = new AzureSqlDatabaseCommunicator(Context);
var database = dbCommunicator.Get(resourceGroupName, serverName, databaseName);
Enum.TryParse(database.Edition, true, out Database.Model.DatabaseEdition edition);
return edition != Database.Model.DatabaseEdition.None &&
edition != Database.Model.DatabaseEdition.Free;

if (!Enum.TryParse(database.Edition, true, out Database.Model.DatabaseEdition edition))
{
throw new Exception(string.Format(CultureInfo.InvariantCulture,
Properties.Resources.UnsupportedDatabaseEditionForAuditingPolicy, database.Edition));
}

if (edition == Database.Model.DatabaseEdition.None || edition == Database.Model.DatabaseEdition.Free)
{
throw new Exception(Properties.Resources.DatabaseNotInServiceTierForAuditingPolicy);
}
}

private void PolicizeAuditModel(ServerAuditModel model, dynamic policy)
Expand Down
3 changes: 2 additions & 1 deletion src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
- Additional information about change #1
-->
## Upcoming Release
* Fixed issues where Set-AzSqlDatabaseAudit were not support Hyperscale database and database edition cannot be determined
* Added DiffBackupIntervalInHours to `Set-AzSqlDatabaseBackupShortTermRetentionPolicy`
* Fixed issue where New-AzSqlDatabaseExport fails if networkIsolation not specified [#13097]
* Fixed issue where New-AzSqlDatabaseExport and New-AzSqlDatabaseImport were not returning OperationStatusLink in the result object [#13097]
* Update Azure Paired Regions URL in Backup Storage Redundancy Warnings
* Update Azure Paired Regions URL in Backup Storage Redundancy Warnings

## Version 2.11.0
* Added BackupStorageRedundancy to the following:
Expand Down
5 changes: 5 additions & 0 deletions src/Sql/Sql/Database/Model/DatabaseEdition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public enum DatabaseEdition
/// Business Critical edition for SqlAzure database
/// </summary>
BusinessCritical = 11,

/// <summary>
/// Hyperscale edition for SqlAzure database
/// </summary>
Hyperscale = 12
}
}

9 changes: 9 additions & 0 deletions src/Sql/Sql/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Sql/Sql/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,7 @@
<data name="BackupRedundancyNotChosenTakeSourceWarning" xml:space="preserve">
<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>
</data>
<data name="UnsupportedDatabaseEditionForAuditingPolicy" xml:space="preserve">
<value>Auditing policy cannot be defined for database edition {0}</value>
</data>
</root>