Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/Resources/Policy.Autorest/Az.Policy.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RequiredAssemblies = './bin/Az.Policy.private.dll'
FormatsToProcess = './Az.Policy.format.ps1xml'
ScriptsToProcess = @('./custom/Helpers.ps1')
FunctionsToExport = 'Get-AzPolicyAssignment', 'Get-AzPolicyDefinition', 'Get-AzPolicyExemption', 'Get-AzPolicySetDefinition', 'LocationCompleter', 'New-AzPolicyAssignment', 'New-AzPolicyDefinition', 'New-AzPolicyExemption', 'New-AzPolicySetDefinition', 'Remove-AzPolicyAssignment', 'Remove-AzPolicyDefinition', 'Remove-AzPolicyExemption', 'Remove-AzPolicySetDefinition', 'Update-AzPolicyAssignment', 'Update-AzPolicyDefinition', 'Update-AzPolicyExemption', 'Update-AzPolicySetDefinition'
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 = @{
Expand Down
103 changes: 0 additions & 103 deletions src/Resources/Policy.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
This directory contains the PowerShell module for the Policy service.

---
## Status
[![Az.Policy](https://img.shields.io/powershellgallery/v/Az.Policy.svg?style=flat-square&label=Az.Policy "Az.Policy")](https://www.powershellgallery.com/packages/Az.Policy/)

## Info
- Modifiable: yes
- Generated: all
Expand Down Expand Up @@ -133,106 +130,6 @@ directive:
script: '{ "" }'
hide: true

# Rename and hide Name and SubscriptionId parameters on Get-AzPolicySetDefinition
# to allow customizing control over parameter bindings to match current SDK cmdlets
- where:
verb: Get
subject: PolicyDefinition|PolicyDefinitionVersion|PolicySetDefinition|PolicySetDefinitionVersion
parameter-name: Name
set:
parameter-name: NameInternal
default:
name: DefaultName
description: Need a placeholder to keep autorest happy
script: '"PlaceholderName"'
hide: true
clear-alias: true
- where:
verb: Get
subject: PolicyDefinition|PolicyDefinitionVersion|PolicySetDefinition|PolicySetDefinitionVersion
parameter-name: SubscriptionId
set:
parameter-name: SubscriptionIdInternal
default:
name: DefaultSubscriptionId
description: Need a placeholder to keep autorest happy
script: '(Get-AzContext).Subscription.Id'
hide: true

# Rename and hide identity parameters on *-AzPolicyAssignment. This is required
# because autorest generation handles these paramters specially and applies their
# own parameter set bindings. We need to customize control over parameter bindings
# to match the behavior of the current SDK cmdlets.
- where:
subject: PolicyAssignment
parameter-name: Name
set:
parameter-name: NameInternal
default:
name: DefaultName
description: Need a placeholder to keep autorest happy
script: '"PlaceholderName"'
hide: true
clear-alias: true
- where:
subject: PolicyAssignment
parameter-name: Scope
set:
parameter-name: ScopeInternal
default:
name: DefaultScope
description: Need a placeholder to keep autorest happy
script: "/subscriptions/((Get-AzContext).Subscription.Id)"
hide: true
- where:
subject: PolicyAssignment
parameter-name: Id
set:
parameter-name: IdInternal
default:
name: DefaultId
description: Need a placeholder to keep autorest happy
script: '"PlaceholderId"'
hide: true
clear-alias: true

# Rename and hide identity parameters on *-AzPolicyExemption. This is required
# because autorest generation handles these paramters specially and applies their
# own parameter set bindings. We need to customize control over parameter bindings
# to match the behavior of the current SDK cmdlets.
- where:
subject: PolicyExemption
parameter-name: Name
set:
parameter-name: NameInternal
default:
name: DefaultName
description: Need a placeholder to keep autorest happy
script: '"PlaceholderName"'
hide: true
clear-alias: true
- where:
subject: PolicyExemption
parameter-name: Scope
set:
parameter-name: ScopeInternal
default:
name: DefaultScope
description: Need a placeholder to keep autorest happy
script: "/subscriptions/((Get-AzContext).Subscription.Id)"
hide: true
- where:
subject: PolicyExemption
parameter-name: Id
set:
parameter-name: IdInternal
default:
name: DefaultId
description: Need a placeholder to keep autorest happy
script: '"PlaceholderId"'
hide: true
clear-alias: true

# Need to change ExpiresOn to a nullable DateTime (not supported by autorest)
- where:
verb: New
Expand Down
17 changes: 8 additions & 9 deletions src/Resources/Policy.Autorest/custom/Get-AzPolicyAssignment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ process {

if ($Name) {
$calledParameterSet = 'Get'
$calledParameters.NameInternal = $Name
$calledParameters.Name = $Name

if (!$Scope) {
$Scope = "/subscriptions/$($(Get-AzContext).Subscription.Id)"
$Scope = "/subscriptions/$($(Get-SubscriptionId))"
}

$calledParameters.ScopeInternal = $Scope
$calledParameters.Scope = $Scope
}
elseif ($Id) {
$calledParameterSet = 'Get1'
$calledParameters.IdInternal = $Id
$calledParameters.Id = $Id
}
else {
# set up filter values for list case
Expand Down Expand Up @@ -234,18 +234,17 @@ process {
'none' {
# This will fail, but return a helpful message
$calledParameterSet = 'Get1'
$calledParameters = @{ IdInternal = $resolved.Scope }
$calledParameters = @{ Id = $resolved.Scope }
}
}
}
else {
$calledParameters.SubscriptionId = @((Get-AzContext).Subscription.Id)
$calledParameters.SubscriptionId = @(Get-SubscriptionId)
}

$null = $calledParameters.Remove('Scope')
}

$null = $calledParameters.Remove('Name')
$null = $calledParameters.Remove('Scope')
$null = $calledParameters.Remove('Id')
$null = $calledParameters.Remove('PolicyDefinitionId')
$null = $calledParameters.Remove('IncludeDescendent')
$null = $calledParameters.Remove('BackwardCompatible')
Expand Down
11 changes: 3 additions & 8 deletions src/Resources/Policy.Autorest/custom/Get-AzPolicyDefinition.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ process {
else {
$calledParameterSet = 'List';
}

# rename subscription parameter to internal version
$PSBoundParameters['SubscriptionIdInternal'] = $PSBoundParameters['SubscriptionId']

}
elseif ($PSBoundParameters['ManagementGroupName']) {
$PSBoundParameters['ManagementGroupId'] = $PSBoundParameters['ManagementGroupName']
Expand All @@ -255,7 +251,7 @@ process {
}
}
elseif ($parameterSet -ne 'Id') {
$PSBoundParameters['SubscriptionIdInternal'] = (Get-AzContext).Subscription.Id
$PSBoundParameters['SubscriptionId'] = (Get-SubscriptionId)
if ($PSBoundParameters['Name']) {
$calledParameterSet = 'Get'
}
Expand All @@ -264,7 +260,6 @@ process {

# remove parameters not used by generated cmdlets
$null = $PSBoundParameters.Remove('BackwardCompatible')
$null = $PSBoundParameters.Remove('SubscriptionId')
$null = $PSBoundParameters.Remove('ManagementGroupName')
$null = $PSBoundParameters.Remove('Id')
$null = $PSBoundParameters.Remove('BuiltIn')
Expand All @@ -285,12 +280,12 @@ process {
$output = Invoke-Command -ScriptBlock $scriptCmd
}
catch {
if (($_.Exception.Message -like '*PolicyDefinitionNotFound*') -and $PSBoundParameters.Name -and $PSBoundParameters.SubscriptionIdInternal) {
if (($_.Exception.Message -like '*PolicyDefinitionNotFound*') -and $PSBoundParameters.Name -and $PSBoundParameters.SubscriptionId) {

# failed by name at subscription level, try builtins
$PSBoundParameters.PolicyDefinitionName = $PSBoundParameters.Name
$null = $PSBoundParameters.Remove('Name')
$null = $PSBoundParameters.Remove('SubscriptionIdInternal')
$null = $PSBoundParameters.Remove('SubscriptionId')
$cmdInfo = Get-Command -Name $mapping['BuiltInGet']
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.MessageAttributeHelper]::ProcessCustomAttributesAtRuntime($cmdInfo, $MyInvocation, $calledParameterSet, $PSCmdlet)
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping['BuiltInGet']), [System.Management.Automation.CommandTypes]::Cmdlet)
Expand Down
54 changes: 5 additions & 49 deletions src/Resources/Policy.Autorest/custom/Get-AzPolicyExemption.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,45 +83,6 @@ param(
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
${InputObject},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Path')]
[System.String[]]
# The ID of the target subscription.
${SubscriptionId},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Path')]
[System.String]
# The name of the resource group containing the resource.
${ResourceGroupName},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Path')]
[System.String]
# The parent resource path.
# Use empty string if there is none.
${ParentResourcePath},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Path')]
[System.String]
# The name of the resource.
${ResourceName},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Path')]
[System.String]
# The namespace of the resource provider.
# For example, the namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines)
${ResourceProviderNamespace},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Path')]
[System.String]
# The resource type name.
# For example the type name of a web app is 'sites' (from Microsoft.Web/sites).
${ResourceType},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Query')]
[System.String]
Expand Down Expand Up @@ -211,10 +172,6 @@ process {

$calledParameters = $PSBoundParameters

# SubscriptionId is autorest-generated and mandatory so gets populated with default value.
# This customized cmdlet doesn't allow/use it, so we must remove it, otherwise the parameter set is broken.
$null = $calledParameters.Remove('SubscriptionId')

if ($Id) {
$parsed = ParsePolicyExemptionId $Id

Expand All @@ -228,13 +185,13 @@ process {
}

if (!$Scope) {
$Scope = "/subscriptions/$($(Get-AzContext).Subscription.Id)"
$Scope = "/subscriptions/$($(Get-SubscriptionId))"
}

if ($Name) {
$calledParameterSet = 'Get'
$calledParameters.NameInternal = $Name
$calledParameters.ScopeInternal = $Scope
$calledParameters.Name = $Name
$calledParameters.Scope = $Scope
}
else {
# set up filter values for list case
Expand Down Expand Up @@ -282,12 +239,11 @@ process {
}
}
}

$null = $calledParameters.Remove('Scope')
}

$null = $calledParameters.Remove('Name')
$null = $calledParameters.Remove('Scope')
$null = $calledParameters.Remove('Id')

$null = $calledParameters.Remove('PolicyAssignmentIdFilter')
$null = $calledParameters.Remove('IncludeDescendent')
$null = $calledParameters.Remove('BackwardCompatible')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ process {
else {
$calledParameterSet = 'List';
}

# rename subscription parameter to internal version
$PSBoundParameters['SubscriptionIdInternal'] = $PSBoundParameters['SubscriptionId']

}
elseif ($PSBoundParameters['ManagementGroupName']) {
$PSBoundParameters['ManagementGroupId'] = $PSBoundParameters['ManagementGroupName']
Expand All @@ -245,7 +241,7 @@ process {
}
}
elseif ($parameterSet -ne 'Id') {
$PSBoundParameters['SubscriptionIdInternal'] = (Get-AzContext).Subscription.Id
$PSBoundParameters['SubscriptionId'] = (Get-SubscriptionId)
if ($PSBoundParameters['Name']) {
$calledParameterSet = 'Get'
}
Expand All @@ -254,7 +250,6 @@ process {

# remove parameters not used by generated cmdlets
$null = $PSBoundParameters.Remove('BackwardCompatible')
$null = $PSBoundParameters.Remove('SubscriptionId')
$null = $PSBoundParameters.Remove('ManagementGroupName')
$null = $PSBoundParameters.Remove('Id')
$null = $PSBoundParameters.Remove('BuiltIn')
Expand All @@ -274,12 +269,12 @@ process {
$output = Invoke-Command -ScriptBlock $scriptCmd
}
catch {
if (($_.Exception.Message -like '*PolicySetDefinitionNotFound*') -and $PSBoundParameters.Name -and $PSBoundParameters.SubscriptionIdInternal) {
if (($_.Exception.Message -like '*PolicySetDefinitionNotFound*') -and $PSBoundParameters.Name -and $PSBoundParameters.SubscriptionId) {

# failed by name at subscription level, try builtins
$PSBoundParameters.PolicySetDefinitionName = $PSBoundParameters.Name
$null = $PSBoundParameters.Remove('Name')
$null = $PSBoundParameters.Remove('SubscriptionIdInternal')
$null = $PSBoundParameters.Remove('SubscriptionId')

$cmdInfo = Get-Command -Name $mapping['BuiltInGet']
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.MessageAttributeHelper]::ProcessCustomAttributesAtRuntime($cmdInfo, $MyInvocation, $calledParameterSet, $PSCmdlet)
Expand Down
Loading