Skip to content

Fix for issue #7479 #7592

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 2 commits into from
Oct 16, 2018
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 @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Current Release
* Fix isssue where Get-AzureRMRoleDefinition throws an unintelligible excpetion (when the default profile has no subscription in it and no scope is specified) by adding a meaningful exception in the scenario. Also set the default param set to `RoleDefinitionNameParameterSet`.

## Version 6.6.0
* Add missing -Mode parameter to Set-AzureRmPolicyDefinition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.Resources
/// <summary>
/// Get the available role Definitions for certain resource types.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RoleDefinition"), OutputType(typeof(PSRoleDefinition))]
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RoleDefinition", DefaultParameterSetName = ParameterSet.RoleDefinitionName), OutputType(typeof(PSRoleDefinition))]
public class GetAzureRoleDefinitionCommand : ResourcesBaseCmdlet
{
[Parameter(Position = 0, Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleDefinitionName, HelpMessage = "Role definition name. For e.g. Reader, Contributor, Virtual Machine Contributor.")]
Expand Down Expand Up @@ -54,15 +54,25 @@ public override void ExecuteCmdlet()
Scope = Scope,
ResourceIdentifier = new ResourceIdentifier
{
Subscription = DefaultProfile.DefaultContext.Subscription.Id.ToString()
Subscription = DefaultProfile.DefaultContext.Subscription.Id?.ToString()
},
RoleDefinitionId = Id,
RoleDefinitionName = Name,
};

if (options.Scope == null && options.ResourceIdentifier.Subscription == null)
{
WriteTerminatingError("No subscription was found in the default profile and no scope was specified. Either specify a scope or use a tenant with a subscription to run the command.");
}

AuthorizationClient.ValidateScope(options.Scope, true);

WriteObject(PoliciesClient.FilterRoleDefinitions(options), enumerateCollection: true);
}

private void WriteTerminatingError(string message, params object[] args)
{
ThrowTerminatingError(new ErrorRecord(new Exception(String.Format(message, args)), "Error", ErrorCategory.NotSpecified, null));
}
}
}