Skip to content

Commit ef00783

Browse files
committed
Revert "Added new Server threat detection support"
This reverts commit 647e298.
1 parent 489cb2e commit ef00783

12 files changed

+48
-473
lines changed

src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@
5151
<Prefer32Bit>false</Prefer32Bit>
5252
</PropertyGroup>
5353
<ItemGroup>
54-
<Compile Include="ThreatDetection\Cmdlet\UseAzureSqlServerThreatDetectionPolicy.cs" />
55-
<Compile Include="ThreatDetection\Cmdlet\GetAzureSqlServerThreatDetection.cs" />
56-
<Compile Include="ThreatDetection\Cmdlet\RemoveSqlServerThreatDetection.cs" />
57-
<Compile Include="ThreatDetection\Cmdlet\SetAzureSqlServerThreatDetection.cs" />
58-
<Compile Include="ThreatDetection\Cmdlet\SqlServerThreatDetectionCmdletBase.cs" />
59-
<Compile Include="ThreatDetection\Model\ServerThreatDetectionPolicyModel.cs" />
6054
<Compile Include="ThreatDetection\Cmdlet\SqlDatabaseThreatDetectionCmdletBase.cs" />
6155
<Compile Include="ThreatDetection\Cmdlet\GetAzureSqlDatabaseThreatDetection.cs" />
6256
<Compile Include="ThreatDetection\Cmdlet\SetAzureSqlDatabaseThreatDetection.cs" />
@@ -101,7 +95,7 @@
10195
<Compile Include="Auditing\Cmdlet\UseAzureSqlServerAuditingPolicy.cs" />
10296
<Compile Include="Auditing\Model\BaseAuditingPolicyModel.cs" />
10397
<Compile Include="ThreatDetection\Model\BaseThreatDetectionPolicyModel.cs" />
104-
<Compile Include="ThreatDetection\Model\DatabaseThreatDetectionPolicyModel.cs" />
98+
<Compile Include="ThreatDetection\Model\DatabaseThreatDetectionPolicyModel .cs" />
10599
<Compile Include="Auditing\Model\DatabaseAuditingPolicyModel.cs" />
106100
<Compile Include="Auditing\Model\ServerAuditingPolicyModel.cs" />
107101
<Compile Include="Auditing\Services\AuditingEndpointsCommunicator.cs" />

src/ResourceManager/Sql/Commands.Sql/ThreatDetection/Cmdlet/GetAzureSqlServerThreatDetection.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/ResourceManager/Sql/Commands.Sql/ThreatDetection/Cmdlet/RemoveSqlServerThreatDetection.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/ResourceManager/Sql/Commands.Sql/ThreatDetection/Cmdlet/SetAzureSqlDatabaseThreatDetection.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ protected override DatabaseThreatDetectionPolicyModel ApplyUserInputToModel(Data
6868
base.ApplyUserInputToModel(model);
6969

7070
model.ThreatDetectionState = ThreatDetectionStateType.Enabled;
71-
model.UseServerDefault = UseServerDefaultOptions.Disabled;
7271

7372
if (NotificationRecipientsEmails != null)
7473
{
@@ -85,9 +84,50 @@ protected override DatabaseThreatDetectionPolicyModel ApplyUserInputToModel(Data
8584
model.ExcludedDetectionTypes = ExcludedDetectionType.Select(s => SecurityConstants.ExcludedDetectionToExcludedDetectionTypes[s]).ToArray();
8685
}
8786

88-
model.ValidateInput();
87+
ValidateInput(model);
8988

9089
return model;
9190
}
91+
92+
/// <summary>
93+
/// Preforms validity checks
94+
/// </summary>
95+
/// <param name="model">The model</param>
96+
private void ValidateInput(DatabaseThreatDetectionPolicyModel model)
97+
{
98+
// Validity checks:
99+
// 1. Check that EmailAddresses are in correct format
100+
bool areEmailAddressesInCorrectFormat = AreEmailAddressesInCorrectFormat(model.NotificationRecipientsEmails);
101+
if (!areEmailAddressesInCorrectFormat)
102+
{
103+
throw new Exception(Properties.Resources.EmailsAreNotValid);
104+
}
105+
106+
// 2. check that EmailAdmins is not False and NotificationRecipientsEmails is not empty
107+
if (!model.EmailAdmins && string.IsNullOrEmpty(model.NotificationRecipientsEmails))
108+
{
109+
throw new Exception(Properties.Resources.NeedToProvideEmail);
110+
}
111+
}
112+
113+
/// <summary>
114+
/// Checks if email addresses are in a correct format
115+
/// </summary>
116+
/// <param name="emailAddresses">The email addresses</param>
117+
/// <returns>Returns whether the email addresses are in a correct format</returns>
118+
private bool AreEmailAddressesInCorrectFormat(string emailAddresses)
119+
{
120+
if (string.IsNullOrEmpty(emailAddresses))
121+
{
122+
return true;
123+
}
124+
125+
string[] emailAddressesArray = emailAddresses.Split(';').Where(s => !string.IsNullOrEmpty(s)).ToArray();
126+
var emailRegex =
127+
new Regex(string.Format("{0}{1}",
128+
@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))",
129+
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$"));
130+
return !emailAddressesArray.Any(e => !emailRegex.IsMatch(e));
131+
}
92132
}
93133
}

src/ResourceManager/Sql/Commands.Sql/ThreatDetection/Cmdlet/SetAzureSqlServerThreatDetection.cs

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/ResourceManager/Sql/Commands.Sql/ThreatDetection/Cmdlet/SqlServerThreatDetectionCmdletBase.cs

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/ResourceManager/Sql/Commands.Sql/ThreatDetection/Cmdlet/UseAzureSqlServerThreatDetectionPolicy.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)