Skip to content

Commit b1948c6

Browse files
author
dicolanl
committed
major updates
1 parent 194ca1c commit b1948c6

File tree

58 files changed

+1480
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1480
-243
lines changed

src/SecurityInsights/SecurityInsights/Cmdlets/Actions/GetAlertRuleActions.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
using Microsoft.Azure.Commands.SecurityInsights.Common;
1919
using Microsoft.Azure.Commands.SecurityInsights.Models.Actions;
2020
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
21+
using Microsoft.Azure.Management.SecurityInsights;
2122

2223
namespace Microsoft.Azure.Commands.SecurityInsights.Cmdlets.Actions
2324
{
24-
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SentinelAlertRuleAction", DefaultParameterSetName = ParameterSetNames.AlertRuleId), OutputType(typeof(PSSentinelAction))]
25+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SentinelAlertRuleAction", DefaultParameterSetName = ParameterSetNames.AlertRuleId), OutputType(typeof(PSSentinelActionResponse))]
2526
public class GetAlertRuleActions : SecurityInsightsCmdletBase
2627
{
2728
[Parameter(ParameterSetName = ParameterSetNames.AlertRuleId, Mandatory = true, HelpMessage = ParameterHelpMessages.ResourceGroupName)]
@@ -49,12 +50,12 @@ public override void ExecuteCmdlet()
4950
switch (ParameterSetName)
5051
{
5152
case ParameterSetNames.AlertRuleId:
52-
var actions = SecurityInsightsClient.Actions.ListByAlertRuleWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, AlertRuleId).GetAwaiter().GetResult().Body;
53-
WriteObject(actions, enumerateCollection: false);
53+
var actions = SecurityInsightsClient.Actions.ListByAlertRule(ResourceGroupName, WorkspaceName, AlertRuleId);
54+
WriteObject(actions.ConvertToPSType(), enumerateCollection: true);
5455
break;
5556
case ParameterSetNames.ActionId:
56-
var action = SecurityInsightsClient.AlertRules.GetActionWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, AlertRuleId, ActionId);
57-
WriteObject(action, enumerateCollection: false);
57+
var action = SecurityInsightsClient.AlertRules.GetAction(ResourceGroupName, WorkspaceName, AlertRuleId, ActionId);
58+
WriteObject(action.ConvertToPSType(), enumerateCollection: false);
5859
break;
5960
default:
6061
throw new PSInvalidOperationException();

src/SecurityInsights/SecurityInsights/Cmdlets/Actions/NewAlertRuleActions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace Microsoft.Azure.Commands.SecurityInsights.Cmdlets.Actions
2626
{
27-
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SentinelAlertRuleAction", DefaultParameterSetName = ParameterSetNames.ActionId), OutputType(typeof(PSSentinelAction))]
27+
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SentinelAlertRuleAction", DefaultParameterSetName = ParameterSetNames.ActionId), OutputType(typeof(PSSentinelActionResponse))]
2828
public class NewAlertRuleActions : SecurityInsightsCmdletBase
2929
{
3030
[Parameter(ParameterSetName = ParameterSetNames.ActionId, Mandatory = true, HelpMessage = ParameterHelpMessages.ResourceGroupName)]
@@ -68,7 +68,7 @@ public override void ExecuteCmdlet()
6868
{
6969
var outputaction = SecurityInsightsClient.AlertRules.CreateOrUpdateActionWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, AlertRuleId, name, action).GetAwaiter().GetResult().Body;
7070

71-
WriteObject(outputaction, enumerateCollection: false);
71+
WriteObject(outputaction.ConvertToPSType(), enumerateCollection: false);
7272
}
7373
}
7474
}

src/SecurityInsights/SecurityInsights/Cmdlets/Actions/RemoveAlertRuleActions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
using Microsoft.Azure.Commands.SecurityInsights.Models.AlertRules;
1919
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
2020
using Microsoft.Azure.Commands.SecurityInsights.Models.Actions;
21+
using Microsoft.Azure.Management.SecurityInsights;
2122

