Skip to content

Commit

Permalink
Fix SetAlert Cmdlet - add new parameter to be able to use the new ale…
Browse files Browse the repository at this point in the history
…rts type (#13675)
  • Loading branch information
yibirnba authored Dec 7, 2020
1 parent 32b451b commit d408520
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/Security/Security/Cmdlets/Alerts/SetAlerts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public class SetAlerts : SecurityCenterCmdletBase
[ValidateNotNullOrEmpty]
public PSSecurityAlert InputObject { get; set; }

[Parameter(ParameterSetName = ParameterSetNames.InputObjectV3, Mandatory = true, ValueFromPipeline = true, HelpMessage = ParameterHelpMessages.InputObjectV3)]
[ValidateNotNullOrEmpty]
public PSSecurityAlertV3 InputObjectV3 { get; set; }

[Parameter(Mandatory = false, HelpMessage = ParameterHelpMessages.PassThru)]
public SwitchParameter PassThru { get; set; }

Expand All @@ -66,6 +70,7 @@ public override void ExecuteCmdlet()
var name = Name;
var actionType = ActionType;
var location = Location;
var status = "";

switch (ParameterSetName)
{
Expand All @@ -77,29 +82,39 @@ public override void ExecuteCmdlet()
name = AzureIdUtilities.GetResourceName(ResourceId);
break;
case ParameterSetNames.InputObject:
switch (InputObject.State.ToLower())
{
case "dismissed":
actionType = "Dismiss";
break;
case "active":
actionType = "Activate";
break;
case "resolved":
actionType = "Resolve";
break;
default:
break;
}

status = InputObject.State;
name = InputObject.Name;
rg = AzureIdUtilities.GetResourceGroup(InputObject.Id);
location = AzureIdUtilities.GetResourceLocation(InputObject.Id);
break;
case ParameterSetNames.InputObjectV3:
status = InputObjectV3.Status;
name = InputObjectV3.Name;
rg = AzureIdUtilities.GetResourceGroup(InputObjectV3.Id);
location = AzureIdUtilities.GetResourceLocation(InputObjectV3.Id);
break;
default:
throw new PSInvalidOperationException();
}

if (!string.IsNullOrEmpty(status))
{
switch (status.ToLower())
{
case "dismissed":
actionType = "Dismiss";
break;
case "active":
actionType = "Activate";
break;
case "resolved":
actionType = "Resolve";
break;
default:
break;
}
}

SecurityCenterClient.AscLocation = location;

if (string.IsNullOrEmpty(rg))
Expand Down
1 change: 1 addition & 0 deletions src/Security/Security/Common/ParameterHelpMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class ParameterHelpMessages
public const string Scope = "Scope.";
public const string Kind = "Kind.";
public const string InputObject = "Input Object.";
public const string InputObjectV3 = "Input Object V3.";
public const string Location = "Location.";
public const string PassThru = "Return whether the operation was successful.";
public const string Tags = "Tags.";
Expand Down
1 change: 1 addition & 0 deletions src/Security/Security/Common/ParameterSetNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class ParameterSetNames
public const string ResourceIdLevelResource = "ResourceIdLevelResource";
public const string ResourceId = "ResourceId";
public const string InputObject = "InputObject";
public const string InputObjectV3 = "InputObjectV3";
public const string PolicyOn = "PolicyOn";
public const string PolicyOff = "PolicyOff";

Expand Down

0 comments on commit d408520

Please sign in to comment.