Skip to content

Commit

Permalink
Fixed bug in Invoke-AzUpgradeModulePlan dynamic parameter handling (#82)
Browse files Browse the repository at this point in the history
* Bug fix for dynamic parameter detection

* Bumped version
  • Loading branch information
keithbabinec authored Mar 3, 2021
1 parent 0b3354a commit e965f36
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions common/code-upgrade-samples/az/dynamic-parameters-test1.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
New-AzResourceGroupDeployment -ResourceGroupName "ContosoEngineering" `
-TemplateFile "D:\Azure\Templates\EngineeringSite.json" `
-TemplateParameterFile "D:\Azure\Templates\EngSiteParms.json" `
- "test1" `
- "test2"
-DynamicUserParam1 "test1" `
-DynamicUserParam2 "test2"
8 changes: 2 additions & 6 deletions powershell-module/Az.Tools.Migration/Az.Tools.Migration.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RootModule = 'Az.Tools.Migration.psm1'

# Version number of this module.
ModuleVersion = '1.1.0'
ModuleVersion = '1.1.1'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down Expand Up @@ -108,11 +108,7 @@
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Upgrade Az version to 5.6.0
* Fixed a bug where New-AzUpgradeModulePlan throws errors when analyzing hashtable code (issue #73).
* Updated scanning results for Az cmdlets that implement dynamic parameters to use clearer warnings.
* Updated Get-AzUpgradeCmdletSpec to improve performance.
* Updated quickstart guide to remove outdated guidance on splatted parameter detection.'
ReleaseNotes = '* Fixed a bug in Invoke-AzUpgradeModulePlan where dynamic parameters are incorrectly updated (issue #81).'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,30 @@ function Invoke-ModuleUpgradeStep
-StartOffset $Step.SourceCommand.StartOffset -EndOffset $Step.SourceCommand.EndOffset

# replacement code
$null = $FileContent.Remove($Step.SourceCommand.StartOffset, ($Step.SourceCommand.EndOffset - $Step.SourceCommand.StartOffset));
$null = $FileContent.Insert($Step.SourceCommand.StartOffset, $Step.Replacement);
$null = $FileContent.Remove($Step.SourceCommand.StartOffset, ($Step.SourceCommand.EndOffset - $Step.SourceCommand.StartOffset))
$null = $FileContent.Insert($Step.SourceCommand.StartOffset, $Step.Replacement)
}
"CmdletParameter"
{
Write-Verbose -Message ("[{0}] Updating CmdletParameter {1} to {2}." `
-f $Step.Location, $Step.Original, $Step.Replacement)
if ([System.String]::IsNullOrWhiteSpace($Step.Replacement) -eq $false)
{
Write-Verbose -Message ("[{0}] Updating CmdletParameter {1} to {2}." `
-f $Step.Location, $Step.Original, $Step.Replacement)

# safety check
# ensure that the file offsets are an exact match.
Confirm-StringBuilderSubstring -FileContent $FileContent -Substring $Step.Original `
-StartOffset $Step.SourceCommandParameter.StartOffset -EndOffset $Step.SourceCommandParameter.EndOffset
# safety check
# ensure that the file offsets are an exact match.
Confirm-StringBuilderSubstring -FileContent $FileContent -Substring $Step.Original `
-StartOffset $Step.SourceCommandParameter.StartOffset -EndOffset $Step.SourceCommandParameter.EndOffset

# replacement code
$null = $FileContent.Remove($Step.SourceCommandParameter.StartOffset, ($Step.SourceCommandParameter.EndOffset - $Step.SourceCommandParameter.StartOffset));
$null = $FileContent.Insert($Step.SourceCommandParameter.StartOffset, $Step.Replacement);
# replacement code
$null = $FileContent.Remove($Step.SourceCommandParameter.StartOffset, ($Step.SourceCommandParameter.EndOffset - $Step.SourceCommandParameter.StartOffset))
$null = $FileContent.Insert($Step.SourceCommandParameter.StartOffset, $Step.Replacement)
}
else
{
Write-Verbose -Message ("[{0}] Skipping CmdletParameter {1}, it has no automated replacement." `
-f $Step.Location, $Step.Original)
}
}
default
{
Expand Down
3 changes: 3 additions & 0 deletions powershell-module/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
-->
## Upcoming Release

## 1.1.1
* Fixed a bug in Invoke-AzUpgradeModulePlan where dynamic parameters are incorrectly updated (issue #81).

## 1.1.0
* Upgrade Az version to 5.6.0
* Fixed a bug where New-AzUpgradeModulePlan throws errors when analyzing hashtable code (issue #73).
Expand Down

0 comments on commit e965f36

Please sign in to comment.