| | 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 |
| 0 | 67 | | if ($null -eq $Server) { |
| 0 | 68 | | throw 'Server is not initialized. Please ensure the server is configured before setting options.' |
| | 69 | | } |
| | 70 | | } |
| | 71 | | process { |
| 0 | 72 | | if ($PSCmdlet.ParameterSetName -eq 'Items') { |
| 0 | 73 | | $Options = [Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.NamedPipeTransportOptions]::new() |
| 0 | 74 | | if ($null -ne $ListenerQueueCount) { |
| 0 | 75 | | Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting NamedPipeOptions.ListenerQueueCo |
| 0 | 76 | | $options.ListenerQueueCount = $ListenerQueueCount |
| | 77 | | } |
| 0 | 78 | | if ($null -ne $MaxReadBufferSize) { |
| 0 | 79 | | Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting NamedPipeOptions.MaxReadBufferSi |
| 0 | 80 | | $options.MaxReadBufferSize = $MaxReadBufferSize |
| | 81 | | } |
| 0 | 82 | | if ($CurrentUserOnly.IsPresent) { |
| 0 | 83 | | Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting NamedPipeOptions.CurrentUserOnly |
| 0 | 84 | | $Options.CurrentUserOnly = $true |
| | 85 | | } |
| 0 | 86 | | if ($null -ne $MaxWriteBufferSize) { |
| 0 | 87 | | Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting NamedPipeOptions.MaxWriteBufferS |
| 0 | 88 | | $Options.MaxWriteBufferSize = $MaxWriteBufferSize |
| | 89 | | } |
| 0 | 90 | | if ($null -ne $PipeSecurity) { |
| 0 | 91 | | Write-KrLog -Logger $Server.HostLogger -Level Verbose -Message "Setting NamedPipeOptions.PipeSecurity to |
| 0 | 92 | | $Options.PipeSecurity = $PipeSecurity |
| | 93 | | } |
| | 94 | | } |
| | 95 | |
|
| 0 | 96 | | $Server.Options.NamedPipeOptions = $Options |
| | 97 | |
|
| 0 | 98 | | if ($PassThru.IsPresent) { |
| | 99 | | # if the PassThru switch is specified, return the server instance |
| | 100 | | # Return the modified server instance |
| 0 | 101 | | return $Server |
| | 102 | | } |
| | 103 | | } |
| | 104 | | } |
| | 105 | |
|