Skip to content

Commit fa51040

Browse files
template updates
1 parent fd486be commit fa51040

File tree

24 files changed

+230
-14
lines changed

24 files changed

+230
-14
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Version number of this module.
77

8-
ModuleVersion = '2.2.11.146'
8+
ModuleVersion = '2.2.11.163'
99

1010
# ID used to uniquely identify this module
1111
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'

PSModuleDevelopment/changelog.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
# Changelog
22

3-
## Unreleased
3+
## 2.2.11.163 (2024-02-25)
44

55
+ New: Template ApplockerPipeline - A project that can be used to generate AppLocker policies across environments
6+
+ Upd: Template AzureFunction - Added automatic Endpoint generation based on functions defined in the module
67
+ Upd: Template PSFProject - Improved PSScriptAnalyzer test results
8+
+ Upd: Template PSFProject - Extended list of blacklisted commands
9+
+ Upd: Template PSFProject - Build logic now also supports compiling the C# solution
710
+ Upd: Template PSFModule - Improved PSScriptAnalyzer test results
11+
+ Upd: Template PSFModule - Extended list of blacklisted commands
812
+ Upd: Template PSFHelp - Improved PSScriptAnalyzer test results
13+
+ Upd: Template PSFHelp - Extended list of blacklisted commands
14+
+ Upd: Template MiniModule - Extended list of blacklisted commands
915
+ Fix: Template PSFProject - Help test fails on PS7.4
16+
+ Fix: Template PSFProject - Help test added ProgressAction to common parameters
1017
+ Fix: Template PSFModule - Help test fails on PS7.4
18+
+ Fix: Template PSFModule - Help test added ProgressAction to common parameters
1119
+ Fix: Template PSFHelp - Help test fails on PS7.4
20+
+ Fix: Template PSFHelp - Help test added ProgressAction to common parameters
21+
+ Fix: Template MiniModule - Help test - added ProgressAction to common parameters
1222

1323
## 2.2.11.146 (2023-05-31)
1424

PSModuleDevelopment/functions/templating/Invoke-PSMDTemplate.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
PS C:\> Invoke-PSMDTemplate -TemplateName "module" -Name "MyModule"
8383
8484
Creates a project based on the module template with the name "MyModule"
85+
86+
.EXAMPLE
87+
PS C:\> Invoke-PSMDTemplate MiniModule -Parameters @{ Author = 'Fred' }
88+
89+
Creates a new project based on the template MiniModule and predefines the value for the "Author" placeholder.
8590
#>
8691
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSPossibleIncorrectUsageOfAssignmentOperator", "")]
8792
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '')]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@{
2+
TimerTrigger = @{
3+
# Default Schedule for timed executions
4+
Schedule = '0 5 * * * *'
5+
6+
# Different Schedules for specific timed endpoints
7+
ScheduleOverrides = @{
8+
# 'Update-Whatever' = '0 5 12 * * *'
9+
}
10+
}
11+
12+
HttpTrigger = @{
13+
<#
14+
AuthLevels:
15+
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
16+
17+
anonymous: No Token needed (combine with Identity Provider for Entra ID auth without also needing a token)
18+
function: (default) Require a function-endpoint-specific token with the request
19+
admin: Require a Function-App-global admin token (master key) for the request
20+
#>
21+
AuthLevel = 'function'
22+
AuthLevelOverrides = @{
23+
# 'Set-Foo' = 'anonymous'
24+
}
25+
}
26+
}
Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
param (
2-
[string]
3-
$Repository = 'PSGallery'
2+
[string]
3+
$Repository = 'PSGallery',
4+
5+
[string]
6+
$AppRg,
7+
8+
[string]
9+
$AppName
410
)
511
$workingDirectory = Split-Path $PSScriptRoot
12+
$config = Import-PowerShellDataFile -Path "$PSScriptRoot\build.config.psd1"
613

714
# Prepare output path and copy function folder
815
Remove-Item -Path "$workingDirectory/publish" -Recurse -Force -ErrorAction Ignore
@@ -12,12 +19,46 @@ Copy-Item -Path "$workingDirectory/function/*" -Destination $buildFolder.FullNam
1219
# Process Dependencies
1320
$requiredModules = (Import-PowerShellDataFile -Path "$workingDirectory/þnameþ/þnameþ.psd1").RequiredModules
1421
foreach ($module in $requiredModules) {
15-
Save-Module -Name $module -Path "$($buildFolder.FullName)/modules" -Force -Repository $Repository
22+
Save-Module -Name $module -Path "$($buildFolder.FullName)/modules" -Force -Repository $Repository
1623
}
1724

