From 51a7c9d5f0c147dd7787daf4b6c994745c8ed5bf Mon Sep 17 00:00:00 2001 From: Friedrich Weinmann Date: Fri, 31 May 2024 08:27:52 +0200 Subject: [PATCH] AzureFunction template update --- PSModuleDevelopment/PSModuleDevelopment.psd1 | 2 +- PSModuleDevelopment/changelog.md | 8 ++++++ templates/AzureFunction/PSMDTemplate.ps1 | 2 +- .../AzureFunction/build/build.config.psd1 | 4 +++ templates/AzureFunction/build/build.ps1 | 22 +++++++++------- .../build/functionHttp/function.json | 3 +-- templates/AzureFunction/function/host.json | 25 ++++++++++++++++--- templates/MiniModule/.github/FUNDING.yml | 3 +-- 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/PSModuleDevelopment/PSModuleDevelopment.psd1 b/PSModuleDevelopment/PSModuleDevelopment.psd1 index 71ce75e..8cfb0c9 100644 --- a/PSModuleDevelopment/PSModuleDevelopment.psd1 +++ b/PSModuleDevelopment/PSModuleDevelopment.psd1 @@ -5,7 +5,7 @@ # Version number of this module. - ModuleVersion = '2.2.11.163' + ModuleVersion = '2.2.11.168' # ID used to uniquely identify this module GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6' diff --git a/PSModuleDevelopment/changelog.md b/PSModuleDevelopment/changelog.md index 8178cec..f48423b 100644 --- a/PSModuleDevelopment/changelog.md +++ b/PSModuleDevelopment/changelog.md @@ -1,5 +1,13 @@ # Changelog +## 2.2.11.168 (2024-05-31) + ++ Upd: Template AzureFunction - added config option to override http Endpoint methods (#198) ++ Upd: Template AzureFunction - updated host.json to include some default headers (#197) ++ Fix: Template AzureFunction - build script ignores some overrides due to typo (#199) ++ Fix: Template AzureFunction - build fails when executing without the String module loaded (#196) ++ Fix: Template MiniModule - Automatically adds wrong github sponsor accountname + ## 2.2.11.163 (2024-02-25) + New: Template ApplockerPipeline - A project that can be used to generate AppLocker policies across environments diff --git a/templates/AzureFunction/PSMDTemplate.ps1 b/templates/AzureFunction/PSMDTemplate.ps1 index 131be22..da95b9b 100644 --- a/templates/AzureFunction/PSMDTemplate.ps1 +++ b/templates/AzureFunction/PSMDTemplate.ps1 @@ -1,6 +1,6 @@ @{ TemplateName = 'AzureFunction' - Version = "2.0.0" + Version = "2.0.5" AutoIncrementVersion = $true Tags = 'azure', 'function' Author = 'Friedrich Weinmann' diff --git a/templates/AzureFunction/build/build.config.psd1 b/templates/AzureFunction/build/build.config.psd1 index 8822c4a..21bbff1 100644 --- a/templates/AzureFunction/build/build.config.psd1 +++ b/templates/AzureFunction/build/build.config.psd1 @@ -22,5 +22,9 @@ AuthLevelOverrides = @{ # 'Set-Foo' = 'anonymous' } + Methods = @('get', 'post') + MethodOverrides = @{ + # 'Set-Foo' = 'delete' + } } } \ No newline at end of file diff --git a/templates/AzureFunction/build/build.ps1 b/templates/AzureFunction/build/build.ps1 index 35a4530..753908c 100644 --- a/templates/AzureFunction/build/build.ps1 +++ b/templates/AzureFunction/build/build.ps1 @@ -28,25 +28,29 @@ $commands = Get-ChildItem -Path "$($buildFolder.FullName)/modules/þnameþ/Funct Update-ModuleManifest -Path "$($buildFolder.FullName)/modules/þnameþ/þnameþ.psd1" -FunctionsToExport $commands # Generate Http Trigger -$httpCode = Get-Content -Path "$PSScriptRoot\functionHttp\run.ps1" | Join-String "`n" -$httpConfig = Get-Content -Path "$PSScriptRoot\functionHttp\function.json" | Join-String "`n" +$httpCode = Get-Content -Path "$PSScriptRoot\functionHttp\run.ps1" | Join-String -Separator "`n" +$httpConfig = Get-Content -Path "$PSScriptRoot\functionHttp\function.json" | Join-String -Separator "`n" foreach ($command in Get-ChildItem -Path "$workingDirectory\þnameþ\functions\httpTrigger" -Recurse -File -Filter *.ps1) { $authLevel = $config.HttpTrigger.AuthLevel - if ($config.HttpTrigger.AuthLevelOverride.$($command.BaseName)) { - $authLevel = $config.HttpTrigger.AuthLevelOverride.$($command.BaseName) + if ($config.HttpTrigger.AuthLevelOverrides.$($command.BaseName)) { + $authLevel = $config.HttpTrigger.AuthLevelOverrides.$($command.BaseName) + } + $methods = $config.HttpTrigger.Methods + if ($config.HttpTrigger.MethodOverrides.$($command.BaseName)) { + $methods = $config.HttpTrigger.MethodOverrides.$($command.BaseName) } $endpointFolder = New-Item -Path $buildFolder.FullName -Name $command.BaseName -ItemType Directory $httpCode -replace '%COMMAND%',$command.BaseName | Set-Content -Path "$($endpointFolder.FullName)\run.ps1" - $httpConfig -replace '%AUTHLEVEL%', $authLevel | Set-Content -Path "$($endpointFolder.FullName)\function.json" + $httpConfig -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 "`n" -$timerConfig = Get-Content -Path "$PSScriptRoot\functionTimer\function.json" | Join-String "`n" +$timerCode = Get-Content -Path "$PSScriptRoot\functionTimer\run.ps1" | Join-String -Separator "`n" +$timerConfig = Get-Content -Path "$PSScriptRoot\functionTimer\function.json" | Join-String -Separator "`n" foreach ($command in Get-ChildItem -Path "$workingDirectory\þnameþ\functions\timerTrigger" -Recurse -File -Filter *.ps1) { $schedule = $config.TimerTrigger.Schedule - if ($config.TimerTrigger.ScheduleOverride.$($command.BaseName)) { - $schedule = $config.TimerTrigger.ScheduleOverride.$($command.BaseName) + if ($config.TimerTrigger.ScheduleOverrides.$($command.BaseName)) { + $schedule = $config.TimerTrigger.ScheduleOverrides.$($command.BaseName) } $endpointFolder = New-Item -Path $buildFolder.FullName -Name $command.BaseName -ItemType Directory $timerCode -replace '%COMMAND%',$command.BaseName | Set-Content -Path "$($endpointFolder.FullName)\run.ps1" diff --git a/templates/AzureFunction/build/functionHttp/function.json b/templates/AzureFunction/build/functionHttp/function.json index 436ab49..7383800 100644 --- a/templates/AzureFunction/build/functionHttp/function.json +++ b/templates/AzureFunction/build/functionHttp/function.json @@ -6,8 +6,7 @@ "direction": "in", "name": "Request", "methods": [ - "get", - "post" + "%METHODS%" ] }, { diff --git a/templates/AzureFunction/function/host.json b/templates/AzureFunction/function/host.json index 7ea899d..004505e 100644 --- a/templates/AzureFunction/function/host.json +++ b/templates/AzureFunction/function/host.json @@ -1,6 +1,23 @@ { - "version": "2.0", - "managedDependency": { - "Enabled": true - } + "version": "2.0", + "extensions": { + "http": { + "routePrefix": "api", + "customHeaders": { + "Content-Security-Policy": "default-src 'self'", + "Permissions-Policy": "geolocation=()", + "X-Frame-Options": "SAMEORIGIN", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "X-Content-Type-Options": "nosniff", + "Referrer-Policy": "no-referrer" + } + } + }, + "managedDependency": { + "enabled": true + }, + "extensionBundle": { + "id": "Microsoft.Azure.Functions.ExtensionBundle", + "version": "[3.*, 4.0.0)" + } } \ No newline at end of file diff --git a/templates/MiniModule/.github/FUNDING.yml b/templates/MiniModule/.github/FUNDING.yml index ddf3214..4b16f59 100644 --- a/templates/MiniModule/.github/FUNDING.yml +++ b/templates/MiniModule/.github/FUNDING.yml @@ -1,7 +1,6 @@ # These are supported funding model platforms -github: - FriedrichWeinmann +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username