Skip to content

Commit e0c4a47

Browse files
authored
Merge pull request #8123 from eliagrady/master
Azure Security Center - update set security contacts
2 parents b32385d + 329bb26 commit e0c4a47

File tree

6 files changed

+101
-9
lines changed

6 files changed

+101
-9
lines changed

src/ResourceManager/Security/Commands.Security.Test/ScenarioTests/SecurityContactTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public void SetSubscriptionLevelResource()
5858
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzureRmSecurityContact-SubscriptionLevelResource");
5959
}
6060

61+
[Fact]
62+
[Trait(Category.AcceptanceType, Category.CheckIn)]
63+
public void SetSubscriptionLevelResourceSecondary()
64+
{
65+
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzureRmSecurityContact-SubscriptionLevelResource-Secondary");
66+
}
67+
6168
[Fact]
6269
[Trait(Category.AcceptanceType, Category.CheckIn)]
6370
public void RemoveSubscriptionLevelResource()

src/ResourceManager/Security/Commands.Security.Test/ScenarioTests/SecurityContactTests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ function Set-AzureRmSecurityContact-SubscriptionLevelResource
5757
Set-AzureRmSecurityContact -Name "default1" -Email "[email protected]" -Phone "123123123" -AlertAdmin -NotifyOnAlert
5858
}
5959

60+
<#
61+
.SYNOPSIS
62+
Set a security contact on a subscription
63+
#>
64+
function Set-AzureRmSecurityContact-SubscriptionLevelResource-Secondary
65+
{
66+
Set-AzureRmSecurityContact -Name "default2" -Email "[email protected]"
67+
}
68+
6069
<#
6170
.SYNOPSIS
6271
Delete a security contact on a subscription
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/providers/Microsoft.Security/securityContacts/default2?api-version=2017-08-01-preview",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDg3YmI0ODUtYjViMC00NzFlLTljMGQtMTA3MTc2MTJmODY5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvc2VjdXJpdHlDb250YWN0cy9kZWZhdWx0Mj9hcGktdmVyc2lvbj0yMDE3LTA4LTAxLXByZXZpZXc=",
6+
"RequestMethod": "PUT",
7+
"RequestBody": "{\r\n \"properties\": {\r\n \"email\": \"[email protected]\",\r\n \"phone\": \"\",\r\n \"alertNotifications\": \"Off\",\r\n \"alertsToAdmins\": \"Off\"\r\n }\r\n}",
8+
"RequestHeaders": {
9+
"x-ms-client-request-id": [
10+
"67e5ff82-b090-4760-8d66-ddc5a4db7829"
11+
],
12+
"Accept-Language": [
13+
"en-US"
14+
],
15+
"User-Agent": [
16+
"FxVersion/4.6.27019.06",
17+
"OSName/Windows",
18+
"OSVersion/Microsoft.Windows.10.0.17134.",
19+
"Microsoft.Azure.Management.Security.SecurityCenterClient/0.10.0.0"
20+
],
21+
"Content-Type": [
22+
"application/json; charset=utf-8"
23+
],
24+
"Content-Length": [
25+
"147"
26+
]
27+
},
28+
"ResponseHeaders": {
29+
"Cache-Control": [
30+
"no-cache"
31+
],
32+
"Pragma": [
33+
"no-cache"
34+
],
35+
"x-ms-request-id": [
36+
"59a92935-a7e2-42bf-8261-7cb7a7cae756"
37+
],
38+
"Server": [
39+
"Microsoft-HTTPAPI/2.0"
40+
],
41+
"x-ms-ratelimit-remaining-subscription-resource-requests": [
42+
"249"
43+
],
44+
"x-ms-correlation-request-id": [
45+
"4fa9b8b6-3c4a-44b3-80e5-c1b45bb61e8d"
46+
],
47+
"x-ms-routing-request-id": [
48+
"UKWEST:20181213T145753Z:4fa9b8b6-3c4a-44b3-80e5-c1b45bb61e8d"
49+
],
50+
"Strict-Transport-Security": [
51+
"max-age=31536000; includeSubDomains"
52+
],
53+
"X-Content-Type-Options": [
54+
"nosniff"
55+
],
56+
"Date": [
57+
"Thu, 13 Dec 2018 14:57:52 GMT"
58+
],
59+
"Content-Length": [
60+
"274"
61+
],
62+
"Content-Type": [
63+
"application/json; charset=utf-8"
64+
],
65+
"Expires": [
66+
"-1"
67+
]
68+
},
69+
"ResponseBody": "{\r\n \"id\": \"/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/providers/Microsoft.Security/securityContacts/default2\",\r\n \"name\": \"default2\",\r\n \"type\": \"Microsoft.Security/securityContacts\",\r\n \"properties\": {\r\n \"email\": \"[email protected]\",\r\n \"alertNotifications\": \"Off\",\r\n \"alertsToAdmins\": \"Off\"\r\n }\r\n}",
70+
"StatusCode": 200
71+
}
72+
],
73+
"Names": {},
74+
"Variables": {
75+
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
76+
}
77+
}