2223
namespace Microsoft.Azure.Commands.SecurityInsights.Cmdlets.Actions
2324
{
24-
[Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SentinelAlertRuleAction", DefaultParameterSetName = ParameterSetNames.ActionId, SupportsShouldProcess = true), OutputType(typeof(PSSentinelAction))]
25+
[Cmdlet(VerbsCommon.Remove, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SentinelAlertRuleAction", DefaultParameterSetName = ParameterSetNames.ActionId, SupportsShouldProcess = true), OutputType(typeof(PSSentinelActionResponse))]
2526
public class RemoveAlertRuleActions : SecurityInsightsCmdletBase
2627
{
2728
[Parameter(ParameterSetName = ParameterSetNames.ActionId, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceGroupName)]
@@ -42,7 +43,7 @@ public class RemoveAlertRuleActions : SecurityInsightsCmdletBase
4243

4344
[Parameter(ParameterSetName = ParameterSetNames.InputObject, Mandatory = true, ValueFromPipeline = true, HelpMessage = ParameterHelpMessages.InputObject)]
4445
[ValidateNotNullOrEmpty]
45-
public PSSentinelAction InputObject { get; set; }
46+
public PSSentinelActionResponse InputObject { get; set; }
4647

4748
[Parameter(Mandatory = false, HelpMessage = ParameterHelpMessages.PassThru)]
4849
public SwitchParameter PassThru { get; set; }
@@ -69,7 +70,7 @@ public override void ExecuteCmdlet()
6970

7071
if (ShouldProcess(name, VerbsCommon.Remove))
7172
{
72-
SecurityInsightsClient.AlertRules.DeleteActionWithHttpMessagesAsync(resourcegroup, workspacename, alertrule, name).GetAwaiter().GetResult();
73+
SecurityInsightsClient.AlertRules.DeleteAction(resourcegroup, workspacename, alertrule, name);
7374
}
7475

7576
if (PassThru.IsPresent)

src/SecurityInsights/SecurityInsights/Cmdlets/Actions/SetAlertRuleActions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace Microsoft.Azure.Commands.SecurityInsights.Cmdlets.Actions
2424
{
25-
[Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SentinelAlertRuleAction", DefaultParameterSetName = ParameterSetNames.ActionId), OutputType(typeof(PSSentinelAction))]
25+
[Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SentinelAlertRuleAction", DefaultParameterSetName = ParameterSetNames.ActionId), OutputType(typeof(PSSentinelActionResponse))]
2626
public class SetAlertruleActions : SecurityInsightsCmdletBase
2727
{
2828
[Parameter(ParameterSetName = ParameterSetNames.ActionId, Mandatory = true, HelpMessage = ParameterHelpMessages.ResourceGroupName)]
@@ -50,7 +50,7 @@ public class SetAlertruleActions : SecurityInsightsCmdletBase
5050

5151
[Parameter(ParameterSetName = ParameterSetNames.InputObject, Mandatory = true, ValueFromPipeline = true, HelpMessage = ParameterHelpMessages.InputObject)]
5252
[ValidateNotNullOrEmpty]
53-
public ActionRequest InputObject { get; set; }
53+
public PSSentinelActionResponse InputObject { get; set; }
5454

5555
public override void ExecuteCmdlet()
5656
{
@@ -64,7 +64,6 @@ public override void ExecuteCmdlet()
6464
WorkspaceName = AzureIdUtilities.GetWorkspaceName(InputObject.Id);
6565
ResourceGroupName = AzureIdUtilities.GetResourceGroup(InputObject.Id);
6666
LogicAppResourceId = InputObject.LogicAppResourceId;
67-
TriggerUri = InputObject.TriggerUri;
6867
break;
6968
default:
7069
throw new PSInvalidOperationException();
@@ -82,7 +81,7 @@ public override void ExecuteCmdlet()
8281
{
8382
var outputaction = SecurityInsightsClient.AlertRules.CreateOrUpdateActionWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, AlertRuleId, name, action).GetAwaiter().GetResult().Body;
8483

85-
WriteObject(outputaction, enumerateCollection: false);
84+
WriteObject(outputaction?.ConvertToPSType(), enumerateCollection: false);
8685
}
8786
}
8887
}

src/SecurityInsights/SecurityInsights/Cmdlets/AlertRules/GetAlertRules.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.Azure.Commands.SecurityInsights.Models.AlertRules;
2020
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
2121
using System.Linq;
22+
using Microsoft.Azure.Management.SecurityInsights;
2223

2324
namespace Microsoft.Azure.Commands.SecurityInsights.Cmdlets.AlertRules
2425
{
@@ -53,27 +54,28 @@ public override void ExecuteCmdlet()
5354
switch (ParameterSetName)
5455
{
5556
case ParameterSetNames.WorkspaceScope:
56-
var alertrules = SecurityInsightsClient.AlertRules.ListWithHttpMessagesAsync(ResourceGroupName, WorkspaceName).GetAwaiter().GetResult().Body;
57+
var alertrules = SecurityInsightsClient.AlertRules.List(ResourceGroupName, WorkspaceName);
58+
5759
int alertrulescount = alertrules.Count();
58-
WriteObject(alertrules, enumerateCollection: true);
60+
WriteObject(alertrules.ConvertToPSType(), enumerateCollection: true);
5961
numberOfFetchedAlertRules += alertrulescount;
6062
nextLink = alertrules?.NextPageLink;
6163
while (!string.IsNullOrWhiteSpace(nextLink) && numberOfFetchedAlertRules < MaxAlertRulesToFetch)
6264
{
63-
alertrules = SecurityInsightsClient.AlertRules.ListNextWithHttpMessagesAsync(alertrules.NextPageLink).GetAwaiter().GetResult().Body;
65+
alertrules = SecurityInsightsClient.AlertRules.ListNext(alertrules.NextPageLink);
6466
alertrulescount = alertrules.Count();
65-
WriteObject(alertrules, enumerateCollection: true);
67+
WriteObject(alertrules.ConvertToPSType(), enumerateCollection: true);
6668
numberOfFetchedAlertRules += alertrulescount;
6769
nextLink = alertrules?.NextPageLink;
6870
}
6971
break;
7072
case ParameterSetNames.AlertRuleId:
71-
var alertrule = SecurityInsightsClient.AlertRules.GetWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, AlertRuleId).GetAwaiter().GetResult().Body;
72-
WriteObject(alertrule, enumerateCollection: false);
73+
var alertrule = SecurityInsightsClient.AlertRules.Get(ResourceGroupName, WorkspaceName, AlertRuleId);
74+
WriteObject(alertrule.ConvertToPSType(), enumerateCollection: false);
7375
break;
7476
case ParameterSetNames.ResourceId:
75-
alertrule = SecurityInsightsClient.AlertRules.GetWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, AzureIdUtilities.GetResourceName(ResourceId)).GetAwaiter().GetResult().Body;
76-
WriteObject(alertrule, enumerateCollection: false);
77+
alertrule = SecurityInsightsClient.AlertRules.Get(ResourceGroupName, WorkspaceName, AzureIdUtilities.GetResourceName(ResourceId));
78+
WriteObject(alertrule.ConvertToPSType(), enumerateCollection: false);
7779
break;
7880
default:
7981
throw new PSInvalidOperationException();

src/SecurityInsights/SecurityInsights/Cmdlets/AlertRules/NewAlertRules.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.Generic;
2121
using Microsoft.Azure.Management.SecurityInsights.Models;
2222
using System;
23+
using Microsoft.Azure.Management.SecurityInsights;
2324

2425
namespace Microsoft.Azure.Commands.SecurityInsights.Cmdlets.AlertRules
2526
{
@@ -149,8 +150,8 @@ public override void ExecuteCmdlet()
149150
AlertRuleTemplateName = AlertRuleTemplateName,
150151
Enabled = Enabled
151152
};
152-
var outputfusionalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, name, fusionalertrule).GetAwaiter().GetResult().Body;
153-
WriteObject(outputfusionalertrule, enumerateCollection: false);
153+
var outputfusionalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, fusionalertrule);
154+
WriteObject(outputfusionalertrule.ConvertToPSType(), enumerateCollection: false);
154155
break;
155156
case ParameterSetNames.MicrosoftSecurityIncidentCreationRule:
156157
MicrosoftSecurityIncidentCreationAlertRule msicalertrule = new MicrosoftSecurityIncidentCreationAlertRule
@@ -164,8 +165,8 @@ public override void ExecuteCmdlet()
164165
DisplayNamesFilter = DisplayNamesFilter,
165166
SeveritiesFilter = SeveritiesFilter
166167
};
167-
var outputmsicalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, name, msicalertrule).GetAwaiter().GetResult().Body;
168-
WriteObject(outputmsicalertrule, enumerateCollection: false);
168+
var outputmsicalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, msicalertrule);
169+
WriteObject(outputmsicalertrule.ConvertToPSType(), enumerateCollection: false);
169170
break;
170171
case ParameterSetNames.ScheduledAlertRule:
171172
ScheduledAlertRule scheduledalertrule = new ScheduledAlertRule
@@ -184,8 +185,8 @@ public override void ExecuteCmdlet()
184185
TriggerOperator = TriggerOperator,
185186
TriggerThreshold = TriggerThreshold
186187
};
187-
var outputscheduledalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, name, scheduledalertrule).GetAwaiter().GetResult().Body;
188-
WriteObject(outputscheduledalertrule, enumerateCollection: false);
188+
var outputscheduledalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, scheduledalertrule);
189+
WriteObject(outputscheduledalertrule.ConvertToPSType(), enumerateCollection: false);
189190
break;
190191
default:
191192
throw new PSInvalidOperationException();

