Skip to content

Commit 96766cd

Browse files
authored
Merge pull request #8679 from shblum/FullResourceIDWithTests
Full resource id with tests
2 parents 4a07466 + 363ff9a commit 96766cd

File tree

14 files changed

+407
-321
lines changed

14 files changed

+407
-321
lines changed

src/Security/Security.Test/ScenarioTests/SecurityAdvancedThreatProtectionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public SecurityAdvancedThreatProtectionTests(Xunit.Abstractions.ITestOutputHelpe
3232

3333
[Fact]
3434
[Trait(Category.AcceptanceType, Category.CheckIn)]
35-
public void GetResourceId()
35+
public void TestResourceId()
3636
{
37-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzSecurityThreatProtection-ResourceId");
37+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AzSecurityAdvancedThreatProtection-ResourceId");
3838
}
3939

4040
}

src/Security/Security.Test/ScenarioTests/SecurityAdvancedThreatProtectionTests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
<#
1616
.SYNOPSIS
17-
Get a security contact by resource ID
17+
Enables and disables ATP policy using a full resource id.
1818
#>
19-
function Test-AzSecurityThreatProtection-ResourceId
19+
function Test-AzSecurityAdvancedThreatProtection-ResourceId
2020
{
2121
# Setup
2222
$testPrefix = "psstorage"
@@ -25,15 +25,15 @@ function Test-AzSecurityThreatProtection-ResourceId
2525
Create-TestEnvironmentWithParams $testParams
2626

2727
#Enable
28-
$policy = Set-AzSecurityThreatProtection -ResourceId $resourceId -Enable
29-
$fetchedPolicy = Get-AzSecurityThreatProtection -ResourceId $resourceId
30-
Assert-AreEqual $policy.IsEnabled $True
28+
$policy = Enable-AzSecurityAdvancedThreatProtection -ResourceId $resourceId
29+
$fetchedPolicy = Get-AzSecurityAdvancedThreatProtection -ResourceId $resourceId
30+
Assert-AreEqual $True $policy.IsEnabled
3131
Assert-AreEqual $True $fetchedPolicy.IsEnabled
3232

3333
#Disable
34-
$policy = Set-AzSecurityThreatProtection -ResourceId $resourceId -Disable
35-
$fetchedPolicy = Get-AzSecurityThreatProtection -ResourceId $resourceId
36-
Assert-AreEqual $policy.IsEnabled $False
34+
$policy = Disable-AzSecurityAdvancedThreatProtection -ResourceId $resourceId
35+
$fetchedPolicy = Get-AzSecurityAdvancedThreatProtection -ResourceId $resourceId
36+
Assert-AreEqual $False $policy.IsEnabled
3737
Assert-AreEqual $False $fetchedPolicy.IsEnabled
3838
}
3939

Lines changed: 71 additions & 71 deletions
Large diffs are not rendered by default.

src/Security/Security/Az.Security.psd1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ CmdletsToExport = 'Get-AzSecurityAlert', 'Set-AzSecurityAlert',
8686
'Remove-AzSecurityContact', 'Get-AzSecurityTask',
8787
'Get-AzSecurityWorkspaceSetting', 'Set-AzSecurityWorkspaceSetting',
8888
'Remove-AzSecurityWorkspaceSetting',
89-
'Get-AzSecurityThreatProtection',
90-
'Set-AzSecurityThreatProtection'
89+
'Get-AzSecurityAdvancedThreatProtection',
90+
'Enable-AzSecurityAdvancedThreatProtection',
91+
'Disable-AzSecurityAdvancedThreatProtection'
9192

