Skip to content

Commit 8bfe1e4

Browse files
fix the check if EventType and AuditAction have been populated
fix the check if EventType and AuditAction have been populated
1 parent 8221b0b commit 8bfe1e4

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

src/ResourceManager/Sql/Commands.Sql/Auditing/Cmdlet/RemoveSqlDatabaseAuditing.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,14 @@ protected override AuditingPolicyModel PersistChanges(AuditingPolicyModel model)
6464
ModelAdapter.IgnoreStorage = true;
6565
base.PersistChanges(model);
6666
//if another server auditing policy exists, remove it
67-
Action swapAuditType = () => { AuditType = AuditType == AuditType.Blob ? AuditType.Table : AuditType.Blob; };
68-
swapAuditType();
67+
if (AuditType == AuditType.Blob)
68+
{
69+
AuditType = AuditType.Table;
70+
}
71+
else
72+
{
73+
AuditType = AuditType.Blob;
74+
}
6975
var otherAuditingTypePolicyModel = GetEntity();
7076
if (otherAuditingTypePolicyModel != null)
7177
{

src/ResourceManager/Sql/Commands.Sql/Auditing/Cmdlet/RemoveSqlServerAuditing.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ protected override AuditingPolicyModel PersistChanges(AuditingPolicyModel model)
5858
ModelAdapter.IgnoreStorage = true;
5959
base.PersistChanges(model);
6060
//if another server auditing policy exists, remove it
61-
Action swapAuditType = () => { AuditType = AuditType == AuditType.Blob ? AuditType.Table : AuditType.Blob; };
62-
swapAuditType();
61+
if (AuditType == AuditType.Blob)
62+
{
63+
AuditType = AuditType.Table;
64+
}
65+
else
66+
{
67+
AuditType = AuditType.Blob;
68+
}
6369
var otherAuditingTypePolicyModel = GetEntity();
6470
if (otherAuditingTypePolicyModel != null)
6571
{

src/ResourceManager/Sql/Commands.Sql/Auditing/Cmdlet/SetAzureSqlDatabaseAuditingPolicy.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,22 @@ public class SetAzureSqlDatabaseAuditingPolicy : SqlDatabaseAuditingCmdletBase
4545
/// Defines the set of audit action groups that would be used by the auditing settings
4646
/// </summary>
4747
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The set of the audit action groups")]
48+
[ValidateNotNullOrEmpty]
4849
public AuditActionGroups[] AuditActionGroup { get; set; }
4950

5051
/// <summary>
5152
/// Defines the set of audit actions that would be used by the auditing settings
5253
/// </summary>
5354
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The set of the audit actions")]
55+
[ValidateNotNullOrEmpty]
5456
public string[] AuditAction { get; set; }
5557

5658
/// <summary>
5759
/// Gets or sets the names of the event types to use.
5860
/// </summary>
5961
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Event types to audit")]
6062
[ValidateSet(SecurityConstants.PlainSQL_Success, SecurityConstants.PlainSQL_Failure, SecurityConstants.ParameterizedSQL_Success, SecurityConstants.ParameterizedSQL_Failure, SecurityConstants.StoredProcedure_Success, SecurityConstants.StoredProcedure_Failure, SecurityConstants.Login_Success, SecurityConstants.Login_Failure, SecurityConstants.TransactionManagement_Success, SecurityConstants.TransactionManagement_Failure, SecurityConstants.All, SecurityConstants.None, IgnoreCase = false)]
63+
[ValidateNotNullOrEmpty]
6164
public string[] EventType { get; set; }
6265

6366
/// <summary>
@@ -126,7 +129,7 @@ private void ApplyUserInputToBlobAuditingModel(DatabaseBlobAuditingPolicyModel m
126129
model.StorageAccountName = StorageAccountName;
127130
}
128131

129-
if (!string.IsNullOrEmpty(StorageKeyType))
132+
if (MyInvocation.BoundParameters.ContainsKey("StorageKeyType"))
130133
{
131134
// the user enter a key type - we use it (and override the previously defined key type)
132135
model.StorageKeyType = (StorageKeyType == SecurityConstants.Primary)
@@ -144,7 +147,7 @@ private void ApplyUserInputToBlobAuditingModel(DatabaseBlobAuditingPolicyModel m
144147
model.AuditAction = AuditAction;
145148
}
146149

147-
if (EventType != null) // Event types are relevant only for Table auditing
150+
if (MyInvocation.BoundParameters.ContainsKey("EventType")) // Event types are relevant only for Table auditing
148151
{
149152
throw new Exception(string.Format(Properties.Resources.EventTypeConfiguringIrrelevantForBlobAuditingPolicy));
150153
}
@@ -170,7 +173,7 @@ private void ApplyUserInputToTableAuditingModel(DatabaseAuditingPolicyModel mode
170173

171174
EventType = Util.ProcessAuditEvents(EventType);
172175

173-
if (EventType != null) // the user provided Table auditing event types
176+
if (MyInvocation.BoundParameters.ContainsKey("EventType")) // the user provided Table auditing event types
174177
{
175178
model.EventType = EventType.Select(s => SecurityConstants.AuditEventsToAuditEventType[s]).ToArray();
176179
}

src/ResourceManager/Sql/Commands.Sql/Auditing/Cmdlet/SetAzureSqlServerAuditingPolicy.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ public class SetAzureSqlServerAuditingPolicy : SqlDatabaseServerAuditingCmdletBa
3434
[Parameter(Mandatory = false,
3535
ValueFromPipelineByPropertyName = true,
3636
HelpMessage = "The audit type.")]
37+
[ValidateNotNullOrEmpty]
3738
public override AuditType AuditType { get; set; }
3839

3940
/// <summary>
4041
/// Defines the set of audit action groups that would be used by the auditing settings
4142
/// </summary>
4243
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The set of the audit action groups")]
44+
[ValidateNotNullOrEmpty]
4345
public AuditActionGroups[] AuditActionGroup { get; set; }
4446

4547
[Parameter(Mandatory = false)]
@@ -55,6 +57,7 @@ public class SetAzureSqlServerAuditingPolicy : SqlDatabaseServerAuditingCmdletBa
5557
SecurityConstants.StoredProcedure_Failure, SecurityConstants.Login_Success, SecurityConstants.Login_Failure,
5658
SecurityConstants.TransactionManagement_Success, SecurityConstants.TransactionManagement_Failure,
5759
SecurityConstants.All, SecurityConstants.None, IgnoreCase = false)]
60+
[ValidateNotNullOrEmpty]
5861
public string[] EventType { get; set; }
5962

6063
/// <summary>
@@ -129,7 +132,7 @@ private void ApplyUserInputToTableAuditingModel(ServerAuditingPolicyModel model)
129132

130133
EventType = Util.ProcessAuditEvents(EventType);
131134

132-
if (EventType != null) // the user provided event types to audit
135+
if (MyInvocation.BoundParameters.ContainsKey("EventType")) // the user provided event types to audit
133136
{
134137
model.EventType = EventType.Select(s => SecurityConstants.AuditEventsToAuditEventType[s]).ToArray();
135138
}
@@ -152,7 +155,7 @@ private void ApplyUserInputToTableAuditingModel(ServerAuditingPolicyModel model)
152155
model.TableIdentifier = TableIdentifier;
153156
}
154157

155-
if (AuditActionGroup != null) //AuditActionGroup is relevant only for blob auditing
158+
if (MyInvocation.BoundParameters.ContainsKey("AuditActionGroups")) //AuditActionGroup is relevant only for blob auditing
156159
{
157160
throw new Exception(string.Format(Properties.Resources.AuditActionGroupsConfiguringIrrelevantForTableAuditingPolicy));
158161
}
@@ -181,7 +184,7 @@ private void ApplyUserInputToBlobAuditingModel(ServerBlobAuditingPolicyModel mod
181184
model.AuditActionGroup = AuditActionGroup;
182185
}
183186

184-
if (EventType != null) // EventType is relevant only for table auditing
187+
if (MyInvocation.BoundParameters.ContainsKey("EventType")) // EventType is relevant only for table auditing
185188
{
186189
throw new Exception(string.Format(Properties.Resources.EventTypeConfiguringIrrelevantForBlobAuditingPolicy));
187190
}

0 commit comments

Comments
 (0)