Skip to content

Commit 207a0f7

Browse files
committed
Merge branch 'dev' of github.com:Azure/azure-powershell into parameterAndBugFixes
2 parents 83664bd + 0270be6 commit 207a0f7

File tree

9 files changed

+105
-22
lines changed

9 files changed

+105
-22
lines changed

build.proj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<SetupOutputDirectory>$(PublishDirectory)\Setup</SetupOutputDirectory>
3737
<TestOutputDirectory>$(PublishDirectory)\TestResults</TestOutputDirectory>
3838
<BuildInParallel Condition="'$(BuildInParallel)' == ''">true</BuildInParallel>
39+
<NuGetPublishingSource Condition=" '$(NuGetPublishingSource)' != '' ">http://psget/PSGallery/api/v2/</NuGetPublishingSource>
3940
</PropertyGroup>
4041
<ItemGroup>
4142
<AzureResourceManagerSln Include=".\src\ResourceManager.sln" />
@@ -115,6 +116,7 @@
115116
<NuGetCommand>$(MSBuildProjectDirectory)\src\.nuget\NuGet.exe</NuGetCommand>
116117
<NuGetRestoreConfigFile>$(MSBuildProjectDirectory)\restore.config</NuGetRestoreConfigFile>
117118
<NuGetRestoreConfigSwitch>-ConfigFile &quot;$(NuGetRestoreConfigFile)&quot;</NuGetRestoreConfigSwitch>
119+
<PowerShellCommand>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellCommand>
118120
</PropertyGroup>
119121

120122
<!--
@@ -285,6 +287,14 @@
285287
<!--If we are testing locally then we copy the binaries and do not submit to the code sign server-->
286288
<Copy SourceFiles="@(InstallersToSign)" DestinationFolder="signed" Condition="$(DelaySign)" />
287289
</Target>
290+
291+
<!-- Publish all packages -->
292+
<Target Name="Publish" DependsOnTargets="Build">
293+
<Error Condition=" '$(NuGetKey)' == '' " Text="You must provide the NuGetKey parameter to the build: /p:NuGetKey=YOUR_PUBLISHING_KEY" />
294+
<Message Importance="high" Text="Publishing Cmdlets..." />
295+
296+
<Exec Command="$(PowerShellCommand) -NoLogo -NoProfile -Command &quot;. $(LibraryToolsFolder)\PublishModules.ps1 $(Configuration) $(NuGetKey) \&quot;$(NuGetPublishingSource)\&quot;&quot;"/>
297+
</Target>
288298

289299
<PropertyGroup>
290300
<RunTestLive Condition="'$(RunTestLive)' == ''">false</RunTestLive>

setup-powershellget/Setup/ShortcutStartup.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ Finalizing installation of Azure PowerShell.
2626
Installing Azure Modules from PowerShell Gallery.
2727
This may take some time...
2828
"@
29+
Import-Module PackageManagement
2930
Get-PackageProvider -Name NuGet -ForceBootstrap
30-
Install-Module AzureRM.Installer
31-
Install-AzureRM
31+
32+
$NuGetPublishingSource = $env:NuGetPublishingSource
33+
if ([string]::IsNullOrWhiteSpace($NuGetPublishingSource)) {
34+
Install-Module AzureRM -Repository $NuGetPublishingSource
35+
} else {
36+
Install-Module AzureRM
37+
}
3238
} else {
3339
cd c:\
3440
$welcomeMessage = @"

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleAssignmentTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public void RaByScope()
5858
ResourcesController.NewInstance.RunPsTest("Test-RaByScope");
5959
}
6060

61-
[Fact]
61+
[Fact(Skip = "Need to re-record test")]
6262
[Trait(Category.AcceptanceType, Category.CheckIn)]
6363
public void RaByResourceGroup()
6464
{
6565
ResourcesController.NewInstance.RunPsTest("Test-RaByResourceGroup");
6666
}
6767

68-
[Fact]
68+
[Fact(Skip = "Need to re-record test")]
6969
[Trait(Category.AcceptanceType, Category.CheckIn)]
7070
public void RaByResource()
7171
{
@@ -79,7 +79,7 @@ public void RaByServicePrincipal()
7979
ResourcesController.NewInstance.RunPsTest("Test-RaByServicePrincipal");
8080
}
8181

