Skip to content

Commit 9b51160

Browse files
committed
Add new " SecuritySolutionsReferenceData" cmdlet
1 parent d3e6f57 commit 9b51160

File tree

7 files changed

+300
-1
lines changed

7 files changed

+300
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 Microsoft.Azure.Commands.ScenarioTest;
16+
using Microsoft.Azure.ServiceManagement.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.Security.Test.ScenarioTests
21+
{
22+
public class SecuritySolutionsReferenceDataTests
23+
{
24+
private readonly XunitTracingInterceptor _logger;
25+
26+
public SecuritySolutionsReferenceDataTests(Xunit.Abstractions.ITestOutputHelper output)
27+
{
28+
_logger = new XunitTracingInterceptor(output);
29+
XunitTracingInterceptor.AddToContext(_logger);
30+
TestExecutionHelpers.SetUpSessionAndProfile();
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void GetSubscriptionScope()
36+
{
37+
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSecuritySolutionsReferenceData-SubscriptionScope");
38+
}
39+
}
40+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
<#
16+
.SYNOPSIS
17+
Get discovered security solutions on a subscription scope
18+
#>
19+
function Get-AzSecuritySolutionsReferenceData-SubscriptionScope
20+
{
21+
$SecuritySolutionsReferenceData = Get-AzSecuritySolutionsReferenceData
22+
Validate-SecuritySolutionsReferenceData $SecuritySolutionsReferenceData
23+
}
24+
25+
<#
26+
.SYNOPSIS
27+
Validates a list of security discoveredSecuritySolutions
28+
#>
29+
function Validate-SecuritySolutionsReferenceData
30+
{
31+
param($SecuritySolutionsReferenceData)
32+
33+
Assert-True { $SecuritySolutionsReferenceData.Count -gt 0 }
34+
35+
Foreach($SecuritySolutionsReferenceData in $SecuritySolutionsReferenceData)
36+
{
37+
Validate-SecuritySolutionsReferenceData $SecuritySolutionsReferenceData
38+
}
39+
}
40+
41+
<#
42+
.SYNOPSIS
43+
Validates a single SecuritySolutionsReferenceData
44+
#>
45+
function Validate-SecuritySolutionsReferenceData
46+
{
47+
param($SecuritySolutionsReferenceData)
48+
49+
Assert-NotNull $SecuritySolutionsReferenceData
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions/67bc604b-54b2-4c78-a7ba-72504920a319/providers/Microsoft.Security/securitySolutionsReferenceData?api-version=2020-01-01",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNjdiYzYwNGItNTRiMi00Yzc4LWE3YmEtNzI1MDQ5MjBhMzE5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvc2VjdXJpdHlTb2x1dGlvbnNSZWZlcmVuY2VEYXRhP2FwaS12ZXJzaW9uPTIwMjAtMDEtMDE=",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"x-ms-client-request-id": [
10+
"abc510fc-77d5-480e-a2ce-f779e2587af4"
11+
],
12+
"Accept-Language": [
13+
"en-US"
14+
],
15+
"User-Agent": [
16+
"FxVersion/4.700.22.16002",
17+
"OSName/Windows",
18+
"OSVersion/Microsoft.Windows.10.0.22000",
19+
"Microsoft.Azure.Management.Security.SecurityCenterClient/3.0.0.0"
20+
]
21+
},
22+
"ResponseHeaders": {
23+
"Cache-Control": [
24+
"no-cache"
25+
],
26+
"Pragma": [
27+
"no-cache"
28+
],
29+
"x-ms-original-request-ids": [
30+
"",
31+
"",
32+
""
33+
],
34+
"x-ms-ratelimit-remaining-subscription-resource-requests": [
35+
"749"
36+
],
37+
"x-ms-request-id": [
38+
"6b136efa-30f0-4e91-b561-196ba47198e8"
39+
],
40+
"x-ms-correlation-request-id": [
41+
"6b136efa-30f0-4e91-b561-196ba47198e8"
42+
],
43+
"x-ms-routing-request-id": [
44+
"UAECENTRAL:20220424T150245Z:6b136efa-30f0-4e91-b561-196ba47198e8"
45+
],
46+
"Strict-Transport-Security": [
47+
"max-age=31536000; includeSubDomains"
48+
],
49+
"X-Content-Type-Options": [
50+
"nosniff"
51+
],
52+
"Date": [
53+
"Sun, 24 Apr 2022 15:02:44 GMT"
54+
],
55+
"Content-Type": [
56+
"application/json; charset=utf-8"
57+
],
58+
"Expires": [
59+
"-1"
60+
],
61+
"Content-Length": [
62+
"1903"
63+
]
64+
},
65+
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"id\": \"/subscriptions/67bc604b-54b2-4c78-a7ba-72504920a319/providers/Microsoft.Security/locations/centralus/securitySolutionsReferenceData/rapid7.insightplatform\",\r\n \"name\": \"rapid7.insightplatform\",\r\n \"type\": \"Microsoft.Security/locations/securitySolutionsReferenceData\",\r\n \"properties\": {\r\n \"alertVendorName\": \"Rapid7\",\r\n \"securityFamily\": \"Va\",\r\n \"packageInfoUrl\": \"www.azure.com\",\r\n \"productName\": \"Vulnerability Assessment\",\r\n \"provisionType\": \"SemiIntegrated\",\r\n \"publisher\": \"rapid7\",\r\n \"publisherDisplayName\": \"Rapid7 Inc.\",\r\n \"template\": \"rapid7/insightplatform\"\r\n }\r\n },\r\n {\r\n \"id\": \"/subscriptions/67bc604b-54b2-4c78-a7ba-72504920a319/providers/Microsoft.Security/locations/centralus/securitySolutionsReferenceData/qualys.qualysAgent\",\r\n \"name\": \"qualys.qualysAgent\",\r\n \"type\": \"Microsoft.Security/locations/securitySolutionsReferenceData\",\r\n \"properties\": {\r\n \"alertVendorName\": \"Qualys VA\",\r\n \"securityFamily\": \"Va\",\r\n \"packageInfoUrl\": \"http://www.qualys.com/\",\r\n \"productName\": \"Vulnerability Assessment\",\r\n \"provisionType\": \"SemiIntegrated\",\r\n \"publisher\": \"qualys\",\r\n \"publisherDisplayName\": \"Qualys, Inc.\",\r\n \"template\": \"qualys/qualysAgent\",\r\n \"templateAdministrationExpression\": \"http://www.qualys.com/\"\r\n }\r\n },\r\n {\r\n \"id\": \"/subscriptions/67bc604b-54b2-4c78-a7ba-72504920a319/providers/Microsoft.Security/locations/centralus/securitySolutionsReferenceData/microsoft.ApplicationGateway-ARM\",\r\n \"name\": \"microsoft.ApplicationGateway-ARM\",\r\n \"type\": \"Microsoft.Security/locations/securitySolutionsReferenceData\",\r\n \"properties\": {\r\n \"alertVendorName\": \"Microsoft\",\r\n \"securityFamily\": \"SaasWaf\",\r\n \"packageInfoUrl\": \"www.azure.com\",\r\n \"productName\": \"Web Application Firewall\",\r\n \"provisionType\": \"SemiIntegrated\",\r\n \"publisher\": \"microsoft\",\r\n \"publisherDisplayName\": \"Microsoft Inc.\",\r\n \"template\": \"microsoft/ApplicationGateway-ARM\",\r\n \"templateAdministrationExpression\": \"https://portal.azure.com#resource/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Network/applicationGateways/{name}/overview\"\r\n }\r\n }\r\n ]\r\n}",
66+
"StatusCode": 200
67+
}
68+
],
69+
"Names": {},
70+
"Variables": {
71+
"SubscriptionId": "67bc604b-54b2-4c78-a7ba-72504920a319"
72+
}
73+
}

