Add functions for configuration data handling and extend template merging capabilities

This commit is contained in:
Torsten Brendgen
2026-07-03 10:34:27 +02:00
parent 735bfc9f61
commit fcbe61902f
8 changed files with 408 additions and 76 deletions

View File

@@ -0,0 +1,42 @@
function Get-ConfigurationDataTemplateMergeFile {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]
$Path,
[Parameter(Mandatory=$false)]
[hashtable]
$Visited = @{}
)
$ResolvedPath = Resolve-ConfigurationDataTemplatePath -Path $Path
if($Visited.ContainsKey($ResolvedPath)){
$Chain = @($Visited.Keys + $ResolvedPath) -join " -> "
throw "Circular configuration data template inheritance detected: $Chain"
}
$Visited[$ResolvedPath] = $true
$ConfigurationData = Import-PowerShellDataFile -Path $ResolvedPath
if($ConfigurationData -isnot [System.Collections.IDictionary]){
throw "Configuration data template [$ResolvedPath] must contain a hashtable."
}
$Files = @()
$BasePath = Split-Path -Path $ResolvedPath -Parent
foreach($ParentPath in @(Get-ConfigurationDataTemplateExtends -ConfigurationData $ConfigurationData)){
if([string]::IsNullOrWhiteSpace([string]$ParentPath)){
continue
}
$ResolvedParentPath = Resolve-ConfigurationDataTemplatePath -Path ([string]$ParentPath) -BasePath $BasePath
$Files += @(Get-ConfigurationDataTemplateMergeFile -Path $ResolvedParentPath -Visited $Visited)
}
$Files += $ResolvedPath
$Visited.Remove($ResolvedPath)
return @($Files)
}