1825
# Process Function Module
1926
Copy-Item -Path "$workingDirectory/þnameþ" -Destination "$($buildFolder.FullName)/modules" -Force -Recurse
27+
$commands = Get-ChildItem -Path "$($buildFolder.FullName)/modules/þnameþ/Functions" -Recurse -Filter *.ps1 | ForEach-Object BaseName
28+
Update-ModuleManifest -Path "$($buildFolder.FullName)/modules/þnameþ/þnameþ.psd1" -FunctionsToExport $commands
29+
30+
# Generate Http Trigger
31+
$httpCode = Get-Content -Path "$PSScriptRoot\functionHttp\run.ps1" | Join-String "`n"
32+
$httpConfig = Get-Content -Path "$PSScriptRoot\functionHttp\function.json" | Join-String "`n"
33+
foreach ($command in Get-ChildItem -Path "$workingDirectory\þnameþ\functions\httpTrigger" -Recurse -File -Filter *.ps1) {
34+
$authLevel = $config.HttpTrigger.AuthLevel
35+
if ($config.HttpTrigger.AuthLevelOverride.$($command.BaseName)) {
36+
$authLevel = $config.HttpTrigger.AuthLevelOverride.$($command.BaseName)
37+
}
38+
$endpointFolder = New-Item -Path $buildFolder.FullName -Name $command.BaseName -ItemType Directory
39+
$httpCode -replace '%COMMAND%',$command.BaseName | Set-Content -Path "$($endpointFolder.FullName)\run.ps1"
40+
$httpConfig -replace '%AUTHLEVEL%', $authLevel | Set-Content -Path "$($endpointFolder.FullName)\function.json"
41+
}
42+
43+
# Generate Timer Trigger
44+
$timerCode = Get-Content -Path "$PSScriptRoot\functionTimer\run.ps1" | Join-String "`n"
45+
$timerConfig = Get-Content -Path "$PSScriptRoot\functionTimer\function.json" | Join-String "`n"
46+
foreach ($command in Get-ChildItem -Path "$workingDirectory\þnameþ\functions\timerTrigger" -Recurse -File -Filter *.ps1) {
47+
$schedule = $config.TimerTrigger.Schedule
48+
if ($config.TimerTrigger.ScheduleOverride.$($command.BaseName)) {
49+
$schedule = $config.TimerTrigger.ScheduleOverride.$($command.BaseName)
50+
}
51+
$endpointFolder = New-Item -Path $buildFolder.FullName -Name $command.BaseName -ItemType Directory
52+
$timerCode -replace '%COMMAND%',$command.BaseName | Set-Content -Path "$($endpointFolder.FullName)\run.ps1"
53+
$timerConfig -replace '%SCHEDULE%', $schedule | Set-Content -Path "$($endpointFolder.FullName)\function.json"
54+
}
2055

2156
# Package & Cleanup
57+
Remove-Item -Path "$workingDirectory/Function.zip" -Recurse -Force -ErrorAction Ignore
2258
Compress-Archive -Path "$($buildFolder.FullName)/*" -DestinationPath "$workingDirectory/Function.zip"
23-
Remove-Item -Path $buildFolder.FullName -Recurse -Force -ErrorAction Ignore
59+
Remove-Item -Path $buildFolder.FullName -Recurse -Force -ErrorAction Ignore
60+
61+
if ($AppRg -and $AppName) {
62+
Write-Host "Publishing Function App to $AppRg/$AppName"
63+
Publish-AzWebApp -ResourceGroupName $AppRG -Name $AppName -ArchivePath "$workingDirectory/Function.zip" -Confirm:$false -Force
64+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"bindings": [
3+
{
4+
"authLevel": "%AUTHLEVEL%",
5+
"type": "httpTrigger",
6+
"direction": "in",
7+
"name": "Request",
8+
"methods": [
9+
"get",
10+
"post"
11+
]
12+
},
13+
{
14+
"type": "http",
15+
"direction": "out",
16+
"name": "Response"
17+
}
18+
],
19+
"disabled": false
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
param (
2+
$Request,
3+
4+
$TriggerMetadata
5+
)
6+
7+
8+
Write-Host "Trigger: %COMMAND% has been invoked"
9+
10+
$parameters = Get-RestParameter -Request $Request -Command %COMMAND%
11+
12+
try {
13+
$results = %COMMAND% @parameters -ErrorAction Stop
14+
}
15+
catch {
16+
$_ | Out-String | ForEach-Object {
17+
foreach ($line in ($_ -split "`n")) {
18+
Write-Warning $line
19+
}
20+
}
21+
Write-FunctionResult -Status InternalServerError -Body "$_"
22+
return
23+
}
24+
Write-FunctionResult -Status OK -Body $results
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"bindings": [
3+
{
4+
"name": "Timer",
5+
"type": "timerTrigger",
6+
"direction": "in",
7+
"schedule": "%SCHEDULE%"
8+
}
9+
],
10+
"disabled": false
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Input bindings are passed in via param block.
2+
param ($Timer)
3+
4+
$ErrorActionPreference = 'Stop'
5+
Write-Host "%COMMAND% start time: $((Get-Date).ToUniversalTime())"
6+
try { %COMMAND% }
7+
catch {
8+
Write-Warning "%COMMAND% failed: $_ $((Get-Date).ToUniversalTime())"
9+
throw "%COMMAND% failed: $_ $((Get-Date).ToUniversalTime())"
10+
}
11+
Write-Host "%COMMAND% end time: $((Get-Date).ToUniversalTime())"

0 commit comments

Comments
 (0)