Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions eng/scripts/get-aspire-cli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,49 @@ function Invoke-SecureWebRequest {
}
}

# Builds a compact display string for download messages without exposing the full URL.
function Get-DownloadDescriptor {
[CmdletBinding()]
[OutputType([string])]
param(
[Parameter(Mandatory = $true)]
[string]$Uri
)

try {
$downloadUri = [System.Uri]$Uri
$fileName = [System.IO.Path]::GetFileName($downloadUri.AbsolutePath)
$trimmedPath = $downloadUri.AbsolutePath.Trim("/")
$source = $downloadUri.Host

if ($trimmedPath -match "^dotnet/[^/]+/aspire/(?<source>.+)/(?<file>[^/]+)$") {
$source = $Matches["source"]
$fileName = $Matches["file"]
}
elseif ($trimmedPath -match "^public(?:-checksums)?/aspire/+(?<version>[^/]+)/(?<file>[^/]+)$") {
$source = "version/$($Matches["version"])"
$fileName = $Matches["file"]
}
elseif ($trimmedPath -match "^(?<source>.+)/(?<file>[^/]+)$") {
$source = $Matches["source"]
$fileName = $Matches["file"]
}

if ([string]::IsNullOrWhiteSpace($fileName)) {
return $Uri
}

if ([string]::IsNullOrWhiteSpace($source)) {
return $fileName
}

return "$fileName from '$source'"
}
catch {
return $Uri
}
}

# Enhanced file download wrapper with validation
function Invoke-FileDownload {
[CmdletBinding()]
Expand Down Expand Up @@ -919,11 +962,12 @@ function Get-AspireExtension {
Write-Message "Downloading Aspire VS Code extension" -Level Info

$extensionUrl = Get-AspireExtensionUrl -Version $Version -Quality $Quality
$extensionDescriptor = Get-DownloadDescriptor -Uri $extensionUrl
$extensionArchive = Join-Path $TempDir $Script:ExtensionArtifactName

try {
if ($PSCmdlet.ShouldProcess($extensionArchive, "Download extension from $extensionUrl")) {
Write-Message "Downloading from: $extensionUrl" -Level Info
if ($PSCmdlet.ShouldProcess($extensionArchive, "Download extension ($extensionDescriptor)")) {
Write-Message "Downloading $extensionDescriptor" -Level Info
Invoke-FileDownload -Uri $extensionUrl -OutputPath $extensionArchive -TimeoutSec $Script:ArchiveDownloadTimeoutSec
Write-Message "Successfully downloaded extension archive" -Level Verbose
}
Expand Down Expand Up @@ -1144,17 +1188,19 @@ function Install-AspireCli {
$runtimeIdentifier = "$targetOS-$targetArch"
$extension = if ($targetOS -eq "win") { "zip" } else { "tar.gz" }
$urls = Get-AspireCliUrl -Version $Version -Quality $Quality -RuntimeIdentifier $runtimeIdentifier -Extension $extension
$archiveDescriptor = Get-DownloadDescriptor -Uri $urls.ArchiveUrl
$checksumDescriptor = Get-DownloadDescriptor -Uri $urls.ChecksumUrl

$archivePath = Join-Path $tempDir $urls.ArchiveFilename
$checksumPath = Join-Path $tempDir $urls.ChecksumFilename

if ($PSCmdlet.ShouldProcess($urls.ArchiveUrl, "Download CLI archive")) {
if ($PSCmdlet.ShouldProcess($archivePath, "Download CLI archive ($archiveDescriptor)")) {
# Download the Aspire CLI archive
Write-Message "Downloading from: $($urls.ArchiveUrl)" -Level Info
Write-Message "Downloading $archiveDescriptor" -Level Info
Invoke-FileDownload -Uri $urls.ArchiveUrl -TimeoutSec $Script:ArchiveDownloadTimeoutSec -OutputPath $archivePath
}

if ($PSCmdlet.ShouldProcess($urls.ChecksumUrl, "Download CLI archive checksum")) {
if ($PSCmdlet.ShouldProcess($checksumPath, "Download CLI archive checksum ($checksumDescriptor)")) {
# Download and test the checksum
Invoke-FileDownload -Uri $urls.ChecksumUrl -TimeoutSec $Script:ChecksumDownloadTimeoutSec -OutputPath $checksumPath
Test-FileChecksum -ArchiveFile $archivePath -ChecksumFile $checksumPath
Expand Down
32 changes: 29 additions & 3 deletions eng/scripts/get-aspire-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,30 @@ secure_curl() {
curl "${curl_args[@]}" "$url"
}

# Build a compact display string for download messages without exposing the full URL.
get_download_descriptor() {
local url="$1"
local file_name source

if [[ "$url" =~ ^https://aka\.ms/dotnet/[^/]+/aspire/(.+)/([^/]+)$ ]]; then
source="${BASH_REMATCH[1]}"
file_name="${BASH_REMATCH[2]}"
elif [[ "$url" =~ ^https://ci\.dot\.net/public(-checksums)?/aspire/+([^/]+)/([^/]+)$ ]]; then
source="version/${BASH_REMATCH[2]}"
file_name="${BASH_REMATCH[3]}"
else
file_name="${url##*/}"
source="${url#https://}"
source="${source%%/*}"
fi

if [[ -n "$file_name" && -n "$source" ]]; then
printf "%s from '%s'" "$file_name" "$source"
else
printf "%s" "$file_name"
fi
}

# Validate content type via HEAD request
validate_content_type() {
local url="$1"
Expand Down Expand Up @@ -324,9 +348,12 @@ download_file() {
local max_retries="${4:-5}"
local validate_content_type="${5:-true}"
local use_temp_file="${6:-true}"
local download_descriptor

download_descriptor=$(get_download_descriptor "$url")

if [[ "$DRY_RUN" == true ]]; then
say_info "[DRY RUN] Would download $url"
say_info "[DRY RUN] Would download $download_descriptor"
return 0
fi

Expand All @@ -343,7 +370,7 @@ download_file() {
fi

say_verbose "Downloading $url to $target_file"
say_info "Downloading from: $url"
say_info "Downloading $download_descriptor"

# Download the file
if secure_curl "$url" "$target_file" "$timeout" "$USER_AGENT" "$max_retries"; then
Expand Down Expand Up @@ -843,7 +870,6 @@ download_aspire_extension() {

extension_archive="${temp_dir}/${EXTENSION_ARTIFACT_NAME}"

say_info "Downloading from: $url"
if ! download_file "$url" "$extension_archive" $ARCHIVE_DOWNLOAD_TIMEOUT_SEC; then
return 1
fi
Expand Down
Loading