Skip to content

[Functions]Migrate Functions from generation branch #15385

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 2 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/Functions/Az.Functions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 5/20/2021
# Generated on: 7/1/2021
#

@{
Expand Down Expand Up @@ -47,7 +47,7 @@ PowerShellVersion = '5.1'
DotNetFrameworkVersion = '4.7.2'

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''
# ClrVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
Expand Down Expand Up @@ -115,11 +115,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Added support in function app creation for Python 3.9 and Node 14 function apps
* Removed support in function app creation for V2, Python 3.6, Node 8, and Node 10 function apps
* Updated IdentityID parameter from string to string array in Update-AzFunctionApp. This is to be consistent with New-AzFunctionApp which has the same parameter as a string array
* Updated FullyQualifiedErrorId for an invalid Functions version from FunctionsVersionIsInvalid to FunctionsVersionNotSupported
* When creating a Node.js function app, if no runtime version is specified, the default runtime version is set to 14 instead of 12'
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''
Expand Down
3 changes: 3 additions & 0 deletions src/Functions/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- Additional information about change #1
-->
## Upcoming Release
* Added two additional app settings (WEBSITE_CONTENTSHARE and WEBSITE_CONTENTAZUREFILECONNECTIONSTRING) for Linux Consumption apps. [15124]
* Fixed bug with New-AzFunctionApp when created on Azure Gov. [13379]
* Added Az.Functions cmdlets need to support creating and copying app settings with empty values. [14511]

## Version 3.0.0
* Added support in function app creation for Python 3.9 and Node 14 function apps
Expand Down
5 changes: 4 additions & 1 deletion src/Functions/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ $null = New-Item -ItemType Directory -Force -Path $examplesFolder

Write-Host -ForegroundColor Green 'Creating cmdlets for specified models...'
$modelCmdlets = @()
. (Join-Path $PSScriptRoot 'create-model-cmdlets.ps1') -Models $modelCmdlets
if ($modelCmdlets.Count -gt 0) {
. (Join-Path $PSScriptRoot 'create-model-cmdlets.ps1')
CreateModelCmdlet($modelCmdlets)
}

if($NoDocs) {
Write-Host -ForegroundColor Green 'Creating exports...'
Expand Down
253 changes: 128 additions & 125 deletions src/Functions/create-model-cmdlets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,154 +12,157 @@
# limitations under the License.
# ----------------------------------------------------------------------------------

param([string[]]$Models)
function CreateModelCmdlet {

if ($Models.Count -eq 0)
{
return
}
param([string[]]$Models)

$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated\api') 'Models'
$ModuleName = 'Az.Functions'.Split(".")[1]
$OutputDir = Join-Path $PSScriptRoot 'custom\autogen-model-cmdlets'
$null = New-Item -ItemType Directory -Force -Path $OutputDir
if ($Models.Count -eq 0)
{
return
}

$CsFiles = Get-ChildItem -Path $ModelCsPath -Recurse -Filter *.cs
$Content = ''
$null = $CsFiles | ForEach-Object -Process { if ($_.Name.Split('.').count -eq 2 )
{ $Content += get-content $_.fullname -raw
} }
$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated\api') 'Models'
$ModuleName = 'Az.Functions'.Split(".")[1]
$OutputDir = Join-Path $PSScriptRoot 'custom\autogen-model-cmdlets'
$null = New-Item -ItemType Directory -Force -Path $OutputDir

$Tree = [Microsoft.CodeAnalysis.CSharp.SyntaxFactory]::ParseCompilationUnit($Content)
$Nodes = $Tree.ChildNodes().ChildNodes()
foreach ($Model in $Models)
{
$InterfaceNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq "I$Model") }
if ($InterfaceNode.count -eq 0) {
continue
}
# through a queue, we iterate all the parent models.
$Queue = @($InterfaceNode)
$visited = @("I$Model")
$AllInterfaceNodes = @()
while ($Queue.count -ne 0)
$CsFiles = Get-ChildItem -Path $ModelCsPath -Recurse -Filter *.cs
$Content = ''
$null = $CsFiles | ForEach-Object -Process { if ($_.Name.Split('.').count -eq 2 )
{ $Content += get-content $_.fullname -raw
} }

$Tree = [Microsoft.CodeAnalysis.CSharp.SyntaxFactory]::ParseCompilationUnit($Content)
$Nodes = $Tree.ChildNodes().ChildNodes()
foreach ($Model in $Models)
{
$AllInterfaceNodes += $Queue[0]
# Baselist contains the direct parent models.
foreach ($parent in $Queue[0].BaseList.Types)
$InterfaceNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq "I$Model") }
if ($InterfaceNode.count -eq 0) {
continue
}
# through a queue, we iterate all the parent models.
$Queue = @($InterfaceNode)
$visited = @("I$Model")
$AllInterfaceNodes = @()
while ($Queue.count -ne 0)
{
if (($parent.Type.Right.Identifier.Value -ne 'IJsonSerializable') -and (-not $visited.Contains($parent.Type.Right.Identifier.Value)))
$AllInterfaceNodes += $Queue[0]
# Baselist contains the direct parent models.
foreach ($parent in $Queue[0].BaseList.Types)
{
$Queue = [Array]$Queue + ($Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq $parent.Type.Right.Identifier.Value) })
$visited = [Array]$visited + $parent.Type.Right.Identifier.Value
if (($parent.Type.Right.Identifier.Value -ne 'IJsonSerializable') -and (-not $visited.Contains($parent.Type.Right.Identifier.Value)))
{
$Queue = [Array]$Queue + ($Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq $parent.Type.Right.Identifier.Value) })
$visited = [Array]$visited + $parent.Type.Right.Identifier.Value
}
}
$first, $Queue = $Queue
}
$first, $Queue = $Queue
}