src/Security/Security/Az.Security.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ NestedModules = @('Microsoft.Azure.PowerShell.Cmdlets.Security.dll')
7474
FunctionsToExport = @()
7575

7676
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
77-
CmdletsToExport = 'Get-AzSecurityAlert', 'Set-AzSecurityAlert',
77+
CmdletsToExport = 'Get-AzSecuritySolutionsReferenceData', 'Get-AzSecurityAlert', 'Set-AzSecurityAlert',
7878
'Get-AzSecurityAutoProvisioningSetting',
7979
'Set-AzSecurityAutoProvisioningSetting', 'Get-AzSecurityCompliance',
8080
'Get-AzDiscoveredSecuritySolution',
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.ResourceManager.Common.ArgumentCompleters;
17+
using Microsoft.Azure.Commands.Security.Common;
18+
using Microsoft.Azure.Commands.Security.Models.SolutionsReferenceData;
19+
using Microsoft.Azure.Commands.SecurityCenter.Common;
20+
using Microsoft.Rest.Azure;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Management.Automation;
24+
using System.Text;
25+
26+
namespace Microsoft.Azure.Commands.Security.Cmdlets.SolutionsReferenceData
27+
{
28+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SecuritySolutionsReferenceData", DefaultParameterSetName = ParameterSetNames.SubscriptionScope), OutputType(typeof(PSSolutionReferenceData))]
29+
public class GetSecuritySolutionReferenceData : SecurityCenterCmdletBase
30+
{
31+
[Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = true, HelpMessage = ParameterHelpMessages.ResourceName)]
32+
33+
[Parameter(ParameterSetName = ParameterSetNames.ResourceId, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceId)]
34+
[ValidateNotNullOrEmpty]
35+
public string ResourceId { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
switch (ParameterSetName)
40+
{
41+
case ParameterSetNames.SubscriptionScope:
42+
var solution = SecurityCenterClient.SecuritySolutionsReferenceData.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body.Value;
43+
WriteObject(solution.ConvertToPSType(), enumerateCollection: true);
44+
break;
45+
46+
default:
47+
throw new PSInvalidOperationException();
48+
}
49+
}
50+
51+
private object ConvertToPSType()
52+
{
53+
throw new NotImplementedException();
54+
}
55+
}
56+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 System.Collections.Generic;
16+
using System.Linq;
17+
using Microsoft.Azure.Management.Security.Models;
18+
19+
namespace Microsoft.Azure.Commands.Security.Models.SolutionsReferenceData
20+
{
21+
public static class PSSecuritySolutionReferenceDataConverters
22+
{
23+
public static PSSolutionReferenceData ConvertToPSType(this SecuritySolutionsReferenceData value)
24+
{
25+
return new PSSolutionReferenceData()
26+
{
27+
Id = value.Id,
28+
Name = value.Name,
29+
template = value.Template,
30+
SecurityFamily = value.SecurityFamily
31+
};
32+
}
33+
34+
public static List<PSSolutionReferenceData> ConvertToPSType(this IEnumerable<SecuritySolutionsReferenceData> value)
35+
{
36+
return value.Select(solution => solution.ConvertToPSType()).ToList();
37+
}
38+
}
39+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
namespace Microsoft.Azure.Commands.Security.Models.SolutionsReferenceData
16+
{
17+
public class PSSolutionReferenceData
18+
{
19+
public string Id { get; set; }
20+
21+
public string Name { get; set; }
22+
23+
public string SecurityFamily { get; set; }
24+
25+
public string alertVendorName { get; set; }
26+
27+
public string packageInfoUrl { get; set; }
28+
29+
public string productName { get; set; }
30+
31+
public string publisher { get; set; }
32+
33+
public string publisherDisplayName { get; set; }
34+
35+
public string template { get; set; }
36+
37+
}
38+
39+
40+
}
41+

0 commit comments

Comments
 (0)