Skip to content

Move Policy CRUD cmdlets to autorest generation: fixes (#23518) #24221

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 24 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7148d1e
Move Policy CRUD cmdlets to autorest generation: fixes (#23518)
mentat9 Nov 22, 2023
a9229ad
Update to autorest 4.x (#24319)
mentat9 Mar 8, 2024
175c597
Update Policy CRUD cmdlets (#24361)
mentat9 Mar 14, 2024
d0bfbf4
Fix calculation for $testFilesFolder on macOS/linux (#24408)
mentat9 Mar 20, 2024
0b48f4e
Hide generated parameter sets for New-* (#24507)
mentat9 Mar 26, 2024
5ae5ed0
Replace Get-AzContext with Utils\Get-SubscriptionIdTestSafe (#24540)
mentat9 Mar 28, 2024
656a440
Apply changes to support -Playback mode (#24555)
mentat9 Apr 1, 2024
f43da67
move creation of resource group to utils.ps1
VeryEarly Apr 1, 2024
c7a8496
Test tweaks (#24566)
mentat9 Apr 2, 2024
c27c2a9
fix test cases
VeryEarly Apr 2, 2024
aa053e9
Correct location handling, fix tests and consistency (#24573)
mentat9 Apr 3, 2024
f6e923c
sync with latest generation branch
VeryEarly Apr 8, 2024
7b4b00a
remove unnecessary script
VeryEarly Apr 8, 2024
d8b37d7
change cached location with a more unique name
VeryEarly Apr 9, 2024
6a518cc
update execution of util script
VeryEarly Apr 9, 2024
67008a2
fix positional parameters generated when only default parameter set
VeryEarly Apr 9, 2024
e3e55fd
fix erroraction for Get-AzPolicyDefinition
VeryEarly Apr 12, 2024
6122e7d
Apply feedback (#24757)
mentat9 Apr 30, 2024
a02e65c
sync generation
VeryEarly May 7, 2024
f349ad0
sync static analysis exceptions
VeryEarly May 7, 2024
1e0eb2f
Merge branch 'generation' into generation-Resources-preview
VeryEarly May 7, 2024
0cefc43
remove redundant
VeryEarly May 7, 2024
b1da604
Merge remote-tracking branch 'origin/generation-Resources-preview' in…
VeryEarly May 7, 2024
9543882
added file accidentally removed
VeryEarly May 8, 2024
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
2 changes: 1 addition & 1 deletion src/EdgeZones/EdgeZones.Autorest/test/loadEnv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ if (Test-Path -Path (Join-Path $PSScriptRoot $envFile)) {
$env = @{}
if (Test-Path -Path $envFilePath) {
$env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json
$PSDefaultParameterValues=@{"*:SubscriptionId"=$env.SubscriptionId; "*:Tenant"=$env.Tenant}
$PSDefaultParameterValues=@{"*:Tenant"=$env.Tenant}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ function setupEnv() {
}
function cleanupEnv() {
# Clean resources you create for testing
}

}
1 change: 1 addition & 0 deletions src/Resources/Policy.Autorest/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
16 changes: 16 additions & 0 deletions src/Resources/Policy.Autorest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bin
obj
.vs
generated
internal
exports
tools
custom/*.psm1
custom/autogen-model-cmdlets
test/*-TestResults.xml
/*.ps1
/*.ps1xml
/*.psm1
/*.snk
/*.csproj
/*.nuspec
25 changes: 25 additions & 0 deletions src/Resources/Policy.Autorest/Az.Policy.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@{
GUID = '54d436a4-6f2e-4977-b339-2b40665fd8c4'
RootModule = './Az.Policy.psm1'
ModuleVersion = '0.1.1'
CompatiblePSEditions = 'Core', 'Desktop'
Author = 'Microsoft Corporation'
CompanyName = 'Microsoft Corporation'
Copyright = 'Microsoft Corporation. All rights reserved.'
Description = 'Microsoft Azure PowerShell: Policy cmdlets'
PowerShellVersion = '5.1'
DotNetFrameworkVersion = '4.7.2'
RequiredAssemblies = './bin/Az.Policy.private.dll'
FormatsToProcess = './Az.Policy.format.ps1xml'
ScriptsToProcess = @('./custom/Helpers.ps1')
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'
AliasesToExport = 'Set-AzPolicyAssignment', 'Set-AzPolicyDefinition', 'Set-AzPolicyExemption', 'Set-AzPolicySetDefinition'
PrivateData = @{
PSData = @{
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'Policy'
LicenseUri = 'https://aka.ms/azps-license'
ProjectUri = 'https://github.com/Azure/azure-powershell'
ReleaseNotes = ''
}
}
}
25 changes: 25 additions & 0 deletions src/Resources/Policy.Autorest/Az.Policy.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34003.232
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Az.Policy", "Az.Policy.csproj", "{E1516122-D175-4776-84D1-CFCC38F34A9C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E1516122-D175-4776-84D1-CFCC38F34A9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1516122-D175-4776-84D1-CFCC38F34A9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1516122-D175-4776-84D1-CFCC38F34A9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1516122-D175-4776-84D1-CFCC38F34A9C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9256CB53-1F25-4B11-9300-554991740A15}
EndGlobalSection
EndGlobal
262 changes: 262 additions & 0 deletions src/Resources/Policy.Autorest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
<!-- region Generated -->
# Az.Policy
This directory contains the PowerShell module for the Policy service.

---
## Info
- Modifiable: yes
- Generated: all
- Committed: yes
- Packaged: yes

---
## Detail
This module was primarily generated via [AutoRest](https://github.com/Azure/autorest) using the [PowerShell](https://github.com/Azure/autorest.powershell) extension.

## Module Requirements
- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.7.5 or greater

## Authentication
AutoRest does not generate authentication code for the module. Authentication is handled via Az.Accounts by altering the HTTP payload before it is sent.

## Development
For information on how to develop for `Az.Policy`, see [how-to.md](how-to.md).
<!-- endregion -->

### AutoRest Configuration
> see https://aka.ms/autorest

``` yaml
# Please specify the commit id that includes your features to make sure generated codes stable.
commit: 33da947dfea91e16a4e62c663a13de4f0fa72251
require:
# readme.azure.noprofile.md is the common configuration file
- $(this-folder)/../../readme.azure.noprofile.md
input-file:
# You need to specify your swagger files here.
- $(repo)/specification/resources/resource-manager/Microsoft.Authorization/stable/2023-04-01/policyDefinitions.json
- $(repo)/specification/resources/resource-manager/Microsoft.Authorization/stable/2023-04-01/policySetDefinitions.json
- $(repo)/specification/resources/resource-manager/Microsoft.Authorization/stable/2023-04-01/policyDefinitionVersions.json
- $(repo)/specification/resources/resource-manager/Microsoft.Authorization/stable/2023-04-01/policySetDefinitionVersions.json
- $(repo)/specification/resources/resource-manager/Microsoft.Authorization/stable/2023-04-01/policyAssignments.json
- $(repo)/specification/resources/resource-manager/Microsoft.Authorization/preview/2022-07-01-preview/policyExemptions.json
# If the swagger has not been put in the repo, you may uncomment the following line and refer to it locally
# - ..\..\..\..\azure-rest-api-specs\specification\resources\resource-manager\Microsoft.Authorization\stable\2023-04-01\policyDefinitionVersions.json
# - ..\..\..\..\azure-rest-api-specs\specification\resources\resource-manager\Microsoft.Authorization\stable\2023-04-01\policySetDefinitionVersions.json

# For new RP, the version is 0.1.1
module-version: 0.1.1
# Normally, title is the service name
root-module-name: $(prefix).Resources
title: Policy
subject-prefix: Policy

# If there are post APIs for some kinds of actions in the RP, you may need to
# uncomment following line to support viaIdentity for these post APIs
# identity-correction-for-post: true

# For new modules, please avoid setting 3.x using the use-extension method and instead, use 4.x as the default option
#use-extension:
# "@autorest/powershell": "3.x"
azure: true
resourcegroup-append: false
identity-correction-for-post: false
export-properties-for-dict: false
nested-object-to-string: false

directive:
# Following is two common directive which are normally required in all the RPs
# 1. Remove the unexpanded parameter set
# 2. For New-* cmdlets, ViaIdentity is not required, so CreateViaIdentityExpanded is removed as well
- where:
variant: ^Create$|^CreateViaIdentity.*$|^CreateViaIdentityExpanded$|^Update$|^UpdateViaIdentity$
remove: true
# Remove the set-* cmdlet
- where:
verb: Set
remove: true
- where:
verb: New|Update
variant: ^(Create|Update)(?!.*?Expanded)
remove: true
# Remove ManagementGroupInputObject parameter for all cmdlets, since it's not supported
- where:
variant: ^(Get|Delete|Update)ViaIdentityManagementGroup(Expanded)?$
remove: true

# Hide separate cmdlets generated for tenant-level GETs. These are used by Get-AzPolicy*
# customization to match behavior of current SDK cmdlets.
- where:
subject: .*Built
hide: true

# Create aliases of Set-*, since they are not supported/generated by autorest.powershell
# They are provide in the new policy module for compatibility with current SDK module.
# Since neither definitions nor set definitions generate Update-* cmdlets, both
# Set-* and Update-* cmdlets are implemented by wrapping the generated New-* cmdlets.
- where:
verb: Update
subject: PolicyAssignment
set:
alias:
Set-AzPolicyAssignment
- where:
verb: Update
subject: PolicyExemption
set:
alias:
Set-AzPolicyExemption

# Hide generated ManagementGroupId parameter for all cmdlets
# since previous SDK cmdlets always used ManagementGroupName
- where:
parameter-name: ManagementGroupId
set:
default:
name: DefaultManagementGroupId
description: Need a placeholder to keep autorest happy
script: '{ "" }'
hide: true

# Hide extra parameters likely to be confusing in new cmdlets
- where:
verb: New
subject: PolicyExemption
parameter-name: PolicyAssignmentId
set:
default:
name: DefaultAssignmentId
description: Need a placeholder to keep autorest happy
script: '{ "" }'
hide: true

# Need to change ExpiresOn to a nullable DateTime (not supported by autorest)
- where:
verb: New
subject: PolicyExemption
parameter-name: ExpiresOn
set:
parameter-name: ExpiresOnInternal
default:
name: DefaultExpiresOn
description: Need a placeholder to keep autorest happy
script: '"PlaceholderExpiresOn"'
hide: true
clear-alias: true

# Transform empty object definitions (e.g. policyRule, metadata) so they are generated as
# hashtable, otherwise their values are discarded
- from: swagger-document
where: $.definitions.PolicyAssignmentProperties.properties.metadata
transform: $['additionalProperties'] = true
- from: swagger-document
where: $.definitions.PolicyDefinitionProperties.properties.policyRule
transform: $['additionalProperties'] = true
- from: swagger-document
where: $.definitions.PolicyDefinitionProperties.properties.metadata
transform: $['additionalProperties'] = true
- from: swagger-document
where: $.definitions.PolicySetDefinitionProperties.properties.metadata
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicyExemptionProperties.properties.metadata
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicySetDefinitionProperties.properties.policyDefinition.policyDefinitionId
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicySetDefinitionProperties.properties.policyDefinition.parameters
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicySetDefinitionProperties.properties.policyDefinition.policyDefinitionReferenceId
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicySetDefinitionProperties.properties.policyDefinition.groupNames
transform: $['additionalProperties'] = true;

# previous approach that partially supported "any type" serialization
- from: swagger-document
where: $.definitions.ParameterDefinitionsValue.properties.allowedValues.items
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.ParameterDefinitionsValue.properties.defaultValue
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.ParameterValues
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.ParameterDefinitions
transform: $['additionalProperties'] = true;

# Rename generated hashtable parameters to avoid type mismatch, since generated code
# uses hashtable and previous SDK cmdlets use [JSON] string. Note, removing any
# of these will cause builds to fail, since a parameter is not allowed to be
# multiple types.
- where:
parameter-name: Metadata
set:
parameter-name: MetadataTable
hide: true
- where:
parameter-name: Parameter
set:
parameter-name: ParameterTable
hide: true
- where:
parameter-name: PolicyDefinition
set:
parameter-name: PolicyDefinitionTable
hide: true
- where:
parameter-name: PolicySetDefinition
set:
parameter-name: PolicySetDefinitionTable
hide: true
- where:
parameter-name: PolicyDefinitionGroup
set:
parameter-name: PolicyDefinitionGroupTable
hide: true
- where:
parameter-name: NonComplianceMessage
set:
parameter-name: NonComplianceMessageTable
hide: true

# Hide parameters that aren't supported.
# For some reason these can't be hidden by hiding them in
# the custom folder so we have to do it here.
- where:
verb: New|Update
subject: PolicyAssignment|PolicyExemption
parameter-name: PolicyDefinitionId|ResourceSelector|Override
hide: true
- where:
verb: New
subject: PolicyDefinition
parameter-name: PolicyRule
hide: true
- where:
verb: New|Update
subject: PolicyDefinition|PolicySetDefinition
parameter-name: Version|PropertiesVersions
hide: true
- where:
verb: Get
parameter-name: Top
hide: true

# Remove or hide cmdlets that are customized or not supported at all
- where:
verb: New|Get|Remove|Update
hide: true
- where:
verb: New|Remove|Update
subject: PolicyDefinitionVersion|PolicySetDefinitionVersion
remove: true

metadata:
scriptsToProcess:
- ./custom/Helpers.ps1

```
Loading