src/ResourceManager/Security/Commands.Security/Az.Security.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ PrivateData = @{
120120
# IconUri = ''
121121

122122
# ReleaseNotes of this module
123-
ReleaseNotes = 'Initial Release with PowerShell and PowerShell Core Support'
123+
ReleaseNotes = 'Update Set-AzSecurityContact. Phone, AlertAdmin, NotifyOnAlert parameters are no longer mandatory'
124124

125125
# Prerelease string of this module
126126
# Prerelease = ''

src/ResourceManager/Security/Commands.Security/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
* Overview of change #1
1818
- Additional information about change #1
1919
-->
20-
## Current Release
20+
## Current Release
21+
* Update Set-AzSecurityContact. Phone, AlertAdmin, NotifyOnAlert parameters are no longer mandatory

src/ResourceManager/Security/Commands.Security/Cmdlets/SecurityContacts/SetSecurityContacts.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,24 @@ public class SetSecurityContacts : SecurityCenterCmdletBase
3232
[ValidateNotNullOrEmpty]
3333
public string Email { get; set; }
3434

35-
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = true, HelpMessage = ParameterHelpMessages.Phone)]
36-
[ValidateNotNullOrEmpty]
35+
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = false, HelpMessage = ParameterHelpMessages.Phone)]
3736
public string Phone { get; set; }
3837

39-
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = true, HelpMessage = ParameterHelpMessages.AlertsToAdmins)]
40-
[ValidateNotNullOrEmpty]
38+
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = false, HelpMessage = ParameterHelpMessages.AlertsToAdmins)]
4139
public SwitchParameter AlertAdmin { get; set; }
4240

43-
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = true, HelpMessage = ParameterHelpMessages.AlertNotifications)]
44-
[ValidateNotNullOrEmpty]
41+
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = false, HelpMessage = ParameterHelpMessages.AlertNotifications)]
4542
public SwitchParameter NotifyOnAlert { get; set; }
4643

4744
public override void ExecuteCmdlet()
4845
{
4946
var alertAdmin = AlertAdmin.IsPresent ? "On" : "Off";
5047
var alertNotification = NotifyOnAlert.IsPresent ? "On" : "Off";
48+
var phone = Phone ?? string.Empty;
5149

5250
if (ShouldProcess(Name, VerbsCommon.Set))
5351
{
54-
var contact = new SecurityContact(Email, Phone, alertNotification, alertAdmin);
52+
var contact = new SecurityContact(Email, phone, alertNotification, alertAdmin);
5553
var sc = SecurityCenterClient.SecurityContacts.CreateWithHttpMessagesAsync(Name, contact).GetAwaiter().GetResult().Body;
5654

5755
WriteObject(sc.ConvertToPSType(), enumerateCollection: true);

0 commit comments

Comments
 (0)