Merge pull request #97211 from jeremyje/fixdl

Fix missing type error in Get-RemoteFile by loading System.Net.Http assembly.
This commit is contained in:
Kubernetes Prow Robot 2020-12-10 16:39:22 -08:00 committed by GitHub
commit 49dea3c6df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -202,6 +202,11 @@ function Get-RemoteFile {
[parameter(Mandatory = $false)] [System.Collections.IDictionary]$Headers = @{}
)
# Load the System.Net.Http assembly if it's not loaded yet.
if ("System.Net.Http.HttpClient" -as [type]) {} else {
Add-Type -AssemblyName System.Net.Http
}
$timeout = New-TimeSpan -Minutes 5
try {
@ -215,19 +220,19 @@ function Get-RemoteFile {
# If the URL is for GCS and the node has dev storage scope, add the
# service account OAuth2 bearer token to the request headers.
# https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#applications
if (($Url -match "^https://storage`.googleapis`.com.*") -And $(Check-StorageScope)) {
if (($Url -match "^https://storage`.googleapis`.com.*") -and $(Check-StorageScope)) {
$httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer $(Get-Credentials)")
}
# Attempt to download the file
$httpResponseMessage = $httpClient.GetAsync([System.Uri]::new($Url))
$httpResponseMessage.Wait()
if (-Not $httpResponseMessage.IsCanceled) {
if (-not $httpResponseMessage.IsCanceled) {
# Check if the request was successful.
#
# DO NOT replace with EnsureSuccessStatusCode(), it prints the
# OAuth2 bearer token.
if (-Not $httpResponseMessage.Result.IsSuccessStatusCode) {
if (-not $httpResponseMessage.Result.IsSuccessStatusCode) {
$statusCode = $httpResponseMessage.Result.StatusCode
throw "Downloading ${Url} returned status code ${statusCode}, retrying."
}