| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Sets the named pipe options for a Kestrun server instance. (Windows Operating Systems only) |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function sets the named pipe options for the specified Kestrun server instance, allowing for configuration of v |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance to configure. This parameter is mandatory and must be a valid server object. |
| | | 8 | | .PARAMETER Options |
| | | 9 | | The NamedPipeTransportOptions object containing the desired named pipe configuration settings. |
| | | 10 | | This parameter is mandatory when using the 'Options' parameter set. |
| | | 11 | | .PARAMETER ListenerQueueCount |
| | | 12 | | Specifies the number of named pipe listener queues to create for the server. This parameter is optional and can be s |
| | | 13 | | .PARAMETER MaxReadBufferSize |
| | | 14 | | Specifies the maximum size, in bytes, of the read buffer for named pipe connections. This parameter is optional and |
| | | 15 | | .PARAMETER CurrentUserOnly |
| | | 16 | | If specified, the named pipe will only be accessible by the current user. This parameter is optional and can be left |
| | | 17 | | .PARAMETER MaxWriteBufferSize |
| | | 18 | | Specifies the maximum size, in bytes, of the write buffer for named pipe connections. This parameter is optional and |
| | | 19 | | .PARAMETER PipeSecurity |
| | | 20 | | Specifies the PipeSecurity object to apply to the named pipe. This parameter is optional and can be set to a specifi |
| | | 21 | | .PARAMETER PassThru |
| | | 22 | | If specified, the cmdlet will return the modified server instance after applying the named pipe options. |
| | | 23 | | .OUTPUTS |
| | | 24 | | [Kestrun.Hosting.KestrunHost] |
| | | 25 | | The modified Kestrun server instance with the updated named pipe options. |
| | | 26 | | .EXAMPLE |
| | | 27 | | Set-KrServerNamedPipeOptions -Server $server -ListenerQueueCount 5 -MaxReadBufferSize 65536 |
| | | 28 | | This command sets the named pipe options for the specified Kestrun server instance, configuring the listener queue c |
| | | 29 | | .EXAMPLE |
| | | 30 | | Set-KrServerNamedPipeOptions -Server $server -CurrentUserOnly |
| | | 31 | | This command configures the named pipe options for the specified Kestrun server instance to restrict access to the c |
| | | 32 | | .NOTES |
| | | 33 | | This function is for Windows Operating Systems only, as named pipes are not supported on Unix-based systems. |
| | | 34 | | The named pipe options will be applied to the server's options and will be used when the server is started to listen |
| | | 35 | | The named pipe transport options can be configured to optimize performance and security based on the specific requir |
| | | 36 | | The named pipe transport options can be set either by providing a complete NamedPipeTransportOptions object |
| | | 37 | | This function is designed to be used in the context of a Kestrun server setup and allows for flexible configuration |
| | | 38 | | #> |
| | | 39 | | function Set-KrServerNamedPipeOptions { |
| | | 40 | | [KestrunRuntimeApi('Definition')] |
| | | 41 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 42 | | [CmdletBinding(defaultParameterSetName = 'Items')] |
| | | 43 | | param( |
| | | 44 | | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] |
| | | 45 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 46 | | [Parameter(Mandatory = $true, ParameterSetName = 'Options')] |
| | | 47 | | [Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.NamedPipeTransportOptions]$Options, |
| | | 48 | | [Parameter( ParameterSetName = 'Items')] |
| | | 49 | | [int]$ListenerQueueCount, |
| | | 50 | | [Parameter( ParameterSetName = 'Items')] |
| | | 51 | | [long]$MaxReadBufferSize, |
| | | 52 | | [Parameter( ParameterSetName = 'Items')] |
| | | 53 | | [switch]$CurrentUserOnly, |
| | | 54 | | [Parameter( ParameterSetName = 'Items')] |
| | | 55 | | [long]$MaxWriteBufferSize, |
| | | 56 | | [Parameter( ParameterSetName = 'Items')] |
| | | 57 | | [System.IO.Pipes.PipeSecurity]$PipeSecurity, |
| | | 58 | | [Parameter()] |
| | | 59 | | [switch]$PassThru |
| | | 60 | | ) |
| | | 61 | | begin { |
| | 0 | 62 | | if (-not $IsWindows) { |
| | 0 | 63 | | Write-Warning 'This function is for Windows Operating Systems only, as named pipes are not supported nativel |
| | | 64 | | } |
| | | 65 | | # Ensure the server instance is resolved |
| | 0 | 66 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 67 | | } |
| | | 68 | | process { |
| | 0 | 69 | | if ($PSCmdlet.ParameterSetName -eq 'Items') { |
| | 0 | 70 | | $Options = [Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.NamedPipeTransportOptions]::new() |
| | 0 | 71 | | if ($null -ne $ListenerQueueCount) { |
| | 0 | 72 | | Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting NamedPipeOptions.ListenerQueueCount |
| | 0 | 73 | | $options.ListenerQueueCount = $ListenerQueueCount |
| | | 74 | | } |
| | 0 | 75 | | if ($null -ne $MaxReadBufferSize) { |
| | 0 | 76 | | Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting NamedPipeOptions.MaxReadBufferSize t |
| | 0 | 77 | | $options.MaxReadBufferSize = $MaxReadBufferSize |
| | | 78 | | } |
| | 0 | 79 | | if ($CurrentUserOnly.IsPresent) { |
| | 0 | 80 | | Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting NamedPipeOptions.CurrentUserOnly to |
| | 0 | 81 | | $Options.CurrentUserOnly = $true |
| | | 82 | | } |
| | 0 | 83 | | if ($null -ne $MaxWriteBufferSize) { |
| | 0 | 84 | | Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting NamedPipeOptions.MaxWriteBufferSize |
| | 0 | 85 | | $Options.MaxWriteBufferSize = $MaxWriteBufferSize |
| | | 86 | | } |
| | 0 | 87 | | if ($null -ne $PipeSecurity) { |
| | 0 | 88 | | Write-KrLog -Logger $Server.Logger -Level Verbose -Message "Setting NamedPipeOptions.PipeSecurity to {Pi |
| | 0 | 89 | | $Options.PipeSecurity = $PipeSecurity |
| | | 90 | | } |
| | | 91 | | } |
| | | 92 | | |
| | 0 | 93 | | $Server.Options.NamedPipeOptions = $Options |
| | | 94 | | |
| | 0 | 95 | | if ($PassThru.IsPresent) { |
| | | 96 | | # if the PassThru switch is specified, return the modified server instance |
| | 0 | 97 | | return $Server |
| | | 98 | | } |
| | | 99 | | } |
| | | 100 | | } |
| | | 101 | | |