< Summary - Kestrun — Combined Coverage

Information
Class: Public.Server.Set-KrServerHttpsOption
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Set-KrServerHttpsOption.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 112
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Set-KrServerHttpsOption.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Configures HTTPS options for a Kestrun server instance.
 4.DESCRIPTION
 5    This function allows administrators to set or modify the HTTPS connection adapter options for a Kestrun
 6server instance, including SSL protocols, client certificate modes, and server certificates.
 7.PARAMETER Server
 8    The Kestrun server instance to configure. This parameter is mandatory and must be a valid server object.
 9.PARAMETER Options
 10    The HttpsConnectionAdapterOptions object containing the desired HTTPS configuration settings.
 11.PARAMETER SslProtocols
 12    Specifies the SSL protocols to be used for HTTPS connections. This parameter is optional and can be set to a specifi
 13.PARAMETER ClientCertificateMode
 14    Specifies the client certificate mode for HTTPS connections. This parameter is optional and can be set to a specific
 15.PARAMETER CheckCertificateRevocation
 16    If specified, enables certificate revocation checking for HTTPS connections. This parameter is optional and can be l
 17.PARAMETER ServerCertificate
 18    Specifies the server certificate to be used for HTTPS connections. This parameter is optional and can be left unset 
 19.PARAMETER ServerCertificateChain
 20    Specifies the server certificate chain to be used for HTTPS connections. This parameter is optional and can be left 
 21.PARAMETER HandshakeTimeout
 22    Specifies the handshake timeout duration in seconds for HTTPS connections. This parameter is optional and can be lef
 23.PARAMETER PassThru
 24    If specified, the cmdlet will return the modified server instance after applying the HTTPS options.
 25.OUTPUTS
 26    [Kestrun.Hosting.KestrunHost]
 27    The modified Kestrun server instance with the applied HTTPS options.
 28.EXAMPLE
 29    Set-KrServerHttpsOptions -Server $server -SslProtocols Tls12
 30    This command sets the SSL protocols for the specified Kestrun server instance to use TLS 1.2.
 31.EXAMPLE
 32    Set-KrServerHttpsOptions -Server $server -ClientCertificateMode RequireCertificate
 33    This command sets the client certificate mode for the specified Kestrun server instance to require a client certific
 34.EXAMPLE
 35    Set-KrServerHttpsOptions -Server $server -CheckCertificateRevocation
 36    This command enables certificate revocation checking for the specified Kestrun server instance.
 37.EXAMPLE
 38    Set-KrServerHttpsOptions -Server $server -ServerCertificate $cert
 39    This command sets the server certificate for the specified Kestrun server instance.
 40.EXAMPLE
 41    Set-KrServerHttpsOptions -Server $server -HandshakeTimeout 30
 42    This command sets the handshake timeout for the specified Kestrun server instance to 30 seconds.
 43.NOTES
 44    This function is designed to be used in the context of a Kestrun server setup and allows for flexible configuration 
 45    $ClientCertificateValidation, $ServerCertificateSelector, and $OnAuthenticate are currently not implemented in this 
 46#>
 47function Set-KrServerHttpsOptions {
 48    [KestrunRuntimeApi('Definition')]
 49    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
 50    [CmdletBinding(defaultParameterSetName = 'Items')]
 51    param(
 52        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 53        [Kestrun.Hosting.KestrunHost]$Server,
 54        [Parameter(Mandatory = $true, ParameterSetName = 'Options')]
 55        [Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionAdapterOptions]$Options,
 56        [Parameter( ParameterSetName = 'Items')]
 57        [System.Security.Authentication.SslProtocols]$SslProtocols,
 58        [Parameter( ParameterSetName = 'Items')]
 59        [Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode]$ClientCertificateMode,
 60        [Parameter( ParameterSetName = 'Items')]
 61        [switch]$CheckCertificateRevocation,
 62        [Parameter( ParameterSetName = 'Items')]
 63        [System.Security.Cryptography.X509Certificates.X509Certificate2]$ServerCertificate,
 64        [Parameter( ParameterSetName = 'Items')]
 65        [System.Security.Cryptography.X509Certificates.X509Certificate2Collection]$ServerCertificateChain,
 66        [Parameter( ParameterSetName = 'Items')]
 67        [int]$HandshakeTimeout,
 68        [Parameter()]
 69        [switch]$PassThru
 70    )
 71    begin {
 72        # Ensure the server instance is resolved
 073        $Server = Resolve-KestrunServer -Server $Server
 074        if ($null -eq $Server) {
 075            throw 'Server is not initialized. Please ensure the server is configured before setting options.'
 76        }
 77    }
 78    process {
 79
 080        if ($PSCmdlet.ParameterSetName -eq 'Items') {
 81
 082            $Options = [Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionAdapterOptions]::new()
 083            if ($null -ne $SslProtocols) {
 084                $options.SslProtocols = $SslProtocols
 85            }
 086            if ($null -ne $ClientCertificateMode) {
 087                $options.ClientCertificateMode = $ClientCertificateMode
 88            }
 089            if ($CheckCertificateRevocation.IsPresent) {
 090                $Options.CheckCertificateRevocation = $true
 91            }
 092            if ($null -ne $ServerCertificate) {
 093                $Options.ServerCertificate = $ServerCertificate
 94            }
 095            if ($null -ne $ServerCertificateChain) {
 096                $Options.ServerCertificateChain = $ServerCertificateChain
 97            }
 098            if ($null -ne $HandshakeTimeout) {
 099                $Options.HandshakeTimeout = [System.TimeSpan]::FromSeconds($HandshakeTimeout)
 100            }
 101        }
 102
 0103        $Server.Options.HttpsConnectionAdapter = $Options
 104
 0105        if ($PassThru.IsPresent) {
 106            # if the PassThru switch is specified, return the server instance
 107            # Return the modified server instance
 0108            return $Server
 109        }
 110    }
 111}
 112

Methods/Properties

Set-KrServerHttpsOptions()