Skip to content

Commit ce3bd13

Browse files
cherry-pick a666b85 from generation
1 parent a69470e commit ce3bd13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+713
-476
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@{
2+
GUID = '28bf853b-7409-4d2c-bb4a-9c72f30e9a09'
3+
RootModule = './Az.Policy.psm1'
4+
ModuleVersion = '0.1.1'
5+
CompatiblePSEditions = 'Core', 'Desktop'
6+
Author = 'Microsoft Corporation'
7+
CompanyName = 'Microsoft Corporation'
8+
Copyright = 'Microsoft Corporation. All rights reserved.'
9+
Description = 'Microsoft Azure PowerShell: Policy cmdlets'
10+
PowerShellVersion = '5.1'
11+
DotNetFrameworkVersion = '4.7.2'
12+
RequiredAssemblies = './bin/Az.Policy.private.dll'
13+
FormatsToProcess = './Az.Policy.format.ps1xml'
14+
ScriptsToProcess = @('./custom/Helpers.ps1')
15+
FunctionsToExport = 'Get-AzPolicyAssignment', 'Get-AzPolicyDefinition', 'Get-AzPolicyExemption', 'Get-AzPolicySetDefinition', 'New-AzPolicyAssignment', 'New-AzPolicyDefinition', 'New-AzPolicyExemption', 'New-AzPolicySetDefinition', 'Remove-AzPolicyAssignment', 'Remove-AzPolicyDefinition', 'Remove-AzPolicyExemption', 'Remove-AzPolicySetDefinition', 'Update-AzPolicyAssignment', 'Update-AzPolicyDefinition', 'Update-AzPolicyExemption', 'Update-AzPolicySetDefinition'
16+
AliasesToExport = 'Set-AzPolicyAssignment', 'Set-AzPolicyDefinition', 'Set-AzPolicyExemption', 'Set-AzPolicySetDefinition'
17+
PrivateData = @{
18+
PSData = @{
19+
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'Policy'
20+
LicenseUri = 'https://aka.ms/azps-license'
21+
ProjectUri = 'https://github.com/Azure/azure-powershell'
22+
ReleaseNotes = ''
23+
}
24+
}
25+
}

src/Resources/Policy.Autorest/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Resources/Policy.Autorest/build-module.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ if(-not $Debugger) {
9797
$null = Remove-Item -Recurse -ErrorAction SilentlyContinue -Path (Join-Path $binFolder 'Debug'), (Join-Path $binFolder 'Release')
9898
}
9999

100-
$dll = Join-Path $PSScriptRoot 'bin\Az.Policy.private.dll'
100+
$dll = Join-Path $PSScriptRoot 'bin/Az.Policy.private.dll'
101101
if(-not (Test-Path $dll)) {
102102
Write-Error "Unable to find output assembly in '$binFolder'."
103103
}
@@ -106,7 +106,7 @@ if(-not (Test-Path $dll)) {
106106
$null = Import-Module -Name $dll
107107

108108
$modulePaths = $dll
109-
$customPsm1 = Join-Path $PSScriptRoot 'custom\Az.Policy.custom.psm1'
109+
$customPsm1 = Join-Path $PSScriptRoot 'custom/Az.Policy.custom.psm1'
110110
if(Test-Path $customPsm1) {
111111
$modulePaths = @($dll, $customPsm1)
112112
}
@@ -178,8 +178,8 @@ if (Test-Path (Join-Path $PSScriptRoot 'generate-portal-ux.ps1'))
178178
}
179179

