Skip to content
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
57 changes: 38 additions & 19 deletions templates/AzureFunction/build/build.config.psd1
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
@{
TimerTrigger = @{
# Default Schedule for timed executions
Schedule = '0 5 * * * *'
TimerTrigger = @{
# Default Schedule for timed executions
Schedule = '0 5 * * * *'

# Different Schedules for specific timed endpoints
ScheduleOverrides = @{
# 'Update-Whatever' = '0 5 12 * * *'
}
}
# Different Schedules for specific timed endpoints
ScheduleOverrides = @{
# 'Update-Whatever' = '0 5 12 * * *'
}
}

HttpTrigger = @{
<#
HttpTrigger = @{
<#
AuthLevels:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cfunctionsv2&pivots=programming-language-csharp#http-auth

anonymous: No Token needed (combine with Identity Provider for Entra ID auth without also needing a token)
function: (default) Require a function-endpoint-specific token with the request
admin: Require a Function-App-global admin token (master key) for the request
#>
AuthLevel = 'function'
AuthLevelOverrides = @{
# 'Set-Foo' = 'anonymous'
}
Methods = @('get', 'post')
MethodOverrides = @{
# 'Set-Foo' = 'delete'
}
}
AuthLevel = 'function'
AuthLevelOverrides = @{
# 'Set-Foo' = 'anonymous'
}
Methods = @('get', 'post')
MethodOverrides = @{
# 'Set-Foo' = 'delete'
}
}

EventGridTrigger = @{
<#
AuthLevels:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v4%2Cfunctionsv2&pivots=programming-language-csharp#http-auth

anonymous: No Token needed (combine with Identity Provider for Entra ID auth without also needing a token)
function: (default) Require a function-endpoint-specific token with the request
admin: Require a Function-App-global admin token (master key) for the request
#>
AuthLevel = 'function'
AuthLevelOverrides = @{
# 'Set-Foo' = 'anonymous'
}
Methods = @('get', 'post')
MethodOverrides = @{
# 'Set-Foo' = 'delete'
}
}
}
18 changes: 18 additions & 0 deletions templates/AzureFunction/build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ foreach ($command in Get-ChildItem -Path "$workingDirectory\þnameþ\functions\h
$httpConfig -replace '%AUTHLEVEL%', $authLevel -replace '%METHODS%', ($methods -join '", "') | Set-Content -Path "$($endpointFolder.FullName)\function.json"
}


# Generate Event Grid Trigger
$eventGridCode = Get-Content -Path "$PSScriptRoot\functionEventGrid\run.ps1" | Join-String -Separator "`n"
$eventGridConfig = Get-Content -Path "$PSScriptRoot\functionEventGrid\function.json" | Join-String -Separator "`n"
foreach ($command in Get-ChildItem -Path "$workingDirectory\þnameþ\functions\eventGridTrigger" -Recurse -File -Filter *.ps1) {
$authLevel = $config.EventGridTrigger.AuthLevel
if ($config.EventGridTrigger.AuthLevelOverrides.$($command.BaseName)) {
$authLevel = $config.EventGridTrigger.AuthLevelOverrides.$($command.BaseName)
}
$methods = $config.EventGridTrigger.Methods
if ($config.EventGridTrigger.MethodOverrides.$($command.BaseName)) {
$methods = $config.EventGridTrFigger.MethodOverrides.$($command.BaseName)
}
$endpointFolder = New-Item -Path $buildFolder.FullName -Name $command.BaseName -ItemType Directory
$eventGridCode -replace '%COMMAND%',$command.BaseName | Set-Content -Path "$($endpointFolder.FullName)\run.ps1"
$eventGridConfig -replace '%AUTHLEVEL%', $authLevel -replace '%METHODS%', ($methods -join '", "') | Set-Content -Path "$($endpointFolder.FullName)\function.json"
}

# Generate Timer Trigger
$timerCode = Get-Content -Path "$PSScriptRoot\functionTimer\run.ps1" | Join-String -Separator "`n"
$timerConfig = Get-Content -Path "$PSScriptRoot\functionTimer\function.json" | Join-String -Separator "`n"
Expand Down
19 changes: 19 additions & 0 deletions templates/AzureFunction/build/functionEventGrid/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "%AUTHLEVEL%",
"type": "eventGridTrigger",
"direction": "in",
"name": "EventGridEvent",
"methods": [
"%METHODS%"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
],
"disabled": false
}
24 changes: 24 additions & 0 deletions templates/AzureFunction/build/functionEventGrid/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
param (
$EventGridEvent,

$TriggerMetadata
)


Write-Host "Trigger: %COMMAND% has been invoked"

$parameters = Get-RestParameter -Request $Request -Command %COMMAND%

try {
$results = %COMMAND% @parameters -ErrorAction Stop
}
catch {
$_ | Out-String | ForEach-Object {
foreach ($line in ($_ -split "`n")) {
Write-Warning $line
}
}
Write-FunctionResult -Status InternalServerError -Body "$_"
return
}
Write-FunctionResult -Status OK -Body $results
4 changes: 4 additions & 0 deletions templates/AzureFunctionEventGrid/PSMDInvoke.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
param (
$Path
)
New-PSMDTemplate -ReferencePath "$PSScriptRoot" -OutPath $Path
10 changes: 10 additions & 0 deletions templates/AzureFunctionEventGrid/PSMDTemplate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@{
TemplateName = 'AzureFunctionEventGrid'
Version = "1.0.0.0"
AutoIncrementVersion = $true
Tags = 'azure', 'function', 'eventgrid'
Author = 'Jan-Hendrik Peters'
Description = 'Event Grid trigger endpoint for the basic Azure Function Template'
Exclusions = @("PSMDInvoke.ps1", ".PSMDDependency") # Contains list of files - relative path to root - to ignore when building the template
Scripts = @{ }
}
15 changes: 15 additions & 0 deletions templates/AzureFunctionEventGrid/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"bindings": [
{
"type": "eventGridTrigger",
"name": "EventGridEvent",
"direction": "in"
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
],
"disabled": false
}
23 changes: 23 additions & 0 deletions templates/AzureFunctionEventGrid/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param (
$EventGridEvent,

$TriggerMetadata
)

Write-Host "Trigger: %COMMAND% has been invoked"

$parameters = Get-RestParameter -Request $EventGridEvent -Command %COMMAND%

try {
$results = %COMMAND% @parameters -ErrorAction Stop
}
catch {
$_ | Out-String | ForEach-Object {
foreach ($line in ($_ -split "`n")) {
Write-Warning $line
}
}
Write-FunctionResult -Status InternalServerError -Body "$_"
return
}
Write-FunctionResult -Status OK -Body $results