$Namespace = $InterfaceNode.Parent.Name
$ObjectType = $Model
$ObjectTypeWithNamespace = "${Namespace}.${ObjectType}"
# remove duplicated module name
if ($ObjectType.StartsWith($ModuleName)) {
$ModulePrefix = ''
} else {
$ModulePrefix = $ModuleName
}
$OutputPath = Join-Path -ChildPath "New-Az${ModulePrefix}${ObjectType}Object.ps1" -Path $OutputDir
$Namespace = $InterfaceNode.Parent.Name
$ObjectType = $Model
$ObjectTypeWithNamespace = "${Namespace}.${ObjectType}"
# remove duplicated module name
if ($ObjectType.StartsWith($ModuleName)) {
$ModulePrefix = ''
} else {
$ModulePrefix = $ModuleName
}
$OutputPath = Join-Path -ChildPath "New-Az${ModulePrefix}${ObjectType}Object.ps1" -Path $OutputDir

$ParameterDefineScriptList = New-Object System.Collections.Generic.List[string]
$ParameterAssignScriptList = New-Object System.Collections.Generic.List[string]
foreach ($Node in $AllInterfaceNodes)
{
foreach ($Member in $Node.Members)
$ParameterDefineScriptList = New-Object System.Collections.Generic.List[string]
$ParameterAssignScriptList = New-Object System.Collections.Generic.List[string]
foreach ($Node in $AllInterfaceNodes)
{
$Arguments = $Member.AttributeLists.Attributes.ArgumentList.Arguments
$Required = $false
$Description = ""
$Readonly = $False
foreach ($Argument in $Arguments)
foreach ($Member in $Node.Members)
{
if ($Argument.NameEquals.Name.Identifier.Value -eq "Required")
$Arguments = $Member.AttributeLists.Attributes.ArgumentList.Arguments
$Required = $false
$Description = ""
$Readonly = $False
foreach ($Argument in $Arguments)
{
$Required = $Argument.Expression.Token.Value
if ($Argument.NameEquals.Name.Identifier.Value -eq "Required")
{
$Required = $Argument.Expression.Token.Value
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Description")
{
$Description = $Argument.Expression.Token.Value.Trim('.').replace('"', '`"')
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Readonly")
{
$Readonly = $Argument.Expression.Token.Value
}
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Description")
if ($Readonly)
{
$Description = $Argument.Expression.Token.Value.Trim('.').replace('"', '`"')
continue
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Readonly")
$Identifier = $Member.Identifier.Value
$Type = $Member.Type.ToString().replace('?', '').Split("::")[-1]
$ParameterDefinePropertyList = New-Object System.Collections.Generic.List[string]
if ($Required)
{
$Readonly = $Argument.Expression.Token.Value
$ParameterDefinePropertyList.Add("Mandatory")
}
if ($Description -ne "")
{
$ParameterDefinePropertyList.Add("HelpMessage=`"${Description}.`"")
}
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
$ParameterDefineScript = "
[Parameter($ParameterDefineProperty)]
[${Type}]
`$${Identifier}"
$ParameterDefineScriptList.Add($ParameterDefineScript)
$ParameterAssignScriptList.Add("
`$Object.${Identifier} = `$${Identifier}")
}
if ($Readonly)
{
continue
}
$Identifier = $Member.Identifier.Value
$Type = $Member.Type.ToString().replace('?', '').Split("::")[-1]
$ParameterDefinePropertyList = New-Object System.Collections.Generic.List[string]
if ($Required)
{
$ParameterDefinePropertyList.Add("Mandatory")
}
if ($Description -ne "")
{
$ParameterDefinePropertyList.Add("HelpMessage=`"${Description}.`"")
}
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
$ParameterDefineScript = "
[Parameter($ParameterDefineProperty)]
[${Type}]
`$${Identifier}"
$ParameterDefineScriptList.Add($ParameterDefineScript)
$ParameterAssignScriptList.Add("
`$Object.${Identifier} = `$${Identifier}")
}
}
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","
$ParameterAssignScript = $ParameterAssignScriptList | Join-String -Separator ""
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","
$ParameterAssignScript = $ParameterAssignScriptList | Join-String -Separator ""

$Script = "
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the \`"License\`");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an \`"AS IS\`" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------
$Script = "
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the \`"License\`");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an \`"AS IS\`" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Create a in-memory object for ${ObjectType}
.Description
Create a in-memory object for ${ObjectType}
<#
.Synopsis
Create a in-memory object for ${ObjectType}
.Description
Create a in-memory object for ${ObjectType}

.Outputs
${ObjectTypeWithNamespace}
.Link
https://docs.microsoft.com/powershell/module/az.${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
#>
function New-Az${ModulePrefix}${ObjectType}Object {
[OutputType('${ObjectTypeWithNamespace}')]
[CmdletBinding(PositionalBinding=`$false)]
Param(
${ParameterDefineScript}
)
.Outputs
${ObjectTypeWithNamespace}
.Link
https://docs.microsoft.com/powershell/module/az.${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
#>
function New-Az${ModulePrefix}${ObjectType}Object {
[OutputType('${ObjectTypeWithNamespace}')]
[CmdletBinding(PositionalBinding=`$false)]
Param(
${ParameterDefineScript}
)

process {
`$Object = [${ObjectTypeWithNamespace}]::New()
${ParameterAssignScript}
return `$Object
process {
`$Object = [${ObjectTypeWithNamespace}]::New()
${ParameterAssignScript}
return `$Object
}
}
"
Set-Content -Path $OutputPath -Value $Script
}
}
"
Set-Content -Path $OutputPath -Value $Script
}
}
34 changes: 34 additions & 0 deletions src/Functions/custom/FunctionsStack/LinuxFunctionsStacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,40 @@
"frameworks": [],
"isDeprecated": null
}
},
{
"id": null,
"name": "powershell",
"type": "Microsoft.Web/availableStacks?osTypeSelected=LinuxFunctions",
"properties": {
"name": "powershell",
"display": "PowerShell Core",
"dependency": null,
"majorVersions": [
{
"displayVersion": "7.0",
"runtimeVersion": "PowerShell|7",
"supportedFunctionsExtensionVersions": [
"~3"
],
"isDefault": true,
"minorVersions": [],
"applicationInsights": true,
"appSettingsDictionary": {
"FUNCTIONS_WORKER_RUNTIME": "powershell"
},
"siteConfigPropertiesDictionary": {
"use32BitWorkerProcess": false,
"linuxFxVersion": "PowerShell|7"
},
"isPreview": true,
"isDeprecated": false,
"isHidden": true
}
],
"frameworks": [],
"isDeprecated": null
}
}
],
"nextLink": null,
Expand Down
Loading