-
Notifications
You must be signed in to change notification settings - Fork 4k
Add ResourceGroup to DefaultParameterValues #4911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
31d526b
initial changes
azdevxps 07c1e06
put script in startup file
azdevxps ccb1a30
remove old changes
azdevxps 29371d5
Move script to updatemodule
azdevxps d41cfb1
move script to build folder
azdevxps 5a1bdf5
revert changes
azdevxps 647691d
base changes on Cormac's PR
azdevxps c7a69ec
Merge upstream
azdevxps c3eb2d0
Address review comments
azdevxps d6daaa6
Resolve conflicts
azdevxps 0fa53f9
address PR comments
azdevxps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ function Create-ModulePsm1 | |
[CmdletBinding()] | ||
param( | ||
[string]$ModulePath, | ||
[string]$TemplatePath | ||
[string]$TemplatePath, | ||
[bool]$AddDefaultParameters | ||
) | ||
|
||
PROCESS | ||
|
@@ -65,12 +66,89 @@ function Create-ModulePsm1 | |
$template = $template -replace "%MODULE-NAME%", $file.BaseName | ||
$template = $template -replace "%DATE%", [string](Get-Date) | ||
$template = $template -replace "%IMPORTED-DEPENDENCIES%", $importedModules | ||
|
||
$contructedCommands = Find-DefaultResourceGroupCmdlets -AddDefaultParameters $AddDefaultParameters -ModuleMetadata $ModuleMetadata -ModulePath $ModulePath | ||
$template = $template -replace "%COMMANDS%", $contructedCommands | ||
|
||
Write-Host "Writing psm1 manifest to $templateOutputPath" | ||
$template | Out-File -FilePath $templateOutputPath -Force | ||
$file = Get-Item -Path $templateOutputPath | ||
} | ||
} | ||
|
||
function Find-DefaultResourceGroupCmdlets | ||
{ | ||
[CmdletBinding()] | ||
param( | ||
[bool]$AddDefaultParameters, | ||
[Hashtable]$ModuleMetadata, | ||
[string]$ModulePath | ||
) | ||
PROCESS | ||
{ | ||
if ($AddDefaultParameters) | ||
{ | ||
$nestedModules = $ModuleMetadata.NestedModules | ||
$AllCmdlets = @() | ||
$nestedModules | ForEach-Object { | ||
$dllPath = Join-Path -Path $ModulePath -ChildPath $_ | ||
$Assembly = [Reflection.Assembly]::LoadFrom($dllPath) | ||
$dllCmdlets = $Assembly.GetTypes() | Where-Object {$_.CustomAttributes.AttributeType.Name -contains "CmdletAttribute"} | ||
$AllCmdlets += $dllCmdlets | ||
} | ||
|
||
$FilteredCommands = $AllCmdlets | Where-Object {Test-CmdletRequiredParameter -Cmdlet $_ -Parameter "ResourceGroupName"} | ||
|
||
if ($FilteredCommands.Length -eq 0) { | ||
$contructedCommands = "@()" | ||
} | ||
else { | ||
$contructedCommands = "@(" | ||
$FilteredCommands | ForEach-Object { | ||
$contructedCommands += "'" + $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").VerbName + "-" + $_.GetCustomAttributes("System.Management.Automation.CmdletAttribute").NounName + ":ResourceGroupName" + "'," | ||
} | ||
$contructedCommands = $contructedCommands -replace ".$",")" | ||
} | ||
|
||
return $contructedCommands | ||
} | ||
|
||
else { | ||
return "@()" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we return a string representing the code for an array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, when put into the template it will be interpreted as an array. |
||
} | ||
} | ||
} | ||
|
||
function Test-CmdletRequiredParameter | ||
{ | ||
[CmdletBinding()] | ||
param( | ||
[Object]$Cmdlet, | ||
[string]$Parameter | ||
) | ||
|
||
PROCESS | ||
{ | ||
$rgParameter = $Cmdlet.GetProperties() | Where-Object {$_.Name -eq $Parameter} | ||
if ($rgParameter -ne $null) { | ||
$parameterAttributes = $rgParameter.CustomAttributes | Where-Object {$_.AttributeType.Name -eq "ParameterAttribute"} | ||
$isMandatory = $true | ||
$parameterAttributes | ForEach-Object { | ||
$hasParameterSet = $_.NamedArguments | Where-Object {$_.MemberName -eq "ParameterSetName"} | ||
$MandatoryParam = $_.NamedArguments | Where-Object {$_.MemberName -eq "Mandatory"} | ||
if (($hasParameterSet -ne $null) -or (!$MandatoryParam.TypedValue.Value)) { | ||
$isMandatory = $false | ||
} | ||
} | ||
if ($isMandatory) { | ||
return $true | ||
} | ||
} | ||
|
||
return $false | ||
} | ||
} | ||
|
||
function Create-MinimumVersionEntry | ||
{ | ||
[CmdletBinding()] | ||
|
@@ -122,22 +200,22 @@ $templateLocation = "$PSScriptRoot\AzureRM.Example.psm1" | |
if (($scope -eq 'All') -or $publishToLocal ) { | ||
# If we publish 'All' or to local folder, publish AzureRM.Profile first, becasue it is the common dependency | ||
Write-Host "Updating profile module" | ||
Create-ModulePsm1 -ModulePath "$resourceManagerRootFolder\AzureRM.Profile" -TemplatePath $templateLocation | ||
Create-ModulePsm1 -ModulePath "$resourceManagerRootFolder\AzureRM.Profile" -TemplatePath $templateLocation $true | ||
Write-Host "Updated profile module" | ||
} | ||
|
||
if (($scope -eq 'All') -or ($scope -eq 'AzureStorage')) { | ||
$modulePath = "$packageFolder\$buildConfig\Storage\Azure.Storage" | ||
# Publish AzureStorage module | ||
Write-Host "Updating AzureStorage module from $modulePath" | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation $false | ||
} | ||
|
||
if (($scope -eq 'All') -or ($scope -eq 'ServiceManagement')) { | ||
$modulePath = "$packageFolder\$buildConfig\ServiceManagement\Azure" | ||
# Publish Azure module | ||
Write-Host "Updating ServiceManagement(aka Azure) module from $modulePath" | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation $false | ||
} | ||
|
||
$resourceManagerModules = Get-ChildItem -Path $resourceManagerRootFolder -Directory | ||
|
@@ -148,15 +226,15 @@ if ($scope -eq 'All') { | |
if (($module.Name -ne "AzureRM.Profile") -and ($module.Name -ne "Azure.Storage")) { | ||
$modulePath = $module.FullName | ||
Write-Host "Updating $module module from $modulePath" | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation $true | ||
Write-Host "Updated $module module" | ||
} | ||
} | ||
} elseif ($scope -ne 'AzureRM') { | ||
$modulePath = Join-Path $resourceManagerRootFolder "AzureRM.$scope" | ||
if (Test-Path $modulePath) { | ||
Write-Host "Updating $scope module from $modulePath" | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation $false | ||
Write-Host "Updated $scope module" | ||
} else { | ||
Write-Error "Can not find module with name $scope to publish" | ||
|
@@ -169,17 +247,17 @@ if (($scope -eq 'All') -or ($scope -eq 'AzureRM')) { | |
{ | ||
$modulePath = "$PSScriptRoot\..\src\StackAdmin\AzureRM" | ||
Write-Host "Updating AzureRM module from $modulePath" | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation $false | ||
Write-Host "Updated AzureRM module" | ||
$modulePath = "$PSScriptRoot\..\src\StackAdmin\AzureStack" | ||
Write-Host "Updating AzureRM module from $modulePath" | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation $false | ||
Write-Host "Updated AzureStack module" | ||
} | ||
else { | ||
$modulePath = "$PSScriptRoot\AzureRM" | ||
Write-Host "Updating AzureRM module from $modulePath" | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation | ||
Create-ModulePsm1 -ModulePath $modulePath -TemplatePath $templateLocation $false | ||
Write-Host "Updated Azure module" | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there is no context (the user hasn't logged in yet)? Wnat to make sure that we are not pushing errors into the Error stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a null check