src/SecurityInsights/SecurityInsights/Cmdlets/AlertRules/RemoveAlertRules.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Commands.SecurityInsights.Common;
1818
using Microsoft.Azure.Commands.SecurityInsights.Models.AlertRules;
1919
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
20+
using Microsoft.Azure.Management.SecurityInsights;
2021

2122
namespace Microsoft.Azure.Commands.SecurityInsights.Cmdlets.AlertRules
2223
{
@@ -59,7 +60,7 @@ public override void ExecuteCmdlet()
5960

6061
if (ShouldProcess(name, VerbsCommon.Remove))
6162
{
62-
SecurityInsightsClient.Incidents.DeleteWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, name).GetAwaiter().GetResult();
63+
SecurityInsightsClient.Incidents.Delete(ResourceGroupName, WorkspaceName, name);
6364
}
6465

6566
if (PassThru.IsPresent)

src/SecurityInsights/SecurityInsights/Cmdlets/AlertRules/SetAlertRules.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.Generic;
2121
using Microsoft.Azure.Management.SecurityInsights.Models;
2222
using System;
23+
using Microsoft.Azure.Management.SecurityInsights;
2324

2425
namespace Microsoft.Azure.Commands.SecurityInsights.Cmdlets.AlertRules
2526
{
@@ -127,6 +128,9 @@ public class SetAlertRules : SecurityInsightsCmdletBase
127128
[ValidateNotNullOrEmpty]
128129
public int? TriggerThreshold { get; set; }
129130

131+
[Parameter(ParameterSetName = ParameterSetNames.InputObject, Mandatory = true, ValueFromPipeline = true, HelpMessage = ParameterHelpMessages.InputObject)]
132+
[ValidateNotNullOrEmpty]
133+
public PSSentinelAlertRule InputObject { get; set; }
130134

131135
public override void ExecuteCmdlet()
132136
{
@@ -142,8 +146,8 @@ public override void ExecuteCmdlet()
142146
AlertRuleTemplateName = AlertRuleTemplateName,
143147
Enabled = Enabled
144148
};
145-
var outputfusionalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, name, fusionalertrule).GetAwaiter().GetResult().Body;
146-
WriteObject(outputfusionalertrule, enumerateCollection: false);
149+
var outputfusionalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, fusionalertrule);
150+
WriteObject(outputfusionalertrule.ConvertToPSType(), enumerateCollection: false);
147151
break;
148152
case ParameterSetNames.MicrosoftSecurityIncidentCreationRule:
149153
MicrosoftSecurityIncidentCreationAlertRule msicalertrule = new MicrosoftSecurityIncidentCreationAlertRule
@@ -157,8 +161,8 @@ public override void ExecuteCmdlet()
157161
DisplayNamesFilter = DisplayNamesFilter,
158162
SeveritiesFilter = SeveritiesFilter
159163
};
160-
var outputmsicalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, name, msicalertrule).GetAwaiter().GetResult().Body;
161-
WriteObject(outputmsicalertrule, enumerateCollection: false);
164+
var outputmsicalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, msicalertrule);
165+
WriteObject(outputmsicalertrule.ConvertToPSType(), enumerateCollection: false);
162166
break;
163167
case ParameterSetNames.ScheduledAlertRule:
164168
ScheduledAlertRule scheduledalertrule = new ScheduledAlertRule
@@ -177,8 +181,28 @@ public override void ExecuteCmdlet()
177181
TriggerOperator = TriggerOperator,
178182
TriggerThreshold = TriggerThreshold
179183
};
180-
var outputscheduledalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, WorkspaceName, name, scheduledalertrule).GetAwaiter().GetResult().Body;
181-
WriteObject(outputscheduledalertrule, enumerateCollection: false);
184+
var outputscheduledalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, scheduledalertrule);
185+
WriteObject(outputscheduledalertrule.ConvertToPSType(), enumerateCollection: false);
186+
break;
187+
case ParameterSetNames.InputObject:
188+
switch(InputObject.Kind)
189+
{
190+
case "Fusion":
191+
var fusionInputRule = InputObject.CreatePSStype();
192+
outputfusionalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, fusionInputRule);
193+
WriteObject(outputfusionalertrule.ConvertToPSType(), enumerateCollection: false);
194+
break;
195+
case "Scheduled":
196+
var scheduledInputRule = InputObject.CreatePSStype();
197+
outputscheduledalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, scheduledInputRule);
198+
WriteObject(outputscheduledalertrule.ConvertToPSType(), enumerateCollection: false);
199+
break;
200+
case "MicrosoftSecurityIncidentCreation":
201+
var msicInputRule = InputObject.CreatePSStype();
202+
outputmsicalertrule = SecurityInsightsClient.AlertRules.CreateOrUpdate(ResourceGroupName, WorkspaceName, name, msicInputRule);
203+
WriteObject(outputmsicalertrule.ConvertToPSType(), enumerateCollection: false);
204+
break;
205+
}
182206
break;
183207
default:
184208
throw new PSInvalidOperationException();

0 commit comments

Comments
 (0)