Skip to content

Commit e838b86

Browse files
[cli] Shorten install script download logging (#15405)
* [cli] Shorten install script download logging Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * [cli] Address PR feedback on install script logging Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * [cli] Address latest PR feedback on download logging Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * [cli] Trim dead code from install script logging Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 28cfffe commit e838b86

File tree

2 files changed

+80
-8
lines changed

2 files changed

+80
-8
lines changed

eng/scripts/get-aspire-cli.ps1

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,49 @@ function Invoke-SecureWebRequest {
470470
}
471471
}
472472

473+
# Builds a compact display string for download messages without exposing the full URL.
474+
function Get-DownloadDescriptor {
475+
[CmdletBinding()]
476+
[OutputType([string])]
477+
param(
478+
[Parameter(Mandatory = $true)]
479+
[string]$Uri
480+
)
481+
482+
try {
483+
$downloadUri = [System.Uri]$Uri
484+
$fileName = [System.IO.Path]::GetFileName($downloadUri.AbsolutePath)
485+
$trimmedPath = $downloadUri.AbsolutePath.Trim("/")
486+
$source = $downloadUri.Host
487+
488+
if ($trimmedPath -match "^dotnet/[^/]+/aspire/(?<source>.+)/(?<file>[^/]+)$") {
489+
$source = $Matches["source"]
490+
$fileName = $Matches["file"]
491+
}
492+
elseif ($trimmedPath -match "^public(?:-checksums)?/aspire/+(?<version>[^/]+)/(?<file>[^/]+)$") {
493+
$source = "version/$($Matches["version"])"
494+
$fileName = $Matches["file"]
495+
}
496+
elseif ($trimmedPath -match "^(?<source>.+)/(?<file>[^/]+)$") {
497+
$source = $Matches["source"]
498+
$fileName = $Matches["file"]
499+
}
500+
501+
if ([string]::IsNullOrWhiteSpace($fileName)) {
502+
return $Uri
503+
}
504+
505+
if ([string]::IsNullOrWhiteSpace($source)) {
506+
return $fileName
507+
}
508+
509+
return "$fileName from '$source'"
510+
}
511+
catch {
512+
return $Uri
513+
}
514+
}
515+
473516
# Enhanced file download wrapper with validation
474517
function Invoke-FileDownload {
475518
[CmdletBinding()]
@@ -919,11 +962,12 @@ function Get-AspireExtension {
919962
Write-Message "Downloading Aspire VS Code extension" -Level Info
920963

921964
$extensionUrl = Get-AspireExtensionUrl -Version $Version -Quality $Quality
965+
$extensionDescriptor = Get-DownloadDescriptor -Uri $extensionUrl
922966
$extensionArchive = Join-Path $TempDir $Script:ExtensionArtifactName
923967

924968
try {
925-
if ($PSCmdlet.ShouldProcess($extensionArchive, "Download extension from $extensionUrl")) {
926-
Write-Message "Downloading from: $extensionUrl" -Level Info
969+
if ($PSCmdlet.ShouldProcess($extensionArchive, "Download extension ($extensionDescriptor)")) {
970+
Write-Message "Downloading $extensionDescriptor" -Level Info
927971
Invoke-FileDownload -Uri $extensionUrl -OutputPath $extensionArchive -TimeoutSec $Script:ArchiveDownloadTimeoutSec
928972
Write-Message "Successfully downloaded extension archive" -Level Verbose
929973
}
@@ -1144,17 +1188,19 @@ function Install-AspireCli {
11441188
$runtimeIdentifier = "$targetOS-$targetArch"
11451189
$extension = if ($targetOS -eq "win") { "zip" } else { "tar.gz" }
11461190
$urls = Get-AspireCliUrl -Version $Version -Quality $Quality -RuntimeIdentifier $runtimeIdentifier -Extension $extension
1191+
$archiveDescriptor = Get-DownloadDescriptor -Uri $urls.ArchiveUrl
1192+
$checksumDescriptor = Get-DownloadDescriptor -Uri $urls.ChecksumUrl
11471193

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

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

1157-
if ($PSCmdlet.ShouldProcess($urls.ChecksumUrl, "Download CLI archive checksum")) {
1203+
if ($PSCmdlet.ShouldProcess($checksumPath, "Download CLI archive checksum ($checksumDescriptor)")) {
11581204
# Download and test the checksum
11591205
Invoke-FileDownload -Uri $urls.ChecksumUrl -TimeoutSec $Script:ChecksumDownloadTimeoutSec -OutputPath $checksumPath
11601206
Test-FileChecksum -ArchiveFile $archivePath -ChecksumFile $checksumPath

eng/scripts/get-aspire-cli.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,30 @@ secure_curl() {
294294
curl "${curl_args[@]}" "$url"
295295
}
296296

297+
# Build a compact display string for download messages without exposing the full URL.
298+
get_download_descriptor() {
299+
local url="$1"
300+
local file_name source
301+
302+
if [[ "$url" =~ ^https://aka\.ms/dotnet/[^/]+/aspire/(.+)/([^/]+)$ ]]; then
303+
source="${BASH_REMATCH[1]}"
304+
file_name="${BASH_REMATCH[2]}"
305+
elif [[ "$url" =~ ^https://ci\.dot\.net/public(-checksums)?/aspire/+([^/]+)/([^/]+)$ ]]; then
306+
source="version/${BASH_REMATCH[2]}"
307+
file_name="${BASH_REMATCH[3]}"
308+
else
309+
file_name="${url##*/}"
310+
source="${url#https://}"
311+
source="${source%%/*}"
312+
fi
313+
314+
if [[ -n "$file_name" && -n "$source" ]]; then
315+
printf "%s from '%s'" "$file_name" "$source"
316+
else
317+
printf "%s" "$file_name"
318+
fi
319+
}
320+
297321
# Validate content type via HEAD request
298322
validate_content_type() {
299323
local url="$1"
@@ -324,9 +348,12 @@ download_file() {
324348
local max_retries="${4:-5}"
325349
local validate_content_type="${5:-true}"
326350
local use_temp_file="${6:-true}"
351+
local download_descriptor
352+
353+
download_descriptor=$(get_download_descriptor "$url")
327354

328355
if [[ "$DRY_RUN" == true ]]; then
329-
say_info "[DRY RUN] Would download $url"
356+
say_info "[DRY RUN] Would download $download_descriptor"
330357
return 0
331358
fi
332359

@@ -343,7 +370,7 @@ download_file() {
343370
fi
344371

345372
say_verbose "Downloading $url to $target_file"
346-
say_info "Downloading from: $url"
373+
say_info "Downloading $download_descriptor"
347374

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

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

846-
say_info "Downloading from: $url"
847873
if ! download_file "$url" "$extension_archive" $ARCHIVE_DOWNLOAD_TIMEOUT_SEC; then
848874
return 1
849875
fi

0 commit comments

Comments
 (0)