Add functions for configuration data handling and extend template merging capabilities
This commit is contained in:
42
Private/Get-ConfigurationDataTemplateMergeFile.ps1
Normal file
42
Private/Get-ConfigurationDataTemplateMergeFile.ps1
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user