Skip to content

Commit 4d4a682

Browse files
author
Maddie Clayton
authored
Merge pull request #7228 from bganapa/role-fix
Fix for New-AzureRmRoleAssignment and Remove-AzureRmRoleAssignment fo…
2 parents 0cd3351 + 9805feb commit 4d4a682

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/StackAdmin/Resources/Commands.Resources/Models.Authorization/AuthorizationClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,25 @@ public List<PSRoleDefinition> FilterRoleDefinitionsByCustom(string scope, bool s
165165
public PSRoleAssignment CreateRoleAssignment(FilterRoleAssignmentsOptions parameters)
166166
{
167167
Guid principalId = ActiveDirectoryClient.GetObjectId(parameters.ADObjectFilter);
168+
string principalIdStr = null;
169+
170+
if (principalId == Guid.Empty)
171+
{
172+
principalIdStr = ActiveDirectoryClient.GetAdfsObjectId(parameters.ADObjectFilter);
173+
}
174+
else
175+
{
176+
principalIdStr = principalId.ToString();
177+
}
178+
168179
Guid roleAssignmentId = RoleAssignmentNames.Count == 0 ? Guid.NewGuid() : RoleAssignmentNames.Dequeue();
169180
string scope = parameters.Scope;
170181
string roleDefinitionId = !string.IsNullOrEmpty(parameters.RoleDefinitionName)
171182
? AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromScopeAndIdAsGuid(scope, GetSingleRoleDefinitionByName(parameters.RoleDefinitionName, scope).Id)
172183
: AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromScopeAndIdAsGuid(scope, parameters.RoleDefinitionId);
173184
var createProperties = new RoleAssignmentProperties
174185
{
175-
PrincipalId = principalId.ToString(),
186+
PrincipalId = principalIdStr,
176187
RoleDefinitionId = roleDefinitionId
177188
};
178189
var createParameters = new RoleAssignmentCreateParameters(createProperties);

src/StackAdmin/Resources/Commands.Resources/RoleAssignments/RemoveAzureRoleAssignmentCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public override void ExecuteCmdlet()
175175
ADObjectFilter = new ADObjectFilterOptions
176176
{
177177
UPN = SignInName,
178-
Id = ObjectId.ToString(),
178+
Id = ObjectId,
179179
SPN = ServicePrincipalName
180180
},
181181
ResourceIdentifier = new ResourceIdentifier()

tools/CleanupBuild.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ foreach($RMPath in $resourceManagerPaths)
7777
$removedScripts = Get-ChildItem -Path "$($RMFolder.FullName)\StartupScripts" -Filter "*.ps1" | where { $_.FullName -ne $scriptName }
7878
$removedScripts | % { Write-Verbose "Removing $($_.FullName)"; Remove-Item $_.FullName -Force }
7979
}
80-
$removedPsd1 = Get-ChildItem -Path "$($RMFolder.FullName)" -Filter "*.psd1" -Recurse | where { $_.FullName -ne "$($RMFolder.FullName)$([IO.Path]::DirectorySeparatorChar)$($RMFolder.Name).psd1" }
80+
$removedPsd1 = Get-ChildItem -Path "$($RMFolder.FullName)" -Filter "*.psd1" | where { $_.FullName -ne "$($RMFolder.FullName)$([IO.Path]::DirectorySeparatorChar)$($RMFolder.Name).psd1" }
8181
$removedPsd1 | % { Write-Verbose "Removing $($_.FullName)"; Remove-Item $_.FullName -Force }
8282
}
8383
}

tools/Modules/Run-UnitTests.ps1

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,9 @@ if ($Scope -in $AzureScopes) {
117117

118118
if ($Scope -in $StackScopes) {
119119

120-
# Download and add AzureRM.Profile 3.4.1 to PSModulePath
121-
[System.String]$SavePath = (Join-Path -Path $PSScriptRoot -ChildPath "tmp")
122-
if (-not(Test-Path $SavePath)) {
123-
New-Item -Path $SavePath -ItemType Directory -Force | Out-Null
124-
Save-Module -Name AzureRM.Profile -RequiredVersion 3.4.1 -Repository PSGallery -Path $SavePath | Out-Null
125-
Save-Module -Name AzureRM.Resources -RequiredVersion 4.4.1 -Repository PSGallery -Path $SavePath | Out-Null
126-
}
127-
128-
$oldModulePath = $env:PSModulePath.Clone()
129-
[Environment]::SetEnvironmentVariable("PSModulePath","$env:PSModulePath;$SavePath")
120+
$ARMRoot = "$PSScriptRoot\..\..\src\Stack\$BuildConfig\ResourceManager\AzureResourceManager"
121+
Import-Module "$ARMRoot\AzureRM.Profile\AzureRM.Profile.psd1"
122+
Import-Module "$ARMRoot\AzureRM.Resources\AzureRM.Resources.psd1";
130123

131124
# All admin modules
132125
$AllStackModules = @(
@@ -151,6 +144,5 @@ if ($Scope -in $StackScopes) {
151144
[System.String[]]$ModulesToTest = $AllStackModules | Where-Object { !($_ -in $IgnoredStackModules) }
152145
Test-Stack -BuildConfig $BuildConfig -Modules $ModulesToTest
153146

154-
[Environment]::SetEnvironmentVariable("PSModulePath",$oldModulePath)
155147
}
156148

0 commit comments

Comments
 (0)