Enhance configuration data handling with new reference resolution functions, dummy secret support, and update module version to 1.1.0
This commit is contained in:
46
Private/Resolve-ConfigurationDataReference.ps1
Normal file
46
Private/Resolve-ConfigurationDataReference.ps1
Normal file
@@ -0,0 +1,46 @@
|
||||
function Resolve-ConfigurationDataReference {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[AllowEmptyString()]
|
||||
[string]
|
||||
$Property = "",
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
$Context
|
||||
)
|
||||
|
||||
$ReferenceKey = $Path
|
||||
if(-not [string]::IsNullOrWhiteSpace($Property)){
|
||||
$ReferenceKey = "$Path::$Property"
|
||||
}
|
||||
|
||||
if($Context.ReferenceCache.ContainsKey($ReferenceKey)){
|
||||
return $Context.ReferenceCache[$ReferenceKey]
|
||||
}
|
||||
|
||||
if($Context.ResolvingReferences.ContainsKey($ReferenceKey)){
|
||||
$Stack = @($Context.ResolvingReferences.Keys) + $ReferenceKey
|
||||
throw "Circular configuration data reference detected: $($Stack -join ' -> ')."
|
||||
}
|
||||
|
||||
$Context.ResolvingReferences[$ReferenceKey] = $true
|
||||
try {
|
||||
$RawValue = Get-ConfigurationDataPathValue -Value $Context.ConfigurationData -Path $Path
|
||||
$ResolvedValue = Resolve-ConfigurationDataValue -Value $RawValue -Context $Context
|
||||
|
||||
if(-not [string]::IsNullOrWhiteSpace($Property)){
|
||||
$ResolvedValue = Get-ConfigurationDataObjectPropertyValue -Value $ResolvedValue -Property $Property -Path $Path
|
||||
}
|
||||
|
||||
$Context.ReferenceCache[$ReferenceKey] = $ResolvedValue
|
||||
return $ResolvedValue
|
||||
}
|
||||
finally {
|
||||
$Context.ResolvingReferences.Remove($ReferenceKey)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user