-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8523 from shblum/master
Support Advanced Threat Protection policy management
- Loading branch information
Showing
15 changed files
with
1,041 additions
and
14 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/Security/Security.Test/ScenarioTests/SecurityAdvancedThreatProtectionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.ScenarioTest; | ||
using Microsoft.Azure.ServiceManagement.Common.Models; | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Commands.Security.Test.ScenarioTests | ||
{ | ||
public class SecurityAdvancedThreatProtectionTests | ||
{ | ||
private readonly XunitTracingInterceptor _logger; | ||
|
||
public SecurityAdvancedThreatProtectionTests(Xunit.Abstractions.ITestOutputHelper output) | ||
{ | ||
_logger = new XunitTracingInterceptor(output); | ||
XunitTracingInterceptor.AddToContext(_logger); | ||
TestExecutionHelpers.SetUpSessionAndProfile(); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void GetResourceId() | ||
{ | ||
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzSecurityThreatProtection-ResourceId"); | ||
} | ||
|
||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/Security/Security.Test/ScenarioTests/SecurityAdvancedThreatProtectionTests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# Copyright Microsoft Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ---------------------------------------------------------------------------------- | ||
|
||
<# | ||
.SYNOPSIS | ||
Get a security contact by resource ID | ||
#> | ||
function Test-AzSecurityThreatProtection-ResourceId | ||
{ | ||
# Setup | ||
$testPrefix = "psstorage" | ||
$testParams = Get-AdvancedThreatProtectionTestEnvironmentParameters $testPrefix | ||
$resourceId = "/subscriptions/" + $testParams.subscriptionId + "/resourceGroups/" + $testParams.rgName + "/providers/Microsoft.Storage/storageAccounts/" + $testParams.accountName | ||
Create-TestEnvironmentWithParams $testParams | ||
|
||
#Enable | ||
$policy = Set-AzSecurityThreatProtection -ResourceId $resourceId -Enable | ||
$fetchedPolicy = Get-AzSecurityThreatProtection -ResourceId $resourceId | ||
Assert-AreEqual $policy.IsEnabled $True | ||
Assert-AreEqual $True $fetchedPolicy.IsEnabled | ||
|
||
#Disable | ||
$policy = Set-AzSecurityThreatProtection -ResourceId $resourceId -Disable | ||
$fetchedPolicy = Get-AzSecurityThreatProtection -ResourceId $resourceId | ||
Assert-AreEqual $policy.IsEnabled $False | ||
Assert-AreEqual $False $fetchedPolicy.IsEnabled | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Gets the values of the parameters used at the tests | ||
#> | ||
function Get-AdvancedThreatProtectionTestEnvironmentParameters ($testPrefix) | ||
{ | ||
return @{ subscriptionId = (Get-AzContext).Subscription.Id; | ||
rgName = getAssetName ($testPrefix); | ||
accountName = getAssetName ($testPrefix); | ||
storageSku = "Standard_GRS"; | ||
location = Get-Location "Microsoft.Resources" "resourceGroups" "West US" | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Creates the basic test environment needed to perform the threat protection tests - resource group and storage account | ||
#> | ||
function Create-TestEnvironmentWithParams ($testParams) | ||
{ | ||
# Create a new resource group. | ||
New-AzResourceGroup -Name $testParams.rgName -Location $testParams.location | ||
|
||
# Create the storage account. | ||
$storageAccount = New-AzStorageAccount -ResourceGroupName $testParams.rgName -Name $testParams.accountName -Location $testParams.location -Type $testParams.storageSku | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
535 changes: 535 additions & 0 deletions
535
...ands.Security.Test.ScenarioTests.SecurityAdvancedThreatProtectionTests/GetResourceId.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Security/Security/Cmdlets/AdvancedThreatProtection/GetThreatProtectionPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ------------------------------------ | ||
|
||
using Commands.Security; | ||
using Microsoft.Azure.Commands.Security.Common; | ||
using Microsoft.Azure.Commands.Security.Models.Locations; | ||
using System.Management.Automation; | ||
|
||
namespace Microsoft.Azure.Commands.Security.Cmdlets.AdvancedThreatProtection | ||
{ | ||
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SecurityThreatProtection", DefaultParameterSetName = ParameterSetNames.ResourceId), OutputType(typeof(PSSecurityLocation))] | ||
public class GetThreatProtectionPolicy : SecurityCenterCmdletBase | ||
{ | ||
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceId)] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceId { get; set; } | ||
public override void ExecuteCmdlet() | ||
{ | ||
var result = SecurityCenterClient.AdvancedThreatProtection.GetWithHttpMessagesAsync(ResourceId).GetAwaiter().GetResult().Body; | ||
WriteObject(result, enumerateCollection: true); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/Security/Security/Cmdlets/AdvancedThreatProtection/SetThreatProtectionPolicy .cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ------------------------------------ | ||
|
||
using System.Management.Automation; | ||
using Commands.Security; | ||
using Microsoft.Azure.Commands.Security.Common; | ||
using Microsoft.Azure.Commands.Security.Models.ThreatProtection; | ||
|
||
|
||
namespace Microsoft.Azure.Commands.Security.Cmdlets.AdvancedThreatProtection | ||
{ | ||
[Cmdlet(VerbsCommon.Set, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SecurityThreatProtection", DefaultParameterSetName = ParameterSetNames.PolicyOn, SupportsShouldProcess = true), OutputType(typeof(PSThreatProtection))] | ||
public class SetThreatProtectionPolicy : SecurityCenterCmdletBase | ||
{ | ||
[Parameter(ParameterSetName = ParameterSetNames.PolicyOn, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceId)] | ||
[Parameter(ParameterSetName = ParameterSetNames.PolicyOff, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceId)] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceId { get; set; } | ||
|
||
[Parameter(ParameterSetName = ParameterSetNames.PolicyOn, Mandatory = true, HelpMessage = ParameterHelpMessages.Enable)] | ||
[ValidateNotNullOrEmpty] | ||
public SwitchParameter Enable { get; set; } | ||
|
||
[Parameter(ParameterSetName = ParameterSetNames.PolicyOff, Mandatory = true, HelpMessage = ParameterHelpMessages.Disable)] | ||
[ValidateNotNullOrEmpty] | ||
public SwitchParameter Disable { get; set; } | ||
|
||
public override void ExecuteCmdlet() | ||
{ | ||
bool policy; | ||
|
||
switch (ParameterSetName) | ||
{ | ||
case ParameterSetNames.PolicyOn: | ||
policy = true; | ||
break; | ||
case ParameterSetNames.PolicyOff: | ||
policy = false; | ||
break; | ||
default: | ||
throw new PSInvalidOperationException(); | ||
} | ||
|
||
var result = SecurityCenterClient.AdvancedThreatProtection.CreateWithHttpMessagesAsync(ResourceId, policy).GetAwaiter().GetResult().Body; | ||
WriteObject(result, enumerateCollection: true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Security/Security/Models/ThreatProtection/PSThreatProtection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Commands.Security.Models.ThreatProtection | ||
{ | ||
public class PSThreatProtection | ||
{ | ||
public string Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.