180180
if (-not $DisableAfterBuildTasks){
181-
$afterBuildTasksPath = Join-Path $PSScriptRoot ''
182-
$afterBuildTasksArgs = ConvertFrom-Json 'true' -AsHashtable
181+
$afterBuildTasksPath = Join-Path $PSScriptRoot '../../../tools/BuildScripts/AdaptAutorestModule.ps1'
182+
$afterBuildTasksArgs = ConvertFrom-Json '{"SubModuleName":"Policy","ModuleRootName":"Az.Resources"}' -AsHashtable
183183
if(Test-Path -Path $afterBuildTasksPath -PathType leaf){
184184
Write-Host -ForegroundColor Green 'Running after build tasks...'
185185
. $afterBuildTasksPath @afterBuildTasksArgs

src/Resources/Policy.Autorest/create-model-cmdlets.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function CreateModelCmdlet {
2222
return
2323
}
2424

25-
$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated\api') 'Models'
26-
$OutputDir = Join-Path $PSScriptRoot 'custom\autogen-model-cmdlets'
25+
$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated/api') 'Models'
26+
$OutputDir = Join-Path $PSScriptRoot 'custom/autogen-model-cmdlets'
2727
$null = New-Item -ItemType Directory -Force -Path $OutputDir
2828
if ('Az.Resources'.length -gt 0) {
2929
$ModuleName = 'Az.Resources'

src/Resources/Policy.Autorest/custom/Az.Policy.custom.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# region Generated
22
# Load the private module dll
3-
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '..\bin\Az.Policy.private.dll')
3+
$null = Import-Module -PassThru -Name (Join-Path $PSScriptRoot '../bin/Az.Policy.private.dll')
44

55
# Load the internal module
6-
$internalModulePath = Join-Path $PSScriptRoot '..\internal\Az.Policy.internal.psm1'
6+
$internalModulePath = Join-Path $PSScriptRoot '../internal/Az.Policy.internal.psm1'
77
if(Test-Path $internalModulePath) {
88
$null = Import-Module -Name $internalModulePath
99
}

src/Resources/Policy.Autorest/custom/New-AzPolicyAssignment.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ param(
113113
[Parameter(ValueFromPipelineByPropertyName)]
114114
[ValidateNotNullOrEmpty()]
115115
[ValidateSet('Default', 'DoNotEnforce')]
116+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.PSArgumentCompleterAttribute('Default', 'DoNotEnforce')]
116117
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
117118
[System.String]
118119
# The policy assignment enforcement mode.
@@ -121,6 +122,7 @@ param(
121122

122123
[Parameter()]
123124
[ValidateSet('None', 'SystemAssigned', 'UserAssigned')]
125+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.PSArgumentCompleterAttribute('None', 'SystemAssigned', 'UserAssigned')]
124126
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
125127
[System.String]
126128
# The identity type.

src/Resources/Policy.Autorest/custom/New-AzPolicyExemption.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ param(
5252

5353
[Parameter(ValueFromPipelineByPropertyName)]
5454
[ValidateSet('Default', 'DoNotValidate')]
55+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.PSArgumentCompleterAttribute('Default', 'DoNotValidate')]
5556
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
5657
[System.String]
5758
# Whether to validate the exemption is at or under the assignment scope.
@@ -71,6 +72,7 @@ param(
7172

7273
[Parameter(ParameterSetName='Default', Mandatory, ValueFromPipelineByPropertyName)]
7374
[ValidateSet('Waiver', 'Mitigated')]
75+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.PSArgumentCompleterAttribute('Waiver', 'Mitigated')]
7476
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Path')]
7577
[System.String]
7678
# The policy exemption category
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.Policy` 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.Policy.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.Policy` 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.Policy.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.Policy.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.Policy`. 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.Policy.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.Policy.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.Policy`.
38+
- `Microsoft.Azure.PowerShell.Cmdlets.Policy.InternalExportAttribute`
39+
- Used in C# cmdlets to route exported cmdlets to the `../internal`, which are *not exposed* by `Az.Policy`. For more information, see [README.md](../internal/README.md) in the `../internal` folder.
40+
- `Microsoft.Azure.PowerShell.Cmdlets.Policy.ProfileAttribute`
41+
- Used in C# and script cmdlets to define which Azure profiles the cmdlet supports. This is only supported for Azure (`--azure`) modules.

src/Resources/Policy.Autorest/custom/Update-AzPolicyAssignment.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ param(
124124
[Parameter(ValueFromPipelineByPropertyName)]
125125
[ValidateNotNullOrEmpty()]
126126
[ValidateSet('Default', 'DoNotEnforce')]
127+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.PSArgumentCompleterAttribute('Default', 'DoNotEnforce')]
127128
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
128129
[System.String]
129130
# The policy assignment enforcement mode.
@@ -132,6 +133,7 @@ param(
132133

133134
[Parameter()]
134135
[ValidateSet('None', 'SystemAssigned', 'UserAssigned')]
136+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.PSArgumentCompleterAttribute('None', 'SystemAssigned', 'UserAssigned')]
135137
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
136138
[System.String]
137139
# The identity type.

src/Resources/Policy.Autorest/custom/Update-AzPolicyExemption.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ param(
7474

7575
[Parameter(ValueFromPipelineByPropertyName)]
7676
[ValidateSet('Waiver', 'Mitigated')]
77+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.PSArgumentCompleterAttribute('Waiver', 'Mitigated')]
7778
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Path')]
7879
[System.String]
7980
# The policy exemption category
@@ -115,6 +116,7 @@ param(
115116

116117
[Parameter()]
117118
[ValidateSet('Default', 'DoNotValidate')]
119+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.PSArgumentCompleterAttribute('Default', 'DoNotValidate')]
118120
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
119121
[System.String]
120122
# The option whether validate the exemption is at or under the assignment scope.

src/Resources/Policy.Autorest/help/Az.Policy.md renamed to src/Resources/Policy.Autorest/docs/Az.Policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Module Name: Az.Policy
3-
Module Guid: 54d436a4-6f2e-4977-b339-2b40665fd8c4
3+
Module Guid: 28bf853b-7409-4d2c-bb4a-9c72f30e9a09
44
Download Help Link: https://learn.microsoft.com/powershell/module/az.policy
55
Help Version: 1.0.0.0
66
Locale: en-US
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Docs
2-
This directory contains the documentation of the cmdlets for the `Az.Policy` 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.
2+
This directory contains the documentation of the cmdlets for the `Az.Policy` 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.
33

44
## Info
55
- Modifiable: no
@@ -8,4 +8,4 @@ This directory contains the documentation of the cmdlets for the `Az.Policy` mod
88
- Packaged: yes
99

1010
## Details
11-
The process of documentation generation loads `Az.Policy` 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.
11+
The process of documentation generation loads `Az.Policy` 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.

src/Resources/Policy.Autorest/export-surface.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if(-not $NotIsolated) {
2222
return
2323
}
2424

25-
$dll = Join-Path $PSScriptRoot 'bin\Az.Policy.private.dll'
25+
$dll = Join-Path $PSScriptRoot 'bin/Az.Policy.private.dll'
2626
if(-not (Test-Path $dll)) {
2727
Write-Error "Unable to find output assembly in '$binFolder'."
2828
}

src/Resources/Policy.Autorest/generate-info.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)