Skip to content

Azure Security Center - update set security contacts #8123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public void SetSubscriptionLevelResource()
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzureRmSecurityContact-SubscriptionLevelResource");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void SetSubscriptionLevelResourceSecondary()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzureRmSecurityContact-SubscriptionLevelResource-Secondary");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RemoveSubscriptionLevelResource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ function Set-AzureRmSecurityContact-SubscriptionLevelResource
Set-AzureRmSecurityContact -Name "default1" -Email "[email protected]" -Phone "123123123" -AlertAdmin -NotifyOnAlert
}

<#
.SYNOPSIS
Set a security contact on a subscription
#>
function Set-AzureRmSecurityContact-SubscriptionLevelResource-Secondary
{
Set-AzureRmSecurityContact -Name "default2" -Email "[email protected]"
}

<#
.SYNOPSIS
Delete a security contact on a subscription
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/providers/Microsoft.Security/securityContacts/default2?api-version=2017-08-01-preview",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNDg3YmI0ODUtYjViMC00NzFlLTljMGQtMTA3MTc2MTJmODY5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvc2VjdXJpdHlDb250YWN0cy9kZWZhdWx0Mj9hcGktdmVyc2lvbj0yMDE3LTA4LTAxLXByZXZpZXc=",
"RequestMethod": "PUT",
"RequestBody": "{\r\n \"properties\": {\r\n \"email\": \"[email protected]\",\r\n \"phone\": \"\",\r\n \"alertNotifications\": \"Off\",\r\n \"alertsToAdmins\": \"Off\"\r\n }\r\n}",
"RequestHeaders": {
"x-ms-client-request-id": [
"67e5ff82-b090-4760-8d66-ddc5a4db7829"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.27019.06",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.17134.",
"Microsoft.Azure.Management.Security.SecurityCenterClient/0.10.0.0"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"147"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"x-ms-request-id": [
"59a92935-a7e2-42bf-8261-7cb7a7cae756"
],
"Server": [
"Microsoft-HTTPAPI/2.0"
],
"x-ms-ratelimit-remaining-subscription-resource-requests": [
"249"
],
"x-ms-correlation-request-id": [
"4fa9b8b6-3c4a-44b3-80e5-c1b45bb61e8d"
],
"x-ms-routing-request-id": [
"UKWEST:20181213T145753Z:4fa9b8b6-3c4a-44b3-80e5-c1b45bb61e8d"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Thu, 13 Dec 2018 14:57:52 GMT"
],
"Content-Length": [
"274"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
]
},
"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}",
"StatusCode": 200
}
],
"Names": {},
"Variables": {
"SubscriptionId": "487bb485-b5b0-471e-9c0d-10717612f869"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ PrivateData = @{
# IconUri = ''

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

# Prerelease string of this module
# Prerelease = ''
Expand Down
3 changes: 2 additions & 1 deletion src/ResourceManager/Security/Commands.Security/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
* Overview of change #1
- Additional information about change #1
-->
## Current Release
## Current Release
* Update Set-AzSecurityContact. Phone, AlertAdmin, NotifyOnAlert parameters are no longer mandatory
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,24 @@ public class SetSecurityContacts : SecurityCenterCmdletBase
[ValidateNotNullOrEmpty]
public string Email { get; set; }

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

[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = true, HelpMessage = ParameterHelpMessages.AlertsToAdmins)]
[ValidateNotNullOrEmpty]
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = false, HelpMessage = ParameterHelpMessages.AlertsToAdmins)]
public SwitchParameter AlertAdmin { get; set; }

[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = true, HelpMessage = ParameterHelpMessages.AlertNotifications)]
[ValidateNotNullOrEmpty]
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = false, HelpMessage = ParameterHelpMessages.AlertNotifications)]
public SwitchParameter NotifyOnAlert { get; set; }

public override void ExecuteCmdlet()
{
var alertAdmin = AlertAdmin.IsPresent ? "On" : "Off";
var alertNotification = NotifyOnAlert.IsPresent ? "On" : "Off";
var phone = Phone ?? string.Empty;

if (ShouldProcess(Name, VerbsCommon.Set))
{
var contact = new SecurityContact(Email, Phone, alertNotification, alertAdmin);
var contact = new SecurityContact(Email, phone, alertNotification, alertAdmin);
var sc = SecurityCenterClient.SecurityContacts.CreateWithHttpMessagesAsync(Name, contact).GetAwaiter().GetResult().Body;

WriteObject(sc.ConvertToPSType(), enumerateCollection: true);
Expand Down