82-
[Fact]
82+
[Fact(Skip = "Need to re-record test")]
8383
[Trait(Category.AcceptanceType, Category.CheckIn)]
8484
public void RaByUpn()
8585
{

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,18 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
141141
List<PSRoleAssignment> result = new List<PSRoleAssignment>();
142142
ListAssignmentsFilterParameters parameters = new ListAssignmentsFilterParameters();
143143

144+
PSADObject adObject = null;
144145
if (options.ADObjectFilter.HasFilter)
145146
{
147+
adObject = ActiveDirectoryClient.GetADObject(options.ADObjectFilter);
148+
if (adObject == null)
149+
{
150+
throw new KeyNotFoundException(ProjectResources.PrincipalNotFound);
151+
}
152+
146153
// Filter first by principal
147154
if (options.ExpandPrincipalGroups)
148155
{
149-
PSADObject adObject = ActiveDirectoryClient.GetADObject(options.ADObjectFilter);
150-
if (adObject == null)
151-
{
152-
throw new KeyNotFoundException(ProjectResources.PrincipalNotFound);
153-
}
154-
155156
if (!(adObject is PSADUser))
156157
{
157158
throw new InvalidOperationException(ProjectResources.ExpandGroupsNotSupported);
@@ -161,7 +162,7 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
161162
}
162163
else
163164
{
164-
parameters.PrincipalId = string.IsNullOrEmpty(options.ADObjectFilter.Id) ? ActiveDirectoryClient.GetObjectId(options.ADObjectFilter) : Guid.Parse(options.ADObjectFilter.Id);
165+
parameters.PrincipalId = string.IsNullOrEmpty(options.ADObjectFilter.Id) ? adObject.Id : Guid.Parse(options.ADObjectFilter.Id);
165166
}
166167

167168
result.AddRange(AuthorizationManagementClient.RoleAssignments.List(parameters)
@@ -197,7 +198,22 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
197198
{
198199
// Get classic administrator access assignments
199200
List<ClassicAdministrator> classicAdministrators = AuthorizationManagementClient.ClassicAdministrators.List().ClassicAdministrators.ToList();
200-
List<PSRoleAssignment> classicAdministratorsAssignments = classicAdministrators.Select(a => a.ToPSRoleAssignment(currentSubscription)).ToList();
201+
List<PSRoleAssignment> classicAdministratorsAssignments = classicAdministrators.Select(a => a.ToPSRoleAssignment(currentSubscription)).ToList();
202+
203+
// Filter by principal if provided
204+
if (options.ADObjectFilter.HasFilter)
205+
{
206+
if (!(adObject is PSADUser))
207+
{
208+
throw new InvalidOperationException(ProjectResources.IncludeClassicAdminsNotSupported);
209+
}
210+
211+
var userObject = adObject as PSADUser;
212+
classicAdministratorsAssignments = classicAdministratorsAssignments.Where(c =>
213+
c.DisplayName.Equals(userObject.UserPrincipalName, StringComparison.OrdinalIgnoreCase) ||
214+
c.DisplayName.Equals(userObject.Mail, StringComparison.OrdinalIgnoreCase)).ToList();
215+
}
216+
201217
result.AddRange(classicAdministratorsAssignments);
202218
}
203219

src/ResourceManager/Resources/Commands.Resources/Properties/Resources.Designer.cs

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

src/ResourceManager/Resources/Commands.Resources/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,7 @@
312312
<data name="PrincipalNotFound" xml:space="preserve">
313313
<value>Cannot find principal using the specified options</value>
314314
</data>
315+
<data name="IncludeClassicAdminsNotSupported" xml:space="preserve">
316+
<value>IncludeClassicAdministrators is only supported for a User principal</value>
317+
</data>
315318
</root>

tools/AzureRM/AzureRM.psd1

5.14 KB
Binary file not shown.

tools/AzureRM/AzureRM.psm1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<#
2+
.Synopsis
3+
Install Azure Resource Manager cmdlet modules
4+
5+
.Description
6+
Installs all the available Azure Resource Manager cmdlet modules that start with "AzureRM".
7+
8+
.Parameter Repository
9+
Limit the search for "AzureRM" cmdlets in a specific repository.
10+
11+
.Parameter Scope
12+
Specifies the parameter scope.
13+
#>
14+
function Update-AzureRM
15+
{
16+
param(
17+
[Parameter(Position=0, Mandatory = $false)]
18+
[string]
19+
$Repository,
20+
21+
[Parameter(Position=1, Mandatory = $false)]
22+
[ValidateSet("CurrentUser","AllUsers")]
23+
[string]
24+
$Scope)
25+
26+
if ([string]::IsNullOrWhiteSpace($Scope))
27+
{
28+
$Scope = "AllUsers"
29+
}
30+
31+
Install-Module AzureRM.Profile -Repository $Repository
32+
if ([string]::IsNullOrWhiteSpace($Repository))
33+
{
34+
$modules = Find-Module -Name AzureRM.* | Where-Object {$_.Name -ne "AzureRM" -and $_.Name -ne "AzureRM.Profile"}
35+
} else {
36+
$modules = Find-Module -Repository $Repository | Where-Object {$_.Name -like "AzureRM.*" -and $_.Name -ne "AzureRM" -and $_.Name -ne "AzureRM.Profile"}
37+
}
38+
39+
Write-Output "Installing $($modules.Length) AzureRM modules. This may take a few minutes."
40+
41+
$result = $modules | ForEach {
42+
Start-Job -Name $_.Name -ScriptBlock {
43+
Install-Module -Name $args[0] -Repository $args[1] -Scope $args[2]
44+
Write-Output "$($args[0]) installed..."
45+
} -ArgumentList $_.Name, $Repository, $Scope }
46+
47+
$modules | ForEach {Get-Job -Name $_.Name | Wait-Job | Receive-Job }
48+
}

tools/PublishModules.ps1

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ if ([string]::IsNullOrEmpty($repositoryLocation))
3434
}
3535

3636
$packageFolder = "$PSScriptRoot\..\src\Package"
37-
$scriptFolder = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
38-
. ($scriptFolder + '.\SetupEnv.ps1')
39-
40-
if (Test-Path $packageFolder) {
41-
Remove-Item -Path $packageFolder -Recurse -Force
42-
}
43-
44-
# Build the cmdlets in debug mode
45-
msbuild "$env:AzurePSRoot\build.proj" /t:"BuildDebug"
4637

4738
$repoName = $(New-Guid).ToString()
4839
Register-PSRepository -Name $repoName -SourceLocation $repositoryLocation -PublishLocation $repositoryLocation -InstallationPolicy Trusted

0 commit comments

Comments
 (0)