diff --git a/src/Security/Security.Test/ScenarioTests/SecuritySolutionsReferenceDataTests.cs b/src/Security/Security.Test/ScenarioTests/SecuritySolutionsReferenceDataTests.cs new file mode 100644 index 000000000000..e42e10436656 --- /dev/null +++ b/src/Security/Security.Test/ScenarioTests/SecuritySolutionsReferenceDataTests.cs @@ -0,0 +1,40 @@ +// ---------------------------------------------------------------------------------- +// +// 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 SecuritySolutionsReferenceDataTests + { + private readonly XunitTracingInterceptor _logger; + + public SecuritySolutionsReferenceDataTests(Xunit.Abstractions.ITestOutputHelper output) + { + _logger = new XunitTracingInterceptor(output); + XunitTracingInterceptor.AddToContext(_logger); + TestExecutionHelpers.SetUpSessionAndProfile(); + } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void GetSubscriptionScope() + { + TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzSecuritySolutionsReferenceData-SubscriptionScope"); + } + } +} diff --git a/src/Security/Security.Test/ScenarioTests/SecuritySolutionsReferenceDataTests.ps1 b/src/Security/Security.Test/ScenarioTests/SecuritySolutionsReferenceDataTests.ps1 new file mode 100644 index 000000000000..f247b49dace9 --- /dev/null +++ b/src/Security/Security.Test/ScenarioTests/SecuritySolutionsReferenceDataTests.ps1 @@ -0,0 +1,50 @@ +# ---------------------------------------------------------------------------------- +# +# 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 discovered security solutions on a subscription scope +#> +function Get-AzSecuritySolutionsReferenceData-SubscriptionScope +{ + $SecuritySolutionsReferenceData = Get-AzSecuritySolutionsReferenceData + Validate-SecuritySolutionsReferenceData $SecuritySolutionsReferenceData +} + +<# +.SYNOPSIS +Validates a list of security discoveredSecuritySolutions +#> +function Validate-SecuritySolutionsReferenceData +{ + param($SecuritySolutionsReferenceData) + + Assert-True { $SecuritySolutionsReferenceData.Count -gt 0 } + + Foreach($SecuritySolutionsReferenceData in $SecuritySolutionsReferenceData) + { + Validate-SecuritySolutionsReferenceData $SecuritySolutionsReferenceData + } +} + +<# +.SYNOPSIS +Validates a single SecuritySolutionsReferenceData +#> +function Validate-SecuritySolutionsReferenceData +{ + param($SecuritySolutionsReferenceData) + + Assert-NotNull $SecuritySolutionsReferenceData +} \ No newline at end of file diff --git a/src/Security/Security.Test/SessionRecords/Microsoft.Azure.Commands.Security.Test.ScenarioTests.SecuritySolutionsReferenceDataTests/GetSubscriptionScope.json b/src/Security/Security.Test/SessionRecords/Microsoft.Azure.Commands.Security.Test.ScenarioTests.SecuritySolutionsReferenceDataTests/GetSubscriptionScope.json new file mode 100644 index 000000000000..ebd5fbb62218 --- /dev/null +++ b/src/Security/Security.Test/SessionRecords/Microsoft.Azure.Commands.Security.Test.ScenarioTests.SecuritySolutionsReferenceDataTests/GetSubscriptionScope.json @@ -0,0 +1,73 @@ +{ + "Entries": [ + { + "RequestUri": "/subscriptions/67bc604b-54b2-4c78-a7ba-72504920a319/providers/Microsoft.Security/securitySolutionsReferenceData?api-version=2020-01-01", + "EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNjdiYzYwNGItNTRiMi00Yzc4LWE3YmEtNzI1MDQ5MjBhMzE5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU2VjdXJpdHkvc2VjdXJpdHlTb2x1dGlvbnNSZWZlcmVuY2VEYXRhP2FwaS12ZXJzaW9uPTIwMjAtMDEtMDE=", + "RequestMethod": "GET", + "RequestBody": "", + "RequestHeaders": { + "x-ms-client-request-id": [ + "abc510fc-77d5-480e-a2ce-f779e2587af4" + ], + "Accept-Language": [ + "en-US" + ], + "User-Agent": [ + "FxVersion/4.700.22.16002", + "OSName/Windows", + "OSVersion/Microsoft.Windows.10.0.22000", + "Microsoft.Azure.Management.Security.SecurityCenterClient/3.0.0.0" + ] + }, + "ResponseHeaders": { + "Cache-Control": [ + "no-cache" + ], + "Pragma": [ + "no-cache" + ], + "x-ms-original-request-ids": [ + "", + "", + "" + ], + "x-ms-ratelimit-remaining-subscription-resource-requests": [ + "749" + ], + "x-ms-request-id": [ + "6b136efa-30f0-4e91-b561-196ba47198e8" + ], + "x-ms-correlation-request-id": [ + "6b136efa-30f0-4e91-b561-196ba47198e8" + ], + "x-ms-routing-request-id": [ + "UAECENTRAL:20220424T150245Z:6b136efa-30f0-4e91-b561-196ba47198e8" + ], + "Strict-Transport-Security": [ + "max-age=31536000; includeSubDomains" + ], + "X-Content-Type-Options": [ + "nosniff" + ], + "Date": [ + "Sun, 24 Apr 2022 15:02:44 GMT" + ], + "Content-Type": [ + "application/json; charset=utf-8" + ], + "Expires": [ + "-1" + ], + "Content-Length": [ + "1903" + ] + }, + "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}", + "StatusCode": 200 + } + ], + "Names": {}, + "Variables": { + "SubscriptionId": "67bc604b-54b2-4c78-a7ba-72504920a319" + } +} \ No newline at end of file diff --git a/src/Security/Security/Az.Security.psd1 b/src/Security/Security/Az.Security.psd1 index 00a289bdf8e9..3934f6810ae3 100644 --- a/src/Security/Security/Az.Security.psd1 +++ b/src/Security/Security/Az.Security.psd1 @@ -74,7 +74,8 @@ NestedModules = @('Microsoft.Azure.PowerShell.Cmdlets.Security.dll') FunctionsToExport = @() # 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. -CmdletsToExport = 'New-AzAlertsSuppressionRuleScope', 'Get-AzAlertsSuppressionRule', 'Set-AzAlertsSuppressionRule', 'Remove-AzAlertsSuppressionRule', + +CmdletsToExport = 'Get-AzSecuritySolutionsReferenceData', 'New-AzAlertsSuppressionRuleScope', 'Get-AzAlertsSuppressionRule', 'Set-AzAlertsSuppressionRule', 'Remove-AzAlertsSuppressionRule', 'Get-AzSecurityAlert', 'Set-AzSecurityAlert', 'Get-AzSecurityAutoProvisioningSetting', 'Set-AzSecurityAutoProvisioningSetting', 'Get-AzSecurityCompliance', diff --git a/src/Security/Security/ChangeLog.md b/src/Security/Security/ChangeLog.md index 4908459016ac..c7d0103b5031 100644 --- a/src/Security/Security/ChangeLog.md +++ b/src/Security/Security/ChangeLog.md @@ -25,6 +25,9 @@ `Set-AlertsSuppressionRule` `New-AzAlertsSuppressionRuleScope` +## Version 1.3.0 +* Added new cmdlets for security SecuritySolutionsReferenceData API + ## Version 1.2.0 * Added new cmdlets for security Automations API diff --git a/src/Security/Security/Cmdlets/SolutionsReferenceData/GetSecuritySolutionReferenceData.cs b/src/Security/Security/Cmdlets/SolutionsReferenceData/GetSecuritySolutionReferenceData.cs new file mode 100644 index 000000000000..72f571d82f11 --- /dev/null +++ b/src/Security/Security/Cmdlets/SolutionsReferenceData/GetSecuritySolutionReferenceData.cs @@ -0,0 +1,56 @@ +// ---------------------------------------------------------------------------------- +// +// 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.ResourceManager.Common.ArgumentCompleters; +using Microsoft.Azure.Commands.Security.Common; +using Microsoft.Azure.Commands.Security.Models.SolutionsReferenceData; +using Microsoft.Azure.Commands.SecurityCenter.Common; +using Microsoft.Rest.Azure; +using System; +using System.Collections.Generic; +using System.Management.Automation; +using System.Text; + +namespace Microsoft.Azure.Commands.Security.Cmdlets.SolutionsReferenceData +{ + [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SecuritySolutionsReferenceData", DefaultParameterSetName = ParameterSetNames.SubscriptionScope), OutputType(typeof(PSSolutionReferenceData))] + public class GetSecuritySolutionReferenceData : SecurityCenterCmdletBase + { + [Parameter(ParameterSetName = ParameterSetNames.SubscriptionLevelResource, Mandatory = true, HelpMessage = ParameterHelpMessages.ResourceName)] + + [Parameter(ParameterSetName = ParameterSetNames.ResourceId, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = ParameterHelpMessages.ResourceId)] + [ValidateNotNullOrEmpty] + public string ResourceId { get; set; } + + public override void ExecuteCmdlet() + { + switch (ParameterSetName) + { + case ParameterSetNames.SubscriptionScope: + var solution = SecurityCenterClient.SecuritySolutionsReferenceData.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body.Value; + WriteObject(solution.ConvertToPSType(), enumerateCollection: true); + break; + + default: + throw new PSInvalidOperationException(); + } + } + + private object ConvertToPSType() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/Security/Security/Models/SolutionsReferenceData/PSSecuritySolutionReferenceDataConverters.cs b/src/Security/Security/Models/SolutionsReferenceData/PSSecuritySolutionReferenceDataConverters.cs new file mode 100644 index 000000000000..cd61017bcb33 --- /dev/null +++ b/src/Security/Security/Models/SolutionsReferenceData/PSSecuritySolutionReferenceDataConverters.cs @@ -0,0 +1,39 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Collections.Generic; +using System.Linq; +using Microsoft.Azure.Management.Security.Models; + +namespace Microsoft.Azure.Commands.Security.Models.SolutionsReferenceData +{ + public static class PSSecuritySolutionReferenceDataConverters + { + public static PSSolutionReferenceData ConvertToPSType(this SecuritySolutionsReferenceData value) + { + return new PSSolutionReferenceData() + { + Id = value.Id, + Name = value.Name, + template = value.Template, + SecurityFamily = value.SecurityFamily + }; + } + + public static List ConvertToPSType(this IEnumerable value) + { + return value.Select(solution => solution.ConvertToPSType()).ToList(); + } + } +} \ No newline at end of file diff --git a/src/Security/Security/Models/SolutionsReferenceData/PSSolutionReferenceData.cs b/src/Security/Security/Models/SolutionsReferenceData/PSSolutionReferenceData.cs new file mode 100644 index 000000000000..c1615bdc39de --- /dev/null +++ b/src/Security/Security/Models/SolutionsReferenceData/PSSolutionReferenceData.cs @@ -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. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Security.Models.SolutionsReferenceData +{ + public class PSSolutionReferenceData + { + public string Id { get; set; } + + public string Name { get; set; } + + public string SecurityFamily { get; set; } + + public string alertVendorName { get; set; } + + public string packageInfoUrl { get; set; } + + public string productName { get; set; } + + public string publisher { get; set; } + + public string publisherDisplayName { get; set; } + + public string template { get; set; } + + } + + +} + diff --git a/src/Security/Security/help/Get-AzSecuritySolutionsReferenceData.md b/src/Security/Security/help/Get-AzSecuritySolutionsReferenceData.md new file mode 100644 index 000000000000..82cf50b6b2f8 --- /dev/null +++ b/src/Security/Security/help/Get-AzSecuritySolutionsReferenceData.md @@ -0,0 +1,86 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Security.dll-Help.xml +Module Name: Az.Security +online version: https://docs.microsoft.com/powershell/module/az.security/Get-AzSecuritySolutionsReferenceData +schema: 2.0.0 +--- + +# Get-AzSecuritySolutionsReferenceData + +## SYNOPSIS +Get Security Solutions Reference Data + +## SYNTAX + +### SubscriptionScope (Default) +``` +Get-AzSecuritySolutionsReferenceData [-DefaultProfile ] [] +``` + +## DESCRIPTION +Get Security Solutions Reference Data + +## EXAMPLES + +### Example 1 +```powershell +Get-AzSecuritySolutionsReferenceData +``` + +```output +Id : /subscriptions/67bc604b-54b2-4c78-a7ba-72504920a319/providers/Microsoft.Security/locations/centr + alus/securitySolutionsReferenceData/qualys.qualysAgent +Name : qualys.qualysAgent +SecurityFamily : Va +alertVendorName : +packageInfoUrl : +productName : +publisher : +publisherDisplayName : +template : qualys/qualysAgent + +Id : /subscriptions/67bc604b-54b2-4c78-a7ba-72504920a319/providers/Microsoft.Security/locations/centr + alus/securitySolutionsReferenceData/microsoft.ApplicationGateway-ARM +Name : microsoft.ApplicationGateway-ARM +SecurityFamily : SaasWaf +alertVendorName : +packageInfoUrl : +productName : +publisher : +publisherDisplayName : +template : microsoft/ApplicationGateway-ARM +``` + +Get all Get Security Solutions Reference Data in the subscription + +## PARAMETERS + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +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). + +## INPUTS + +### System.String + +## OUTPUTS + +### Microsoft.Azure.Commands.Security.Models.ExternalSecuritySolutions.PSSecurityExternalSecuritySolution + +## NOTES + +## RELATED LINKS