Skip to content

Commit b728076

Browse files
committed
Revert "[Az.Resources] Fix unexplicable error message when subscription and scope are both null. (#22730)"
This reverts commit 0e49447.
1 parent a6cf6ef commit b728076

File tree

9 files changed

+11
-49
lines changed

9 files changed

+11
-49
lines changed

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Reverted commits that caused regression in `Get-AzRoleAssignment`. [#22863]
2223

2324
## Version 6.11.0
2425
* Supported `TemplateParameterFile` to accept a `.bicepparam` file.

src/Resources/Resources/Models.ResourceGroups/ResourcesBaseCmdlet.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace Microsoft.Azure.Commands.Resources.Models
1717
{
1818
using Authorization;
1919
using ResourceManager.Common;
20-
using System.Management.Automation;
21-
using System;
2220

2321
/// <summary>
2422
/// Base class for all resources cmdlets
@@ -116,10 +114,5 @@ public virtual string DetermineParameterSetName()
116114
{
117115
return ParameterSetName;
118116
}
119-
120-
protected void WriteTerminatingError(string message, params object[] args)
121-
{
122-
ThrowTerminatingError(new ErrorRecord(new Exception(String.Format(message, args)), "Error", ErrorCategory.NotSpecified, null));
123-
}
124117
}
125118
}

src/Resources/Resources/Properties/Resources.Designer.cs

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/Resources/Properties/Resources.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,4 @@ This means the role assignment was not able to be created. Please assign a role
463463
<data name="SuccessfullRARemove" xml:space="preserve">
464464
<value>Succesfully removed role assignment for AD object '{0}' on scope '{1}' with role definition '{2}'</value>
465465
</data>
466-
<data name="ScopeAndSubscriptionNeitherProvided" xml:space="preserve">
467-
<value>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.</value>
468-
</data>
469466
</root>

src/Resources/Resources/RoleAssignments/GetAzureRoleAssignmentCommand.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Management.Automation;
24-
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
2524

2625
namespace Microsoft.Azure.Commands.Resources
2726
{
@@ -246,11 +245,6 @@ public override void ExecuteCmdlet()
246245
IncludeClassicAdministrators = IncludeClassicAdministrators.IsPresent,
247246
};
248247

249-
if (options.Scope == null && options.ResourceIdentifier.Subscription == null)
250-
{
251-
WriteTerminatingError(ProjectResources.ScopeAndSubscriptionNeitherProvided);
252-
}
253-
254248
AuthorizationClient.ValidateScope(options.Scope, true);
255249

256250
List<PSRoleAssignment> ra = PoliciesClient.FilterRoleAssignments(options, DefaultProfile.DefaultContext.Subscription.Id);

src/Resources/Resources/RoleAssignments/NewAzureRoleAssignmentCommand.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
using System;
2525
using System.IO;
2626
using System.Management.Automation;
27-
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
2827

2928
namespace Microsoft.Azure.Commands.Resources
3029
{
@@ -324,19 +323,14 @@ public override void ExecuteCmdlet()
324323
ResourceGroupName = ResourceGroupName,
325324
ResourceName = ResourceName,
326325
ResourceType = ResourceType,
327-
Subscription = DefaultProfile.DefaultContext.Subscription?.Id?.ToString(),
326+
Subscription = DefaultProfile.DefaultContext.Subscription != null ? DefaultProfile.DefaultContext.Subscription.Id : "",
328327
},
329328
CanDelegate = AllowDelegation.IsPresent ? true : false,
330329
Description = Description,
331330
Condition = Condition,
332331
ConditionVersion = ConditionVersion,
333332
};
334333

335-
if (parameters.Scope == null && parameters.ResourceIdentifier.Subscription == null)
336-
{
337-
WriteTerminatingError(ProjectResources.ScopeAndSubscriptionNeitherProvided);
338-
}
339-
340334
AuthorizationClient.ValidateScope(parameters.Scope, true);
341335

342336
WriteObject(PoliciesClient.CreateRoleAssignment(parameters, RoleAssignmentId));

src/Resources/Resources/RoleAssignments/RemoveAzureRoleAssignmentCommand.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,14 @@ public override void ExecuteCmdlet()
188188
ResourceGroupName = ResourceGroupName,
189189
ResourceName = ResourceName,
190190
ResourceType = ResourceType,
191-
Subscription = DefaultProfile.DefaultContext.Subscription?.Id?.ToString()
191+
Subscription = DefaultProfile.DefaultContext.Subscription.Id
192192
},
193193
// we should never expand principal groups in the Delete scenario
194194
ExpandPrincipalGroups = false,
195195
// never include classic administrators in the Delete scenario
196196
IncludeClassicAdministrators = false
197197
};
198198

199-
if (options.Scope == null && options.ResourceIdentifier.Subscription == null)
200-
{
201-
WriteTerminatingError(ProjectResources.ScopeAndSubscriptionNeitherProvided);
202-
}
203-
204199
AuthorizationClient.ValidateScope(options.Scope, true);
205200
ConfirmAction(
206201
string.Format(ProjectResources.RemovingRoleAssignment, ObjectId, Scope, RoleDefinitionName),

src/Resources/Resources/RoleDefinitions/GetAzureRoleDefinitionCommand.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using System.Collections.Generic;
2222
using System.Linq;
2323
using System.Management.Automation;
24-
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
2524

2625
namespace Microsoft.Azure.Commands.Resources
2726
{
@@ -62,15 +61,15 @@ public override void ExecuteCmdlet()
6261
Scope = Scope,
6362
ResourceIdentifier = new ResourceIdentifier
6463
{
65-
Subscription = DefaultProfile.DefaultContext.Subscription?.Id?.ToString()
64+
Subscription = DefaultProfile.DefaultContext.Subscription.Id?.ToString()
6665
},
6766
RoleDefinitionId = Id,
6867
RoleDefinitionName = Name,
6968
};
7069

7170
if (options.Scope == null && options.ResourceIdentifier.Subscription == null)
7271
{
73-
WriteTerminatingError(ProjectResources.ScopeAndSubscriptionNeitherProvided);
72+
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.");
7473
}
7574

7675
AuthorizationClient.ValidateScope(options.Scope, true);
@@ -88,7 +87,10 @@ public override void ExecuteCmdlet()
8887
WriteObject(filteredRoleDefinitions, enumerateCollection: true);
8988
}
9089
}
91-
92-
90+
91+
private void WriteTerminatingError(string message, params object[] args)
92+
{
93+
ThrowTerminatingError(new ErrorRecord(new Exception(String.Format(message, args)), "Error", ErrorCategory.NotSpecified, null));
94+
}
9395
}
9496
}

src/Resources/Resources/RoleDefinitions/RemoveAzureRoleDefinitionCommand.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,10 @@ public override void ExecuteCmdlet()
8989
Scope = Scope,
9090
ResourceIdentifier = new ResourceIdentifier
9191
{
92-
Subscription = DefaultProfile.DefaultContext.Subscription?.Id?.ToString()
92+
Subscription = DefaultProfile.DefaultContext.Subscription.Id.ToString()
9393
}
9494
};
9595

96-
if (options.Scope == null && options.ResourceIdentifier.Subscription == null)
97-
{
98-
WriteTerminatingError(ProjectResources.ScopeAndSubscriptionNeitherProvided);
99-
}
100-
10196
AuthorizationClient.ValidateScope(options.Scope, true);
10297

10398
ConfirmAction(

0 commit comments

Comments
 (0)