Private/Resolve-SshImportIdUrl.ps1

function Resolve-SshImportIdUrl {
    <#
    .SYNOPSIS
        Resolves a '<prefix>:<username>' identifier to a keys-fetch URL.
    #>

    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param(
        [Parameter(Mandatory)]
        [string] $UserId
    )

    if ($UserId -notmatch '^(?<prefix>[a-zA-Z0-9_-]+):(?<user>.+)$') {
        throw "Invalid user id '$UserId'. Expected format '<prefix>:<username>', e.g. 'gh:octocat'."
    }

    $prefix = $Matches.prefix.ToLowerInvariant()
    $userName = $Matches.user

    $builtIn = @{
        gh = 'https://github.com/{0}.keys'
        gl = 'https://gitlab.com/{0}.keys'
        lp = 'https://launchpad.net/~{0}/+sshkeys'
    }

    $custom = Get-SshImportIdCustomSourceMap

    $template = $null
    if ($custom.ContainsKey($prefix)) {
        $template = $custom[$prefix]
    } elseif ($builtIn.ContainsKey($prefix)) {
        $template = $builtIn[$prefix]
    }

    if (-not $template) {
        $known = @($builtIn.Keys) + @($custom.Keys) | Sort-Object -Unique
        throw "Unknown source prefix '$prefix'. Known prefixes: $($known -join ', '). Use Register-SshImportIdSource to add a custom prefix."
    }

    [pscustomobject]@{
        Prefix   = $prefix
        UserName = $userName
        Url      = ($template -f $userName)
    }
}