mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
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:
commit
49dea3c6df
@ -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."
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user