|
| 1 | +#!/bin/env pwsh |
| 2 | +param( |
| 3 | + [string] $StorageAccountName = 'azuresdkartifacts', |
| 4 | + [string] $StorageContainerName = 'public-vcpkg-container' |
| 5 | +) |
| 6 | + |
| 7 | +. "$PSScriptRoot/../common/scripts/Helpers/PSModule-Helpers.ps1" |
| 8 | + |
| 9 | +Write-Host "`$env:PSModulePath = $($env:PSModulePath)" |
| 10 | + |
| 11 | +# Work around double backslash |
| 12 | +if ($IsWindows) { |
| 13 | + $hostedAgentModulePath = $env:SystemDrive + "\\Modules" |
| 14 | + $moduleSeperator = ";" |
| 15 | +} |
| 16 | +else { |
| 17 | + $hostedAgentModulePath = "/usr/share" |
| 18 | + $moduleSeperator = ":" |
| 19 | +} |
| 20 | +$modulePaths = $env:PSModulePath -split $moduleSeperator |
| 21 | +$modulePaths = $modulePaths.Where({ !$_.StartsWith($hostedAgentModulePath) }) |
| 22 | +$AzModuleCachePath = (Get-ChildItem "$hostedAgentModulePath/az_*" -Attributes Directory) -join $moduleSeperator |
| 23 | +if ($AzModuleCachePath -and $env.PSModulePath -notcontains $AzModuleCachePath) { |
| 24 | + $modulePaths += $AzModuleCachePath |
| 25 | +} |
| 26 | + |
| 27 | +$env:PSModulePath = $modulePaths -join $moduleSeperator |
| 28 | + |
| 29 | +Install-ModuleIfNotInstalled "Az.Storage" "4.3.0" | Import-Module |
| 30 | + |
| 31 | +$ctx = New-AzStorageContext ` |
| 32 | + -StorageAccountName $StorageAccountName ` |
| 33 | + -UseConnectedAccount |
| 34 | + |
| 35 | +$vcpkgBinarySourceSas = New-AzStorageContainerSASToken ` |
| 36 | + -Name $StorageContainerName ` |
| 37 | + -Permission "rwcl" ` |
| 38 | + -Context $ctx ` |
| 39 | + -ExpiryTime (Get-Date).AddHours(1) |
| 40 | + |
| 41 | +Write-Host "Ensure redaction of SAS tokens in logs" |
| 42 | +Write-Host "##vso[task.setvariable variable=VCPKG_BINARY_SAS_TOKEN;issecret=true;]$vcpkgBinarySourceSas" |
| 43 | + |
| 44 | +Write-Host "Setting vcpkg binary cache to read and write" |
| 45 | +Write-Host "##vso[task.setvariable variable=VCPKG_BINARY_SOURCES_SECRET;issecret=true;]clear;x-azcopy-sas,https://$StorageAccountName.blob.core.windows.net/$StorageContainerName,$vcpkgBinarySourceSas,readwrite" |
| 46 | +Write-Host "##vso[task.setvariable variable=X_VCPKG_ASSET_SOURCES_SECRET;issecret=true;]clear;x-azurl,https://$StorageAccountName.blob.core.windows.net/$StorageContainerName,$vcpkgBinarySourceSas,readwrite" |
0 commit comments