9293
# Variables to export from this module
9394
# VariablesToExport = @()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ------------------------------------
14+
15+
using Commands.Security;
16+
using Microsoft.Azure.Commands.Security.Common;
17+
using Microsoft.Azure.Commands.Security.Models.AdvancedThreatProtection;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Commands.Security.Cmdlets.AdvancedThreatProtection
21+
{
22+
[Cmdlet("Disable", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SecurityAdvancedThreatProtection", SupportsShouldProcess = true, DefaultParameterSetName = ParameterSetNames.ResourceId), OutputType(typeof(PSAdvancedThreatProtection))]
23+
public class DisableAdvancedThreatProtection : SecurityCenterCmdletBase
24+
{
25+
[Parameter(ParameterSetName = ParameterSetNames.ResourceId, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceId)]
26+
[ValidateNotNullOrEmpty]
27+
public string ResourceId { get; set; }
28+
29+
public override void ExecuteCmdlet()
30+
{
31+
if (ShouldProcess(target: ResourceId, action: $"Disabling advanced threat protection policy for '{ResourceId}'."))
32+
{
33+
var result = SecurityCenterClient.AdvancedThreatProtection.CreateWithHttpMessagesAsync(ResourceId, isEnabled: false).GetAwaiter().GetResult().Body;
34+
WriteObject(result, enumerateCollection: true);
35+
}
36+
}
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ------------------------------------
14+
15+
using Commands.Security;
16+
using Microsoft.Azure.Commands.Security.Common;
17+
using Microsoft.Azure.Commands.Security.Models.AdvancedThreatProtection;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Commands.Security.Cmdlets.AdvancedThreatProtection
21+
{
22+
[Cmdlet("Enable", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SecurityAdvancedThreatProtection", SupportsShouldProcess = true, DefaultParameterSetName = ParameterSetNames.ResourceId), OutputType(typeof(PSAdvancedThreatProtection))]
23+
public class EnableAdvancedThreatProtection : SecurityCenterCmdletBase
24+
{
25+
[Parameter(ParameterSetName = ParameterSetNames.ResourceId, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceId)]
26+
[ValidateNotNullOrEmpty]
27+
public string ResourceId { get; set; }
28+
29+
public override void ExecuteCmdlet()
30+
{
31+
if (ShouldProcess(target: ResourceId, action: $"Enabling advanced threat protection policy for '{ResourceId}'."))
32+
{
33+
var result = SecurityCenterClient.AdvancedThreatProtection.CreateWithHttpMessagesAsync(ResourceId, isEnabled: true).GetAwaiter().GetResult().Body;
34+
WriteObject(result, enumerateCollection: true);
35+
}
36+
}
37+
}
38+
}

src/Security/Security/Cmdlets/AdvancedThreatProtection/GetThreatProtectionPolicy.cs renamed to src/Security/Security/Cmdlets/AdvancedThreatProtection/GetAdvancedThreatProtection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
using Commands.Security;
1616
using Microsoft.Azure.Commands.Security.Common;
17-
using Microsoft.Azure.Commands.Security.Models.Locations;
1817
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.Security.Models.AdvancedThreatProtection;
1919

2020
namespace Microsoft.Azure.Commands.Security.Cmdlets.AdvancedThreatProtection
2121
{
22-
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SecurityThreatProtection", DefaultParameterSetName = ParameterSetNames.ResourceId), OutputType(typeof(PSSecurityLocation))]
23-
public class GetThreatProtectionPolicy : SecurityCenterCmdletBase
22+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SecurityAdvancedThreatProtection", SupportsShouldProcess = false, DefaultParameterSetName = ParameterSetNames.ResourceId), OutputType(typeof(PSAdvancedThreatProtection))]
23+
public class GetAdvancedThreatProtection : SecurityCenterCmdletBase
2424
{
2525
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceId)]
2626
[ValidateNotNullOrEmpty]

src/Security/Security/Cmdlets/AdvancedThreatProtection/SetThreatProtectionPolicy .cs

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

src/Security/Security/Models/ThreatProtection/PSThreatProtection.cs renamed to src/Security/Security/Models/AdvancedThreatProtection/PSAdvancedThreatProtection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
namespace Microsoft.Azure.Commands.Security.Models.ThreatProtection
15+
namespace Microsoft.Azure.Commands.Security.Models.AdvancedThreatProtection
1616
{
17-
public class PSThreatProtection
17+
public class PSAdvancedThreatProtection
1818
{
1919
public string Id { get; set; }
2020

21-
public string Name { get; set; }
21+
public bool IsEnabled { get; set; }
2222
}
2323
}

src/Security/Security/help/Az.Security.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Locale: en-US
1111
Azure Security Center gives you control over the security of your Azure subscriptions and other machines that you connected to it outside of Azure.
1212

1313
## Az.Security Cmdlets
14+
### [Disable-AzSecurityAdvancedThreatProtection](Disable-AzSecurityAdvancedThreatProtection.md)
15+
Disables the advanced threat protection policy for a storage account.
16+
17+
### [Enable-AzSecurityAdvancedThreatProtection](Enable-AzSecurityAdvancedThreatProtection.md)
18+
Enables the advanced threat protection policy for a storage account.
19+
1420
### [Get-AzDiscoveredSecuritySolution](Get-AzDiscoveredSecuritySolution.md)
1521
Gets security solutions that were discovered by Azure Security Center
1622

@@ -20,6 +26,9 @@ Get external security solution
2026
### [Get-AzJitNetworkAccessPolicy](Get-AzJitNetworkAccessPolicy.md)
2127
Gets the JIT network access policies
2228

29+
### [Get-AzSecurityAdvancedThreatProtection](Get-AzSecurityAdvancedThreatProtection.md)
30+
Gets the advanced threat protection policy for a storage account.
31+
2332
### [Get-AzSecurityAlert](Get-AzSecurityAlert.md)
2433
Gets security alerts that were detected by Azure Security Center
2534

@@ -41,9 +50,6 @@ Gets the pricing tier data for Azure Security Center for a scope.
4150
### [Get-AzSecurityTask](Get-AzSecurityTask.md)
4251
Gets the security tasks that Azure Security Center recommends you to do in order to strengthen your security posture.
4352

44-
### [Get-AzSecurityThreatProtection](Get-AzSecurityThreatProtection.md)
45-
Gets the threat protection policy for a storage account.
46-
4753
### [Get-AzSecurityWorkspaceSetting](Get-AzSecurityWorkspaceSetting.md)
4854
Gets the configured security workspace settings on a subscription.
4955

@@ -71,9 +77,6 @@ Updates a security contact for a subscription.
7177
### [Set-AzSecurityPricing](Set-AzSecurityPricing.md)
7278
Sets the pricing of Azure Security Center tier for a scope.
7379

74-
### [Set-AzSecurityThreatProtection](Set-AzSecurityThreatProtection.md)
75-
Sets the threat protection policy for a storage account.
76-
7780
### [Set-AzSecurityWorkspaceSetting](Set-AzSecurityWorkspaceSetting.md)
7881
Updates the workspace settings for the subscription.
7982

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
external help file: Microsoft.Azure.PowerShell.Cmdlets.Security.dll-Help.xml
3+
Module Name: Az.Security
4+
online version: https://docs.microsoft.com/en-us/powershell/module/az.security/disable-azsecurityadvancedthreatprotection
5+
schema: 2.0.0
6+
---
7+
8+
# Disable-AzSecurityAdvancedThreatProtection
9+
10+
## SYNOPSIS
11+
Disables the advanced threat protection policy for a storage account.
12+
13+
## SYNTAX
14+
15+
```
16+
Disable-AzSecurityAdvancedThreatProtection -ResourceId <String> [-DefaultProfile <IAzureContextContainer>]
17+
[-WhatIf] [-Confirm] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
The `Disable-AzSecurityAdvancedThreatProtection` cmdlet disables the threat protetion policy for a storage account.
22+
To use this cmdlet, specify the *ResourceId* parameter.
23+
24+
## EXAMPLES
25+
26+
### Example 1
27+
```powershell
28+
PS C:\> Disable-AzSecurityAdvancedThreatProtection -ResourceId "/subscriptions/xxxxxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/myStorageAccount/"
29+
30+
IsEnabled Id
31+
--------- --
32+
False "/subscriptions/xxxxxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/myStorageAccount/"
33+
```
34+
35+
This command disables the advanced threat protection policy for resource id `"/subscriptions/xxxxxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/myStorageAccount/"`.
36+
37+
## PARAMETERS
38+
39+
### -DefaultProfile
40+
The credentials, account, tenant, and subscription used for communication with Azure.
41+
42+
```yaml
43+
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
44+
Parameter Sets: (All)
45+
Aliases: AzContext, AzureRmContext, AzureCredential
46+
47+
Required: False
48+
Position: Named
49+
Default value: None
50+
Accept pipeline input: False
51+
Accept wildcard characters: False
52+
```
53+
54+
### -ResourceId
55+
ID of the security resource that you want to invoke the command on.
56+
57+
```yaml
58+
Type: System.String
59+
Parameter Sets: (All)
60+
Aliases:
61+
62+
Required: True
63+
Position: Named
64+
Default value: None
65+
Accept pipeline input: True (ByPropertyName)
66+
Accept wildcard characters: False
67+
```
68+
69+
### -Confirm
70+
Prompts you for confirmation before running the cmdlet.
71+
72+
```yaml
73+
Type: System.Management.Automation.SwitchParameter
74+
Parameter Sets: (All)
75+
Aliases: cf
76+
77+
Required: False
78+
Position: Named
79+
Default value: None
80+
Accept pipeline input: False
81+
Accept wildcard characters: False
82+
```
83+
84+
### -WhatIf
85+
Shows what would happen if the cmdlet runs. The cmdlet is not run.
86+
87+
```yaml
88+
Type: System.Management.Automation.SwitchParameter
89+
Parameter Sets: (All)
90+
Aliases: wi
91+
92+
Required: False
93+
Position: Named
94+
Default value: None
95+
Accept pipeline input: False
96+
Accept wildcard characters: False
97+
```
98+
99+
### CommonParameters
100+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
101+
102+
## INPUTS
103+
104+
### None
105+
106+
## OUTPUTS
107+
108+
### Microsoft.Azure.Commands.Security.Models.AdvancedThreatProtection.PSAdvancedThreatProtection
109+
110+
## NOTES
111+
112+
## RELATED LINKS

0 commit comments

Comments
 (0)