Skip to content

Commit 322bf91

Browse files
[Functions] Update the logic to populate the function app creation stacks cache and tab completers. (#24656)
* Update Stacks API parser logic * Update Functions Stack definitions * Update the logic to populate tab completers only when the Az.Functions cmdlets are invoked * Update test
1 parent e5ce6e2 commit 322bf91

18 files changed

+627
-437
lines changed

src/Functions/Functions.Autorest/custom/FunctionsStack/functionAppStacks.json

Lines changed: 495 additions & 366 deletions
Large diffs are not rendered by default.

src/Functions/Functions.Autorest/custom/Get-AzFunctionApp.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function Get-AzFunctionApp {
8585

8686
process {
8787

88+
RegisterFunctionsTabCompleters
89+
8890
$apps = $null
8991
$locationToUse = $null
9092
$parameterSetName = $PsCmdlet.ParameterSetName

src/Functions/Functions.Autorest/custom/Get-AzFunctionAppAvailableLocation.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ function Get-AzFunctionAppAvailableLocation {
7373

7474
process {
7575

76+
RegisterFunctionsTabCompleters
77+
7678
# Remove bound parameters from the dictionary that cannot be process by the intenal cmdlets
7779
$paramsToRemove = @(
7880
"OSType",

src/Functions/Functions.Autorest/custom/Get-AzFunctionAppPlan.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function Get-AzFunctionAppPlan {
8181

8282
process {
8383

84+
RegisterFunctionsTabCompleters
85+
8486
$plans = $null
8587
$locationToUse = $null
8688
$parameterSetName = $PsCmdlet.ParameterSetName

src/Functions/Functions.Autorest/custom/Get-AzFunctionAppSetting.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ function Get-AzFunctionAppSetting {
7676
)
7777

7878
process {
79+
80+
RegisterFunctionsTabCompleters
7981

8082
if ($PsCmdlet.ParameterSetName -eq "ByObjectInput")
8183
{

src/Functions/Functions.Autorest/custom/HelperFunctions.ps1

Lines changed: 94 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,11 +1843,7 @@ function ParseMinorVersion
18431843
(
18441844
[Parameter(Mandatory=$false)]
18451845
[System.String]
1846-
$RuntimeName,
1847-
1848-
[Parameter(Mandatory=$false)]
1849-
[System.String]
1850-
$RuntimeVersion,
1846+
$StackMinorVersion,
18511847

18521848
[Parameter(Mandatory=$false)]
18531849
[System.String]
@@ -1862,45 +1858,54 @@ function ParseMinorVersion
18621858
$RuntimeFullName,
18631859

18641860
[Parameter(Mandatory=$false)]
1865-
[Switch]
1861+
[Bool]
18661862
$StackIsLinux
18671863
)
18681864

18691865
# If this FunctionsVersion is not supported, skip it
18701866
if ($RuntimeSettings.supportedFunctionsExtensionVersions -notcontains "~$DefaultFunctionsVersion")
18711867
{
18721868
$supportedFunctionsExtensionVersions = $RuntimeSettings.supportedFunctionsExtensionVersions -join ", "
1873-
Write-Debug "$DEBUG_PREFIX Minimium required Functions version '$DefaultFunctionsVersion' is not supported. Current supported Functions versions: $supportedFunctionsExtensionVersions. Skipping..."
1869+
Write-Debug "$DEBUG_PREFIX Minimium required Functions version '$DefaultFunctionsVersion' is not supported. Runtime supported Functions versions: $supportedFunctionsExtensionVersions. Skipping..."
18741870
return
18751871
}
18761872
else
18771873
{
18781874
Write-Debug "$DEBUG_PREFIX Minimium required Functions version '$DefaultFunctionsVersion' is supported."
18791875
}
18801876

1881-
if (-not $RuntimeName)
1882-
{
1883-
$RuntimeName = GetRuntimeName -AppSettingsDictionary $RuntimeSettings.AppSettingsDictionary
1884-
}
1877+
$runtimeName = GetRuntimeName -AppSettingsDictionary $RuntimeSettings.AppSettingsDictionary
18851878

1886-
if ($runtimeName -like "dotnet*" -or $runtimeName -like "node*")
1879+
$version = $null
1880+
if ($RuntimeName -eq "Java" -and $RuntimeSettings.RuntimeVersion -eq "1.8")
18871881
{
1888-
$RuntimeVersion = GetRuntimeVersion -Version $RuntimeVersion
1882+
# Java 8 is only supported in Windows. The display value is 8; however, the actual SiteConfig.JavaVersion is 1.8
1883+
$version = $StackMinorVersion
18891884
}
1890-
1891-
# Some runtimes do not have a version like custom handler
1892-
if (-not $runtimeVersion -and $RuntimeSettings.RuntimeVersion)
1885+
else
18931886
{
1894-
$version = GetRuntimeVersion -Version $RuntimeSettings.RuntimeVersion -StackIsLinux $StackIsLinux.IsPresent
1895-
$RuntimeVersion = $version
1887+
$version = $RuntimeSettings.RuntimeVersion
18961888
}
18971889

1890+
$runtimeVersion = GetRuntimeVersion -Version $version -StackIsLinux $StackIsLinux
1891+
18981892
# For Java function app, the version from the Stacks API is 8.0, 11.0, and 17.0. However, this is a breaking change which cannot be supported in the current release.
1899-
# We will convert the version to 8, 11, and 17. This change will be reverted for the November 2023 breaking release.
1893+
# We will convert the version to 8, 11, and 17. This change will be reverted for the May 2024 breaking release.
19001894
if ($RuntimeName -eq "Java")
19011895
{
1902-
$RuntimeVersion = [int]$RuntimeVersion
1903-
Write-Debug "$DEBUG_PREFIX Runtime version for Java is modified to be compatible with the current release. Current version '$RuntimeVersion'"
1896+
$runtimeVersion = [int]$runtimeVersion
1897+
Write-Debug "$DEBUG_PREFIX Runtime version for Java is modified to be compatible with the current release. Current version '$runtimeVersion'"
1898+
}
1899+
1900+
# For DotNet function app, the version from the Stacks API is 6.0. 7.0, and 8.0. However, this is a breaking change which cannot be supported in the current release.
1901+
# We will convert the version to 6, 7, and 8. This change will be reverted for the May 2024 breaking release.
1902+
if ($RuntimeName -like "DotNet*")
1903+
{
1904+
if ($runtimeVersion.EndsWith(".0"))
1905+
{
1906+
$runtimeVersion = [int]$runtimeVersion
1907+
}
1908+
Write-Debug "$DEBUG_PREFIX Runtime version for $runtimeName is modified to be compatible with the current release. Current version '$runtimeVersion'"
19041909
}
19051910

19061911
$runtime = [Runtime]::new()
@@ -1926,10 +1931,10 @@ function ParseMinorVersion
19261931
return
19271932
}
19281933

1929-
if ($RuntimeVersion -and ($runtimeName -ne "custom"))
1934+
if ($runtimeVersion -and ($runtimeName -ne "custom"))
19301935
{
1931-
Write-Debug "$DEBUG_PREFIX Runtime version: $RuntimeVersion"
1932-
$runtime.Version = $RuntimeVersion
1936+
Write-Debug "$DEBUG_PREFIX Runtime version: $runtimeVersion"
1937+
$runtime.Version = $runtimeVersion
19331938
}
19341939
else
19351940
{
@@ -1947,7 +1952,7 @@ function ParseMinorVersion
19471952
$runtime.PreferredOs = $PreferredOs
19481953
}
19491954

1950-
$targetOs = if ($StackIsLinux.IsPresent) { 'Linux' } else { 'Windows' }
1955+
$targetOs = if ($StackIsLinux) { 'Linux' } else { 'Windows' }
19511956
Write-Debug "$DEBUG_PREFIX Runtime '$runtimeName' for '$targetOs' parsed successfully."
19521957

19531958
return $runtime
@@ -1959,23 +1964,28 @@ function GetRuntimeVersion
19591964
[Microsoft.Azure.PowerShell.Cmdlets.Functions.DoNotExportAttribute()]
19601965
param
19611966
(
1962-
[Parameter(Mandatory=$true)]
1963-
[ValidateNotNullOrEmpty()]
1967+
[Parameter(Mandatory=$false)]
19641968
[System.String]
19651969
$Version,
19661970

19671971
[Parameter(Mandatory=$false)]
1968-
[Switch]
1972+
[Bool]
19691973
$StackIsLinux
19701974
)
19711975

1972-
if ($StackIsLinux.IsPresent)
1976+
if (-not $Version)
1977+
{
1978+
# Some runtimes do not have a version like custom handler
1979+
return
1980+
}
1981+
1982+
if ($StackIsLinux)
19731983
{
19741984
$Version = $Version.Split('|')[1]
19751985
}
19761986
else
19771987
{
1978-
$valuesToReplace = @('STS', 'non-', 'LTS', 'Isolated', '(', ')', '~', 'custom')
1988+
$valuesToReplace = @('v', '~')
19791989
foreach ($value in $valuesToReplace)
19801990
{
19811991
if ($Version.Contains($value))
@@ -1986,8 +1996,7 @@ function GetRuntimeVersion
19861996
}
19871997

19881998
$Version = $Version.Trim()
1989-
1990-
return $Version
1999+
return $Version
19912000
}
19922001

19932002
function GetDictionary
@@ -2123,27 +2132,26 @@ function SetLinuxandWindowsSupportedRuntimes
21232132
{
21242133
$preferredOs = $stackDefinition.properties.preferredOs
21252134

2126-
# runtime name is the $stackDefinition.Name
2127-
$runtimeName = $stackDefinition.properties.value
2128-
Write-Debug "$DEBUG_PREFIX Parsing runtime name: $runtimeName"
2135+
$stackName = $stackDefinition.properties.value
2136+
Write-Debug "$DEBUG_PREFIX Parsing stack name: $stackName"
21292137

21302138
foreach ($majorVersion in $stackDefinition.properties.majorVersions)
21312139
{
21322140
foreach ($minorVersion in $majorVersion.minorVersions)
21332141
{
21342142
$runtimeFullName = $minorVersion.DisplayText
2135-
$runtimeVersion = $minorVersion.value
21362143
Write-Debug "$DEBUG_PREFIX runtime full name: $runtimeFullName"
2137-
Write-Debug "$DEBUG_PREFIX runtime version: $runtimeVersion"
21382144

2145+
$stackMinorVersion = $minorVersion.value
2146+
Write-Debug "$DEBUG_PREFIX stack minor version: $stackMinorVersion"
21392147
$runtime = $null
21402148

21412149
if (ContainsProperty -Object $minorVersion.stackSettings -PropertyName "windowsRuntimeSettings")
21422150
{
2143-
$runtime = ParseMinorVersion -RuntimeVersion $runtimeVersion `
2144-
-RuntimeSettings $minorVersion.stackSettings.windowsRuntimeSettings `
2151+
$runtime = ParseMinorVersion -RuntimeSettings $minorVersion.stackSettings.windowsRuntimeSettings `
21452152
-RuntimeFullName $runtimeFullName `
2146-
-PreferredOs $preferredOs
2153+
-PreferredOs $preferredOs `
2154+
-StackMinorVersion $stackMinorVersion
21472155

21482156
if ($runtime)
21492157
{
@@ -2153,11 +2161,10 @@ function SetLinuxandWindowsSupportedRuntimes
21532161

21542162
if (ContainsProperty -Object $minorVersion.stackSettings -PropertyName "linuxRuntimeSettings")
21552163
{
2156-
$runtime = ParseMinorVersion -RuntimeVersion $runtimeVersion `
2157-
-RuntimeSettings $minorVersion.stackSettings.linuxRuntimeSettings `
2164+
$runtime = ParseMinorVersion -RuntimeSettings $minorVersion.stackSettings.linuxRuntimeSettings `
21582165
-RuntimeFullName $runtimeFullName `
21592166
-PreferredOs $preferredOs `
2160-
-StackIsLinux
2167+
-StackIsLinux $true
21612168

21622169
if ($runtime)
21632170
{
@@ -2168,44 +2175,60 @@ function SetLinuxandWindowsSupportedRuntimes
21682175
}
21692176
}
21702177
}
2171-
SetLinuxandWindowsSupportedRuntimes
21722178

2173-
# New-AzFunction app ArgumentCompleter for the RuntimeVersion parameter
2174-
# The values of RuntimeVersion depend on the selection of the Runtime parameter
2175-
$GetRuntimeVersionCompleter = {
2176-
2177-
param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
2179+
# This method pulls down the Functions stack definitions from the ARM API and builds a list of supported runtimes and runtime versions.
2180+
# This is used to build the tab completers for the New-AzFunctionApp cmdlet.
2181+
function RegisterFunctionsTabCompleters
2182+
{
2183+
[Microsoft.Azure.PowerShell.Cmdlets.Functions.DoNotExportAttribute()]
2184+
param ()
21782185

2179-
if ($fakeBoundParameters.ContainsKey('Runtime'))
2186+
if ($env:FunctionsTabCompletersRegistered)
21802187
{
2181-
# RuntimeVersions is defined in SetLinuxandWindowsSupportedRuntimes
2182-
$AllRuntimeVersions[$fakeBoundParameters.Runtime] | Where-Object {
2183-
$_ -like "$wordToComplete*"
2184-
} | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }
2188+
return
21852189
}
2186-
}
21872190

2188-
# New-AzFunction app ArgumentCompleter for the Runtime parameter
2189-
$GetAllRuntimesCompleter = {
2191+
SetLinuxandWindowsSupportedRuntimes
21902192

2191-
param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
2193+
# New-AzFunction app ArgumentCompleter for the RuntimeVersion parameter
2194+
# The values of RuntimeVersion depend on the selection of the Runtime parameter
2195+
$GetRuntimeVersionCompleter = {
21922196

2193-
$runtimeValues = $AllRuntimeVersions.Keys | Sort-Object | ForEach-Object { $_ }
2197+
param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
21942198

2195-
$runtimeValues | Where-Object { $_ -like "$wordToComplete*" }
2196-
}
2199+
if ($fakeBoundParameters.ContainsKey('Runtime'))
2200+
{
2201+
# RuntimeVersions is defined in SetLinuxandWindowsSupportedRuntimes
2202+
$AllRuntimeVersions[$fakeBoundParameters.Runtime] | Where-Object {
2203+
$_ -like "$wordToComplete*"
2204+
} | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }
2205+
}
2206+
}
21972207

2198-
# New-AzFunction app ArgumentCompleter for the Runtime parameter
2199-
$GetAllFunctionsVersionsCompleter = {
2208+
# New-AzFunction app ArgumentCompleter for the Runtime parameter
2209+
$GetAllRuntimesCompleter = {
22002210

2201-
param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
2211+
param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
22022212

2203-
$functionsVersions = $AllFunctionsExtensionVersions | Sort-Object | ForEach-Object { $_ }
2213+
$runtimeValues = $AllRuntimeVersions.Keys | Sort-Object | ForEach-Object { $_ }
22042214

2205-
$functionsVersions | Where-Object { $_ -like "$wordToComplete*" }
2206-
}
2215+
$runtimeValues | Where-Object { $_ -like "$wordToComplete*" }
2216+
}
2217+
2218+
# New-AzFunction app ArgumentCompleter for the Runtime parameter
2219+
$GetAllFunctionsVersionsCompleter = {
2220+
2221+
param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
22072222

2208-
# Register tab completers
2209-
Register-ArgumentCompleter -CommandName New-AzFunctionApp -ParameterName FunctionsVersion -ScriptBlock $GetAllFunctionsVersionsCompleter
2210-
Register-ArgumentCompleter -CommandName New-AzFunctionApp -ParameterName Runtime -ScriptBlock $GetAllRuntimesCompleter
2211-
Register-ArgumentCompleter -CommandName New-AzFunctionApp -ParameterName RuntimeVersion -ScriptBlock $GetRuntimeVersionCompleter
2223+
$functionsVersions = $AllFunctionsExtensionVersions | Sort-Object | ForEach-Object { $_ }
2224+
2225+
$functionsVersions | Where-Object { $_ -like "$wordToComplete*" }
2226+
}
2227+
2228+
# Register tab completers
2229+
Register-ArgumentCompleter -CommandName New-AzFunctionApp -ParameterName FunctionsVersion -ScriptBlock $GetAllFunctionsVersionsCompleter
2230+
Register-ArgumentCompleter -CommandName New-AzFunctionApp -ParameterName Runtime -ScriptBlock $GetAllRuntimesCompleter
2231+
Register-ArgumentCompleter -CommandName New-AzFunctionApp -ParameterName RuntimeVersion -ScriptBlock $GetRuntimeVersionCompleter
2232+
2233+
$env:FunctionsTabCompletersRegistered = $true
2234+
}

src/Functions/Functions.Autorest/custom/New-AzFunctionApp.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ function New-AzFunctionApp {
210210
)
211211

212212
process {
213+
214+
RegisterFunctionsTabCompleters
215+
213216
# Remove bound parameters from the dictionary that cannot be process by the intenal cmdlets.
214217
$paramsToRemove = @(
215218
"StorageAccountName",

src/Functions/Functions.Autorest/custom/New-AzFunctionAppPlan.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ function New-AzFunctionAppPlan {
122122
${ProxyUseDefaultCredentials}
123123
)
124124
process {
125+
126+
RegisterFunctionsTabCompleters
127+
125128
# Remove bound parameters from the dictionary that cannot be process by the intenal cmdlets.
126129
foreach ($paramName in @("Sku", "WorkerType", "MaximumWorkerCount", "MinimumWorkerCount", "Location", "Tag"))
127130
{

src/Functions/Functions.Autorest/custom/Remove-AzFunctionApp.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ function Remove-AzFunctionApp {
8383
${ProxyUseDefaultCredentials}
8484
)
8585
process {
86+
87+
RegisterFunctionsTabCompleters
88+
8689
# The input object is an ISite. This needs to be transformed into a FunctionsIdentity
8790
if ($PsCmdlet.ParameterSetName -eq "ByObjectInput")
8891
{

src/Functions/Functions.Autorest/custom/Remove-AzFunctionAppPlan.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ function Remove-AzFunctionAppPlan {
8484
)
8585

8686
process {
87+
88+
RegisterFunctionsTabCompleters
89+
8790
if ($PsCmdlet.ParameterSetName -eq "ByObjectInput")
8891
{
8992
if ($PSBoundParameters.ContainsKey("InputObject"))

src/Functions/Functions.Autorest/custom/Remove-AzFunctionAppSetting.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ function Remove-AzFunctionAppSetting {
8686
)
8787
process {
8888

89+
RegisterFunctionsTabCompleters
90+
8991
# Remove bound parameters from the dictionary that cannot be process by the intenal cmdlets
9092
$paramsToRemove = @(
9193
"AppSettingName"

src/Functions/Functions.Autorest/custom/Restart-AzFunctionApp.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function Restart-AzFunctionApp {
8585

8686
process {
8787

88+
RegisterFunctionsTabCompleters
89+
8890
# The input object is an ISite. This needs to be transformed into a FunctionsIdentity
8991
if ($PsCmdlet.ParameterSetName -eq "ByObjectInput")
9092
{

src/Functions/Functions.Autorest/custom/Start-AzFunctionApp.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function Start-AzFunctionApp {
8181

8282
process {
8383

84+
RegisterFunctionsTabCompleters
85+
8486
# The input object is an ISite. This needs to be transformed into a FunctionsIdentity.
8587
if ($PsCmdlet.ParameterSetName -eq "ByObjectInput")
8688
{

0 commit comments

Comments
 (0)