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
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private bool IsResourceGet(string resourceId)
/// </summary>
private string GetResourceId()
{
return this.Id ?? this.MakePolicyAssignmentId(this.Scope ?? $"/{Constants.Subscriptions}/{DefaultContext.Subscription.Id}", this.Name);
return this.Id ?? this.MakePolicyAssignmentId(this.Scope, this.Name);
}

private string GetFilterParam(string resourceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class NewAzurePolicyAssignmentCmdlet : PolicyCmdletBase, IDynamicParamete
/// <summary>
/// Gets or sets the policy assignment scope parameter
/// </summary>
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.NewPolicyAssignmentScopeHelp)]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.NewPolicyAssignmentScopeHelp)]
[ValidateNotNullOrEmpty]
public string Scope { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected JArray GetArrayFromParameter(string parameter, string parameterName)
protected string MakePolicyAssignmentId(string scope, string resourceName)
{
return ResourceIdUtility.GetResourceId(
resourceId: scope,
resourceId: scope ?? $"/{Constants.Subscriptions}/{DefaultContext.Subscription.Id}",
extensionResourceType: Constants.MicrosoftAuthorizationPolicyAssignmentType,
extensionResourceName: resourceName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public static class PolicyHelpStrings
/// Policy assignment cmdlet parameter help strings
/// </summary>
public const string GetPolicyAssignmentNameHelp = "The name of the policy assignment to get.";
public const string GetPolicyAssignmentScopeHelp = "The scope of the policy assignment to get, e.g. /providers/managementGroups/{managementGroupName}.";
public const string GetPolicyAssignmentScopeHelp = "The scope of the policy assignment to get, e.g. /providers/managementGroups/{managementGroupName}, defaults to current subscription.";
public const string GetPolicyAssignmentIdHelp = "The fully qualified policy assignment ID to get, including the scope, e.g. /subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}.";
public const string GetPolicyDefinitionFilterHelp = "Limits the list of returned policy assignments to those assigning the policy definition identified by this fully qualified Id.";
public const string GetPolicyAssignmentIncludeDescendentsHelp = "Causes the list of returned policy assignments to include all assignments related to the given scope, including those from ancestor scopes and those from descendent scopes.";
public const string GetPolicyAssignmentDoesNothingHelp = "This parameter is ignored if provided with -Name or -Id parameters.";
public const string NewPolicyAssignmentNameHelp = "The name of the new policy assignment.";
public const string NewPolicyAssignmentScopeHelp = "The scope of the new policy assignment, e.g. /providers/managementGroups/{managementGroupName}.";
public const string NewPolicyAssignmentScopeHelp = "The scope of the new policy assignment, e.g. /providers/managementGroups/{managementGroupName}, defaults to current subscription.";
public const string NewPolicyAssignmentNotScopesHelp = "The not scopes for the new policy assignment.";
public const string NewPolicyAssignmentDisplayNameHelp = "The display name for the new policy assignment.";
public const string NewPolicyAssignmentDescriptionHelp = "The description for the new policy assignment.";
Expand All @@ -38,10 +38,10 @@ public static class PolicyHelpStrings
public const string NewPolicyAssignmentEnforcementModeHelp = "The enforcement mode for the new policy assignment, e.g. Default, DoNotEnforce. It indicates whether a policy effect will be enforced or not during assignment creation and update. Please visit https://aka.ms/azure-policyAssignment-enforcement-mode for more information.";
public const string NewPolicyAssignmentSkuHelp = "A hash table which specifies sku properties. This parameter is deprecated and ignored.";
public const string RemovePolicyAssignmentNameHelp = "The name of the policy assignment to delete.";
public const string RemovePolicyAssignmentScopeHelp = "The scope of the policy assignment to delete, e.g. /providers/managementGroups/{managementGroupName}.";
public const string RemovePolicyAssignmentScopeHelp = "The scope of the policy assignment to delete, e.g. /providers/managementGroups/{managementGroupName}, defaults to current subscription.";
public const string RemovePolicyAssignmentIdHelp = "The fully qualified policy assignment ID to delete, including the scope, e.g. /subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}.";
public const string SetPolicyAssignmentNameHelp = "The name of the policy assignment to update.";
public const string SetPolicyAssignmentScopeHelp = "The scope of the policy assignment to update, e.g. /providers/managementGroups/{managementGroupName}.";
public const string SetPolicyAssignmentScopeHelp = "The scope of the policy assignment to update, e.g. /providers/managementGroups/{managementGroupName}, defaults to current subscription.";
public const string SetPolicyAssignmentNotScopesHelp = "The not scopes of the updated policy assignment.";
public const string SetPolicyAssignmentIdHelp = "The fully qualified ID of the policy assignment to update, including the scope, e.g. /subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}.";
public const string SetPolicyAssignmentDisplayNameHelp = "The display name of the updated policy assignment";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class RemoveAzurePolicyAssignmentCmdlet : PolicyCmdletBase
/// <summary>
/// Gets or sets the policy assignment scope parameter.
/// </summary>
[Parameter(ParameterSetName = PolicyCmdletBase.NameParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.RemovePolicyAssignmentScopeHelp)]
[Parameter(ParameterSetName = PolicyCmdletBase.NameParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.RemovePolicyAssignmentScopeHelp)]
[ValidateNotNullOrEmpty]
public string Scope { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public class SetAzurePolicyAssignmentCmdlet : PolicyCmdletBase
/// <summary>
/// Gets or sets the policy assignment scope parameter.
/// </summary>
[Parameter(ParameterSetName = PolicyCmdletBase.NameParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.SetPolicyAssignmentScopeHelp)]
[Parameter(ParameterSetName = PolicyCmdletBase.PolicyParameterNameObjectParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.SetPolicyAssignmentPolicyParameterObjectHelp)]
[Parameter(ParameterSetName = PolicyCmdletBase.PolicyParameterNameStringParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.SetPolicyParameterHelp)]
[Parameter(ParameterSetName = PolicyCmdletBase.NameParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.SetPolicyAssignmentScopeHelp)]
[Parameter(ParameterSetName = PolicyCmdletBase.PolicyParameterNameObjectParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.SetPolicyAssignmentPolicyParameterObjectHelp)]
[Parameter(ParameterSetName = PolicyCmdletBase.PolicyParameterNameStringParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = PolicyHelpStrings.SetPolicyParameterHelp)]
[ValidateNotNullOrEmpty]
public string Scope { get; set; }

Expand Down
23 changes: 12 additions & 11 deletions src/Resources/Resources.Test/ScenarioTests/PolicyTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ function Test-NewPolicyAssignmentParameters
Assert-ThrowsContains { New-AzPolicyAssignment } $missingParameters

# validate parameter combinations starting with -Name
Assert-ThrowsContains { New-AzPolicyAssignment -Name $someName } $missingParameters
Assert-ThrowsContains { New-AzPolicyAssignment -Name $someName } $invalidRequestContent
Assert-ThrowsContains { New-AzPolicyAssignment -Name $someName -Scope $goodScope } $invalidRequestContent
Assert-ThrowsContains { New-AzPolicyAssignment -Name $someName -Scope $someScope -PolicyDefinition $goodPolicyDefinition } $missingSubscription
Assert-ThrowsContains { New-AzPolicyAssignment -Name $someName -Scope $someScope -PolicyDefinition $goodPolicyDefinition -PolicySetDefinition $goodPolicySetDefinition } $onlyDefinitionOrSetDefinition
Expand Down Expand Up @@ -1245,7 +1245,8 @@ function Test-RemovePolicyAssignmentParameters
Assert-ThrowsContains { Remove-AzPolicyAssignment } $missingParameters

# validate parameter combinations starting with -Name
Assert-ThrowsContains { Remove-AzPolicyAssignment -Name $someName } $missingParameters
$ok = Remove-AzPolicyAssignment -Name $someName
Assert-AreEqual True $ok
$ok = Remove-AzPolicyAssignment -Name $someName -Scope $goodScope
Assert-AreEqual True $ok
Assert-ThrowsContains { Remove-AzPolicyAssignment -Name $someName -Id $someId } $parameterSetError
Expand Down Expand Up @@ -1277,17 +1278,17 @@ function Test-SetPolicyAssignmentParameters
Assert-ThrowsContains { Set-AzPolicyAssignment } $missingParameters

# validate parameter combinations starting with -Name
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Scope $goodScope } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -NotScope $someNotScope } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -NotScope $someNotScope } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Id $someId } $parameterSetError
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -DisplayName $someDisplayName } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Description $description } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Metadata $metadata } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -PolicyParameterObject $someParameterObject } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -PolicyParameter $someParameters } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -AssignIdentity } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Location $someLocation } $missingParameters
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -DisplayName $someDisplayName } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Description $description } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Metadata $metadata } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -PolicyParameterObject $someParameterObject } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -PolicyParameter $someParameters } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -AssignIdentity } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Location $someLocation } $policyAssignmentNotFound
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Scope $someScope -NotScope $someNotScope } $missingSubscription
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Scope $someScope -Id $someId } $parameterSetError
Assert-ThrowsContains { Set-AzPolicyAssignment -Name $someName -Scope $someScope -DisplayName $someDisplayName } $missingSubscription
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading