From 797ad961b810afba714fe9b98998c0a5c5560868 Mon Sep 17 00:00:00 2001 From: Jeremy Edwards <1312331+jeremyje@users.noreply.github.com> Date: Thu, 10 Dec 2020 21:18:15 +0000 Subject: [PATCH] Fix missing type error in Get-RemoteFile by loading System.Net.Http assembly. --- cluster/gce/windows/common.psm1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cluster/gce/windows/common.psm1 b/cluster/gce/windows/common.psm1 index d057f24e54e..4a292077e86 100644 --- a/cluster/gce/windows/common.psm1 +++ b/cluster/gce/windows/common.psm1 @@ -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." }