Skip to content

Add proxy support in kvm #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion kvm.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
param(
[parameter(Position=0)]
[string] $command,
[string] $proxy,
[switch] $verbosity = $false,
[alias("g")][switch] $global = $false,
[alias("p")][switch] $persistent = $false,
Expand All @@ -26,12 +27,13 @@ K Runtime Environment Version Manager - Build 509

USAGE: kvm <command> [options]

kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global]
kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] [-proxy <ADDRESS>]
install latest KRE from feed
set 'default' alias to installed version
add KRE bin to user PATH environment variable
-g|-global install to machine-wide location
-f|-force upgrade even if latest is already installed
-proxy <ADDRESS> use given address as proxy when accessing remote server

kvm install <semver>|<alias>|<nupkg> [-x86][-x64] [-svr50][-svrc50] [-g|-global]
install requested KRE from feed
Expand Down Expand Up @@ -124,6 +126,25 @@ function Kvm-Upgrade {
Kvm-Alias-Set "default" $version
}

function Add-Proxy-If-Specified {
param(
[System.Net.WebClient] $wc
)
if (!$proxy) {
$proxy = $env:http_proxy
}
if ($proxy) {
$wp = New-Object System.Net.WebProxy($proxy)
$pb = New-Object UriBuilder($proxy)
if (!$pb.UserName) {
$wp.Credentials = [System.Net.CredentialCache]::DefaultCredentials
} else {
$wp.Credentials = New-Object System.Net.NetworkCredential($pb.UserName, $pb.Password)
}
$wc.Proxy = $wp
}
}

function Kvm-Find-Latest {
param(
[string] $platform,
Expand All @@ -135,6 +156,7 @@ param(

$wc = New-Object System.Net.WebClient
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
Add-Proxy-If-Specified($wc)
[xml]$xml = $wc.DownloadString($url)

$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
Expand Down Expand Up @@ -181,6 +203,7 @@ param(

$wc = New-Object System.Net.WebClient
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
Add-Proxy-If-Specified($wc)
$wc.DownloadFile($url, $tempKreFile)

Do-Kvm-Unpack $tempKreFile $kreTempDownload
Expand Down