11# ###############################################################################
22# # File: Install-AliyunCli.ps1
33# # Desc: Install Alibaba Cloud CLI
4+ # # Supply chain security: Alibaba Cloud CLI - checksum validation
45# ###############################################################################
56
67Write-Host " Download Latest aliyun-cli archive"
7- $ZipballUrl = ' https://aliyuncli.alicdn.com/aliyun-cli-windows-latest-amd64.zip'
8- $aliyunArchivePath = Start-DownloadWithRetry - Url $ZipballUrl - Name " aliyun-cli.zip"
8+ $repoUrl = " https://api.github.com/repos/aliyun/aliyun-cli/releases/latest"
9+ $installerFileName = " aliyun-cli-windows"
10+ $assets = (Invoke-RestMethod - Uri $repoUrl ).assets
11+ $downloadUrl = ($assets.browser_download_url -ilike " *aliyun-cli-windows-*-amd64.zip*" ) | Select-Object - First 1
12+ $packagePath = Start-DownloadWithRetry - Url $downloadUrl - Name " $installerFileName .zip"
13+
14+ # region Supply chain security - Alibaba Cloud CLI
15+ $fileHash = (Get-FileHash - Path $packagePath - Algorithm SHA256).Hash
16+ $hashUrl = ($assets.browser_download_url -ilike " *SHASUMS256.txt*" ) | Select-Object - First 1
17+ $externalHash = (Invoke-RestMethod - Uri $hashURL ).ToString().Split(" `n " ).Where ({ $_ -ilike " *$installerFileName *" }).Split(' ' )[0 ]
18+ Use-ChecksumComparison $fileHash $externalHash
19+ # endregion
920
1021Write-Host " Expand aliyun-cli archive"
1122$aliyunPath = " C:\aliyun-cli"
1223New-Item - Path $aliyunPath - ItemType Directory - Force
13- Extract- 7Zip - Path $aliyunArchivePath - DestinationPath $aliyunPath
24+ Extract- 7Zip - Path $packagePath - DestinationPath $aliyunPath
1425
1526# Add aliyun-cli to path
1627Add-MachinePathItem $aliyunPath
1728
18- Invoke-PesterTests - TestFile " CLI.Tools" - TestName " Aliyun CLI"
29+ Invoke-PesterTests - TestFile " CLI.Tools" - TestName " Aliyun CLI"
0 commit comments