< Summary - Kestrun — Combined Coverage

Information
Class: Public.Certificate.Import-KrCertificate
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Certificate/Import-KrCertificate.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 7
Coverable lines: 7
Total lines: 38
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/Certificate/Import-KrCertificate.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Imports a PFX/PEM certificate file and returns X509Certificate2.
 4    .DESCRIPTION
 5        The Import-KrCertificate function allows you to import a certificate into the Kestrun environment.
 6        This may include loading a certificate from a file or other source and adding it to the appropriate certificate 
 7    .PARAMETER FilePath
 8        The path to the certificate file to import.
 9    .PARAMETER Password
 10        The password for the certificate file, if applicable.
 11    .PARAMETER PrivateKeyPath
 12        The path to the private key file, if applicable.
 13    .EXAMPLE
 14        Import-KrCertificate -Path "C:\certs\mycert.pfx" -Password (ConvertTo-SecureString "password" -AsPlainText -Forc
 15        This example imports a certificate from the specified path using the provided password.
 16    .NOTES
 17        This function is part of the Kestrun PowerShell module.
 18#>
 19function Import-KrCertificate {
 20    [KestrunRuntimeApi('Everywhere')]
 21    [CmdletBinding()]
 22    [OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
 23    param(
 24        [Parameter(Mandatory)][string] $FilePath,
 25        [securestring] $Password,
 26        [string] $PrivateKeyPath
 27    )
 028    $resolvedPath = Resolve-KrPath -Path $FilePath -KestrunRoot -Test
 029    Write-KrLog -Level Verbose -Message "Resolved file path: $resolvedPath"
 030    if ( -not (Test-Path -Path $resolvedPath -PathType Leaf)) {
 031        throw "Certificate file not found at path: $resolvedPath"
 32    }
 033    if ($null -eq $Password) {
 034        return [Kestrun.Certificates.CertificateManager]::Import($resolvedPath, $PrivateKeyPath)
 35    }
 036    return [Kestrun.Certificates.CertificateManager]::Import($resolvedPath, $Password, $PrivateKeyPath)
 37}
 38

Methods/Properties

Import-KrCertificate()