| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Reads a Service.psd1 descriptor file. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | Reads Service.psd1 and returns a normalized object with FormatVersion, Name, Description, Version, EntryPoint, Servi |
| | | 6 | | .PARAMETER Path |
| | | 7 | | Descriptor path. Accepts either a descriptor file path or a directory path. |
| | | 8 | | When a directory path is provided, Service.psd1 is appended automatically. |
| | | 9 | | .EXAMPLE |
| | | 10 | | Get-KrServiceDescriptor |
| | | 11 | | #> |
| | | 12 | | function Get-KrServiceDescriptor { |
| | | 13 | | [KestrunRuntimeApi('Everywhere')] |
| | | 14 | | [CmdletBinding()] |
| | | 15 | | [OutputType([pscustomobject])] |
| | | 16 | | param( |
| | | 17 | | [Parameter()] |
| | | 18 | | [ValidateNotNullOrEmpty()] |
| | | 19 | | [string]$Path = 'Service.psd1' |
| | | 20 | | ) |
| | | 21 | | |
| | 1 | 22 | | $fullPath = [System.IO.Path]::GetFullPath($Path) |
| | 1 | 23 | | if (Test-Path -LiteralPath $fullPath -PathType Container) { |
| | 1 | 24 | | $fullPath = Join-Path -Path $fullPath -ChildPath 'Service.psd1' |
| | | 25 | | } |
| | | 26 | | |
| | 2 | 27 | | if (-not (Test-Path -LiteralPath $fullPath -PathType Leaf)) { |
| | 0 | 28 | | throw "Descriptor file not found: $fullPath" |
| | | 29 | | } |
| | 1 | 30 | | $descriptor = Import-PowerShellDataFile -LiteralPath $fullPath |
| | 2 | 31 | | if (-not $descriptor -or -not ($descriptor -is [hashtable])) { |
| | 0 | 32 | | throw "Descriptor file '$fullPath' is not a valid hashtable." |
| | | 33 | | } |
| | 2 | 34 | | $normalizedDescriptor = Test-KrServiceDescriptorData -Descriptor $descriptor -DescriptorPath $fullPath -PackageRoot |
| | 1 | 35 | | if (-not $normalizedDescriptor) { |
| | 0 | 36 | | throw "Descriptor file '$fullPath' failed validation." |
| | | 37 | | } |
| | | 38 | | |
| | 1 | 39 | | $preservePaths = @() |
| | 1 | 40 | | if ($normalizedDescriptor.PSObject.Properties.Match('PreservePaths').Count -gt 0 -and $null -ne $normalizedDescripto |
| | 2 | 41 | | $preservePaths = @($normalizedDescriptor.PreservePaths) |
| | | 42 | | } |
| | | 43 | | |
| | 1 | 44 | | $props = $normalizedDescriptor.PSObject.Properties |
| | | 45 | | |
| | 2 | 46 | | [pscustomobject]([ordered]@{ |
| | 1 | 47 | | FormatVersion = [string]$normalizedDescriptor.FormatVersion |
| | 1 | 48 | | Path = $fullPath |
| | 1 | 49 | | Name = [string]$normalizedDescriptor.Name |
| | 3 | 50 | | Description = if ($props['Description']) { [string]$normalizedDescriptor.Description } else { $null } |
| | 1 | 51 | | Version = if ($props['Version'] -and -not [string]::IsNullOrWhiteSpace($normalizedDescriptor.Version)) { |
| | 1 | 52 | | [string]$normalizedDescriptor.Version |
| | | 53 | | } else { |
| | 1 | 54 | | $null |
| | | 55 | | } |
| | 3 | 56 | | EntryPoint = if ($props['EntryPoint']) { [string]$normalizedDescriptor.EntryPoint } else { $null } |
| | 3 | 57 | | ServiceLogPath = if ($props['ServiceLogPath']) { [string]$normalizedDescriptor.ServiceLogPath } else { $null |
| | 1 | 58 | | PreservePaths = $preservePaths |
| | | 59 | | }) |
| | | 60 | | } |