Skip to content

Commit 5270cef

Browse files
TalFrankeldolauli
andauthored
Generate Defender for Storage V2 cmdlets (#25728)
* Generate Defender for Storage V2 cmdlets * Fix build and PR comments * Make DefenderForStorageSettings a submodule * Create UXMetadataIssues.csv to suppress false positive UX metadata issue * Edit one of the examples --------- Co-authored-by: Xiaogang <[email protected]>
1 parent 0237811 commit 5270cef

29 files changed

+1703
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bin
2+
obj
3+
.vs
4+
generated
5+
internal
6+
exports
7+
tools
8+
custom/*.psm1
9+
custom/autogen-model-cmdlets
10+
test/*-TestResults.xml
11+
/*.ps1
12+
/*.ps1xml
13+
/*.psm1
14+
/*.snk
15+
/*.csproj
16+
/*.nuspec
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@{
2+
GUID = '51b17cfa-b6cf-4bf1-afd7-a55f8cb67a6b'
3+
RootModule = './Az.DefenderForStorage.psm1'
4+
ModuleVersion = '0.1.0'
5+
CompatiblePSEditions = 'Core', 'Desktop'
6+
Author = 'Microsoft Corporation'
7+
CompanyName = 'Microsoft Corporation'
8+
Copyright = 'Microsoft Corporation. All rights reserved.'
9+
Description = 'Microsoft Azure PowerShell: DefenderForStorage cmdlets'
10+
PowerShellVersion = '5.1'
11+
DotNetFrameworkVersion = '4.7.2'
12+
RequiredAssemblies = './bin/Az.DefenderForStorage.private.dll'
13+
FormatsToProcess = './Az.DefenderForStorage.format.ps1xml'
14+
FunctionsToExport = 'Get-AzSecurityDefenderForStorage', 'Update-AzSecurityDefenderForStorage'
15+
PrivateData = @{
16+
PSData = @{
17+
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'DefenderForStorage'
18+
LicenseUri = 'https://aka.ms/azps-license'
19+
ProjectUri = 'https://github.com/Azure/azure-powershell'
20+
ReleaseNotes = ''
21+
}
22+
}
23+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!-- region Generated -->
2+
# Az.DefenderForStorage
3+
This directory contains the PowerShell module for the DefenderForStorage service.
4+
5+
---
6+
## Info
7+
- Modifiable: yes
8+
- Generated: all
9+
- Committed: yes
10+
- Packaged: yes
11+
12+
---
13+
## Detail
14+
This module was primarily generated via [AutoRest](https://github.com/Azure/autorest) using the [PowerShell](https://github.com/Azure/autorest.powershell) extension.
15+
16+
## Module Requirements
17+
- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.7.5 or greater
18+
19+
## Authentication
20+
AutoRest does not generate authentication code for the module. Authentication is handled via Az.Accounts by altering the HTTP payload before it is sent.
21+
22+
## Development
23+
For information on how to develop for `Az.DefenderForStorage`, see [how-to.md](how-to.md).
24+
<!-- endregion -->
25+
26+
### AutoRest Configuration
27+
> see https://aka.ms/autorest
28+
29+
###
30+
``` yaml
31+
commit: 6c4497e6b0aaad8127f2dd50fa8a29aaf68f24e6
32+
require:
33+
- $(this-folder)/../../readme.azure.noprofile.md
34+
input-file:
35+
- $(repo)/specification/security/resource-manager/Microsoft.Security/preview/2022-12-01-preview/defenderForStorageSettings.json
36+
37+
title: DefenderForStorage
38+
root-module-name: $(prefix).Security
39+
subject-prefix: Security
40+
enable-parent-pipeline-input: false
41+
42+
directive:
43+
44+
- where:
45+
variant: ^(Create|Update)(?!.*?Expanded|JsonFilePath|JsonString)
46+
remove: true
47+
- where:
48+
variant: ^CreateViaIdentity.*$|^GetViaIdentity.*$|^UpdateViaIdentityExpanded.*$
49+
remove: true
50+
51+
- where:
52+
verb: New
53+
remove: true
54+
55+
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"resourceType": "defenderForStorageSettings",
3+
"apiVersion": "2022-12-01-preview",
4+
"learnMore": {
5+
"url": "https://learn.microsoft.com/powershell/module/az.security"
6+
},
7+
"commands": [
8+
{
9+
"name": "Get-AzSecurityDefenderForStorage",
10+
"description": "Gets the Defender for Storage settings for the specified storage account.",
11+
"path": "/{resourceId}/providers/Microsoft.Security/defenderForStorageSettings/{settingName}",
12+
"help": {
13+
"learnMore": {
14+
"url": "https://learn.microsoft.com/powershell/module/az.security/get-azsecuritydefenderforstorage"
15+
},
16+
"parameterSets": [
17+
{
18+
"parameters": [
19+
"-ResourceId <String>"
20+
]
21+
}
22+
]
23+
},
24+
"examples": [
25+
{
26+
"description": "Gets the Defender for Storage settings for the specified storage account.",
27+
"parameters": [
28+
{
29+
"name": "-ResourceId",
30+
"value": "[Path.resourceId]"
31+
}
32+
]
33+
}
34+
]
35+
}
36+
]
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Custom
2+
This directory contains custom implementation for non-generated cmdlets for the `Az.DefenderForStorage` module. Both scripts (`.ps1`) and C# files (`.cs`) can be implemented here. They will be used during the build process in `build-module.ps1`, and create cmdlets into the `../exports` folder. The only generated file into this folder is the `Az.DefenderForStorage.custom.psm1`. This file should not be modified.
3+
4+
## Info
5+
- Modifiable: yes
6+
- Generated: partial
7+
- Committed: yes
8+
- Packaged: yes
9+
10+
## Details
11+
For `Az.DefenderForStorage` to use custom cmdlets, it does this two different ways. We **highly recommend** creating script cmdlets, as they are easier to write and allow access to the other exported cmdlets. C# cmdlets *cannot access exported cmdlets*.
12+
13+
For C# cmdlets, they are compiled with the rest of the generated low-level cmdlets into the `./bin/Az.DefenderForStorage.private.dll`. The names of the cmdlets (methods) and files must follow the `[cmdletName]_[variantName]` syntax used for generated cmdlets. The `variantName` is used as the `ParameterSetName`, so use something appropriate that doesn't clash with already created variant or parameter set names. You cannot use the `ParameterSetName` property in the `Parameter` attribute on C# cmdlets. Each cmdlet must be separated into variants using the same pattern as seen in the `generated/cmdlets` folder.
14+
15+
For script cmdlets, these are loaded via the `Az.DefenderForStorage.custom.psm1`. Then, during the build process, this module is loaded and processed in the same manner as the C# cmdlets. The fundamental difference is the script cmdlets use the `ParameterSetName` attribute and C# cmdlets do not. To create a script cmdlet variant of a generated cmdlet, simply decorate all parameters in the script with the new `ParameterSetName` in the `Parameter` attribute. This will appropriately treat each parameter set as a separate variant when processed to be exported during the build.
16+
17+
## Purpose
18+
This allows the modules to have cmdlets that were not defined in the REST specification. It also allows combining logic using generated cmdlets. This is a level of customization beyond what can be done using the [readme configuration options](https://github.com/Azure/autorest/blob/master/docs/powershell/options.md) that are currently available. These custom cmdlets are then referenced by the cmdlets created at build-time in the `../exports` folder.
19+
20+
## Usage
21+
The easiest way currently to start developing custom cmdlets is to copy an existing cmdlet. For C# cmdlets, copy one from the `generated/cmdlets` folder. For script cmdlets, build the project using `build-module.ps1` and copy one of the scripts from the `../exports` folder. After that, if you want to add new parameter sets, follow the guidelines in the `Details` section above. For implementing a new cmdlets, at minimum, please keep these parameters:
22+
- Break
23+
- DefaultProfile
24+
- HttpPipelineAppend
25+
- HttpPipelinePrepend
26+
- Proxy
27+
- ProxyCredential
28+
- ProxyUseDefaultCredentials
29+
30+
These provide functionality to our HTTP pipeline and other useful features. In script, you can forward these parameters using `$PSBoundParameters` to the other cmdlets you're calling within `Az.DefenderForStorage`. For C#, follow the usage seen in the `ProcessRecordAsync` method.
31+
32+
### Attributes
33+
For processing the cmdlets, we've created some additional attributes:
34+
- `Microsoft.Azure.PowerShell.Cmdlets.DefenderForStorage.DescriptionAttribute`
35+
- Used in C# cmdlets to provide a high-level description of the cmdlet. This is propagated to reference documentation via [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) in the exported scripts.
36+
- `Microsoft.Azure.PowerShell.Cmdlets.DefenderForStorage.DoNotExportAttribute`
37+
- Used in C# and script cmdlets to suppress creating an exported cmdlet at build-time. These cmdlets will *not be exposed* by `Az.DefenderForStorage`.
38+
- `Microsoft.Azure.PowerShell.Cmdlets.DefenderForStorage.InternalExportAttribute`
39+
- Used in C# cmdlets to route exported cmdlets to the `../internal`, which are *not exposed* by `Az.DefenderForStorage`. For more information, see [README.md](../internal/README.md) in the `../internal` folder.
40+
- `Microsoft.Azure.PowerShell.Cmdlets.DefenderForStorage.ProfileAttribute`
41+
- Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
Module Name: Az.DefenderForStorage
3+
Module Guid: 51b17cfa-b6cf-4bf1-afd7-a55f8cb67a6b
4+
Download Help Link: https://learn.microsoft.com/powershell/module/az.defenderforstorage
5+
Help Version: 1.0.0.0
6+
Locale: en-US
7+
---
8+
9+
# Az.DefenderForStorage Module
10+
## Description
11+
Microsoft Azure PowerShell: DefenderForStorage cmdlets
12+
13+
## Az.DefenderForStorage Cmdlets
14+
### [Get-AzSecurityDefenderForStorage](Get-AzSecurityDefenderForStorage.md)
15+
Gets the Defender for Storage settings for the specified storage account.
16+
17+
### [Update-AzSecurityDefenderForStorage](Update-AzSecurityDefenderForStorage.md)
18+
Update the Defender for Storage settings on a specified storage account.
19+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
external help file:
3+
Module Name: Az.Security
4+
online version: https://learn.microsoft.com/powershell/module/az.security/get-azsecuritydefenderforstorage
5+
schema: 2.0.0
6+
---
7+
8+
# Get-AzSecurityDefenderForStorage
9+
10+
## SYNOPSIS
11+
Gets the Defender for Storage settings for the specified storage account.
12+
13+
## SYNTAX
14+
15+
```
16+
Get-AzSecurityDefenderForStorage -ResourceId <String> [-DefaultProfile <PSObject>] [<CommonParameters>]
17+
```
18+
19+
## DESCRIPTION
20+
Gets the Defender for Storage settings for the specified storage account.
21+
22+
## EXAMPLES
23+
24+
### Example 1: Get Defender for Storage V2 settings on a storage account
25+
```powershell
26+
Get-AzSecurityDefenderForStorage -ResourceId "/subscriptions/<SubscriptionId>/resourcegroups/<ResourceGroupName>/providers/Microsoft.Storage/storageAccounts/<StorageAccountName>"
27+
```
28+
29+
```output
30+
Id : /subscriptions/<SubscriptionId>/resourcegroups/<ResourceGroupName>/providers/Microsoft.Storage/storageAccounts/<StorageAccountName>
31+
IsEnabled : True
32+
MalwareScanningOperationStatusCode :
33+
MalwareScanningOperationStatusMessage :
34+
MalwareScanningScanResultsEventGridTopicResourceId :
35+
Name : current
36+
OnUploadCapGbPerMonth : 5000
37+
OnUploadIsEnabled : True
38+
OverrideSubscriptionLevelSetting : False
39+
ResourceGroupName : <ResourceGroupName>
40+
SensitiveDataDiscoveryIsEnabled : True
41+
SensitiveDataDiscoveryOperationStatusCode :
42+
SensitiveDataDiscoveryOperationStatusMessage :
43+
Type : Microsoft.Security/defenderForStorageSettings
44+
```
45+
46+
47+
48+
## PARAMETERS
49+
50+
### -DefaultProfile
51+
The DefaultProfile parameter is not functional.
52+
Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
53+
54+
```yaml
55+
Type: System.Management.Automation.PSObject
56+
Parameter Sets: (All)
57+
Aliases: AzureRMContext, AzureCredential
58+
59+
Required: False
60+
Position: Named
61+
Default value: None
62+
Accept pipeline input: False
63+
Accept wildcard characters: False
64+
```
65+
66+
### -ResourceId
67+
The identifier of the resource.
68+
69+
```yaml
70+
Type: System.String
71+
Parameter Sets: (All)
72+
Aliases:
73+
74+
Required: True
75+
Position: Named
76+
Default value: None
77+
Accept pipeline input: False
78+
Accept wildcard characters: False
79+
```
80+
81+
### CommonParameters
82+
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).
83+
84+
## INPUTS
85+
86+
## OUTPUTS
87+
88+
### Microsoft.Azure.PowerShell.Cmdlets.DefenderForStorage.Models.IDefenderForStorageSetting
89+
90+
## NOTES
91+
92+
## RELATED LINKS
93+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Docs
2+
This directory contains the documentation of the cmdlets for the `Az.DefenderForStorage` module. To run documentation generation, use the `generate-help.ps1` script at the root module folder. Files in this folder will *always be overridden on regeneration*. To update documentation examples, please use the `../examples` folder.
3+
4+
## Info
5+
- Modifiable: no
6+
- Generated: all
7+
- Committed: yes
8+
- Packaged: yes
9+
10+
## Details
11+
The process of documentation generation loads `Az.DefenderForStorage` and analyzes the exported cmdlets from the module. It recognizes the [help comments](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comment_based_help) that are generated into the scripts in the `../exports` folder. Additionally, when writing custom cmdlets in the `../custom` folder, you can use the help comments syntax, which decorate the exported scripts at build-time. The documentation examples are taken from the `../examples` folder.

0 commit comments

Comments
 (0)