Skip to content

Commit 0643bfd

Browse files
Returning error if insufficient user permissions are there for GetAgentRegistrationInfo (#16965)
* added permission check * targetting only the required cmdlet * updating changelog.md * Update ChangeLog.md Co-authored-by: Yunchi Wang <[email protected]>
1 parent 4a160e9 commit 0643bfd

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

src/Automation/Automation/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
-->
2020
## Upcoming Release
2121

22+
## Version *
23+
* Added logic of returning error if insufficient user permissions are there for `GetAgentRegistrationInfo`
24+
2225
## Version 1.7.3
2326
* `New-AzAutomationSchedule` allows defnining StartTime with offsets.
2427
* Fixed bug: updated 'Set-AzAutomationModule' to use PUT call while updating modules with specific versions [#12552]

src/Automation/Automation/Cmdlet/GetAzureAutomationAgentRegistrationInformation.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using System.Collections.Generic;
1717
using System.Management.Automation;
1818
using System.Security.Permissions;
19+
using Microsoft.Azure.Commands.Automation.Common;
20+
using Microsoft.Azure.Commands.Automation.Properties;
1921

2022
namespace Microsoft.Azure.Commands.Automation.Cmdlet
2123
{
@@ -34,11 +36,18 @@ public override void ExecuteCmdlet()
3436
{
3537
IEnumerable<AgentRegistration> ret = null;
3638

39+
var agentRegInfo = this.AutomationClient.GetAgentRegistration(
40+
this.ResourceGroupName,
41+
this.AutomationAccountName);
42+
43+
if (agentRegInfo.PrimaryKey == null && agentRegInfo.SecondaryKey == null)
44+
{
45+
throw new AzureAutomationOperationException(Resources.InsufficientUserPermissions);
46+
}
47+
3748
ret = new List<AgentRegistration>
3849
{
39-
this.AutomationClient.GetAgentRegistration(
40-
this.ResourceGroupName,
41-
this.AutomationAccountName)
50+
agentRegInfo
4251
};
4352

4453
this.GenerateCmdletOutput(ret);

src/Automation/Automation/Model/AgentRegistration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public AgentRegistration(string resourceGroupName, string automationAccountName,
4141

4242
this.ResourceGroupName = resourceGroupName;
4343
this.AutomationAccountName = automationAccountName;
44+
4445
if (agentRegistration.Keys != null)
4546
{
4647
this.PrimaryKey = agentRegistration.Keys.Primary;

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

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

src/Automation/Automation/Properties/Resources.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,8 @@
497497
<data name="SoftwareUpdateConfigurationInvalidTagFormat" xml:space="preserve">
498498
<value>The Tag format is invalid. Valid Tag format is hashtable with string key and value of String or array of string.</value>
499499
</data>
500+
<data name="InsufficientUserPermissions" xml:space="preserve">
501+
<value>Insufficient user permissions. Please refer https://docs.microsoft.com/azure/role-based-access-control/built-in-roles for more details.</value>
502+
<comment>Automation</comment>
503+
</data>
500504
</root>

0 commit comments

Comments
 (0)