Private/Test-KadenDelimitedInstructionDestination.ps1
|
$script:KadenDelimitedCacheRoot = $null $script:KadenDelimitedCacheStamp = $null $script:KadenDelimitedCache = $null function Get-KadenDelimitedInstructionDestination { <# .SYNOPSIS Return managed destinations that are injected as delimited blocks. .DESCRIPTION The managed-file manifest is the inventory. An entry with injection delimited is skipped by the wholesale copy and written by instruction injection. #> [CmdletBinding()] param() $payloadRoot = Get-KadenPayloadRoot $manifestPath = Join-Path $payloadRoot 'kaden-managed-files.json' $stamp = (Get-Item -LiteralPath $manifestPath).LastWriteTimeUtc.Ticks if ($script:KadenDelimitedCacheRoot -eq $payloadRoot -and $script:KadenDelimitedCacheStamp -eq $stamp -and $null -ne $script:KadenDelimitedCache) { return @($script:KadenDelimitedCache) } $manifest = Get-Content -LiteralPath $manifestPath -Raw | ConvertFrom-Json $list = New-Object System.Collections.Generic.List[string] foreach ($entry in @($manifest.files)) { $injectionProperty = $entry.PSObject.Properties['injection'] if ($null -eq $injectionProperty -or [string]$injectionProperty.Value -ne 'delimited') { continue } $key = ConvertTo-KadenDelimitedInstructionKey -Destination ([string]$entry.destination) if (-not [string]::IsNullOrWhiteSpace($key)) { $list.Add($key) } } $script:KadenDelimitedCacheRoot = $payloadRoot $script:KadenDelimitedCacheStamp = $stamp $script:KadenDelimitedCache = @($list) return @($script:KadenDelimitedCache) } function ConvertTo-KadenDelimitedInstructionKey { <# .SYNOPSIS Normalize a managed destination for delimited-injection comparison. #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [AllowEmptyString()] [string]$Destination ) $normalized = ($Destination -replace '\\', '/').Trim().ToLowerInvariant() $segments = @($normalized -split '/' | Where-Object { -not [string]::IsNullOrWhiteSpace($_) -and $_ -ne '.' }) return ($segments -join '/') } function Test-KadenDelimitedInstructionDestination { <# .SYNOPSIS Return true when a managed destination is injected as a delimited block. #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Destination ) $key = ConvertTo-KadenDelimitedInstructionKey -Destination $Destination foreach ($allowed in @(Get-KadenDelimitedInstructionDestination)) { if ($key -eq $allowed) { return $true } } return $false } |