Skip to content

Commit b298eb7

Browse files
committed
Update RBAC internal functions for Azure
1 parent b7d9c4c commit b298eb7

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

core/api/azure/resourcemanagement/helpers/rbac/Get-MonkeyAzRoleAssignmentForObject.ps1

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Function Get-MonkeyAzRoleAssignmentForObject{
8484
api_version = '2022-04-01';
8585
}
8686
}
87+
#Set Null
88+
$p = $null
8789
}
8890
Process{
8991
switch ($PSCmdlet.ParameterSetName.ToLower()){
@@ -118,27 +120,39 @@ Function Get-MonkeyAzRoleAssignmentForObject{
118120
#Get current Id
119121
$objectId = $O365Object.clientApplicationId
120122
}
121-
#Set filter
122-
if($AtScope.IsPresent){
123-
$filter = ("atScope() and assignedTo('{0}')" -f $objectId)
123+
If($null -ne $objectId){
124+
#Set filter
125+
if($AtScope.IsPresent){
126+
$filter = ("atScope() and assignedTo('{0}')" -f $objectId)
127+
}
128+
else{
129+
$filter = ("assignedTo('{0}')" -f $objectId)
130+
}
131+
#Construct query
132+
$p = @{
133+
Authentication = $rmAuth;
134+
Provider = $apiDetails.provider;
135+
ObjectType = 'roleAssignments';
136+
Filter = $filter;
137+
Environment = $Environment;
138+
ContentType = 'application/json';
139+
Method = "GET";
140+
APIVersion = $apiDetails.api_version;
141+
InformationAction = $O365Object.InformationAction;
142+
Verbose = $O365Object.verbose;
143+
Debug = $O365Object.debug;
144+
}
124145
}
125-
else{
126-
$filter = ("assignedTo('{0}')" -f $objectId)
146+
Else{
147+
$msg = @{
148+
MessageData = "Unable to Get ObjectId";
149+
callStack = (Get-PSCallStack | Select-Object -First 1);
150+
logLevel = 'warning';
151+
InformationAction = $O365Object.InformationAction;
152+
Tags = @('AzureRbacWarning');
153+
}
154+
Write-Warning @msg
127155
}
128-
#Construct query
129-
$p = @{
130-
Authentication = $rmAuth;
131-
Provider = $apiDetails.provider;
132-
ObjectType = 'roleAssignments';
133-
Filter = $filter;
134-
Environment = $Environment;
135-
ContentType = 'application/json';
136-
Method = "GET";
137-
APIVersion = $apiDetails.api_version;
138-
InformationAction = $O365Object.InformationAction;
139-
Verbose = $O365Object.verbose;
140-
Debug = $O365Object.debug;
141-
}
142156
}
143157
"PrincipalId"{
144158
#Set filter
@@ -300,6 +314,8 @@ Function Get-MonkeyAzRoleAssignmentForObject{
300314
}
301315
}
302316
End{
303-
Get-MonkeyRMObject @p
317+
If($null -ne $p){
318+
Get-MonkeyRMObject @p
319+
}
304320
}
305321
}

0 commit comments

Comments
 (0)