TalosTools.psm1


Function Update-TalosAssets()
{
    param(
        [Parameter(Position=0,
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   HelpMessage="Target folder for assets")]
        [Alias("Path")]
        [string]
        $Target = ".",
        [Parameter()]
        [string]
        $Version = "Latest"
    )

    $getReleaseArgs = @{
        RepositoryName = "talos"
        OwnerName = "siderolabs"
    }
    if ($Version -eq "Latest") {
        $getReleaseArgs["Latest"] = $true
    } else {
        $getReleaseArgs["Tag"] = $Version
    }

    $release = Get-GitHubRelease @getReleaseArgs

    'talos-amd64.iso','talos-arm64.iso','talosctl-windows-amd64.exe' | Foreach-Object -ThrottleLimit 2 -Parallel {
        $file = $PSItem
        $assetUrl = $USING:release.assets | Where-Object {$_.name -eq $file} | Select-Object -exp browser_download_url
        Invoke-WebRequest -outfile (Join-Path $USING:Target $file) $assetUrl
    }
}