From 4df3f4b0c394accaffcbe61f161984ba377a4da6 Mon Sep 17 00:00:00 2001 From: Alex Stelmachonak Date: Mon, 21 Mar 2022 17:21:01 -0400 Subject: [PATCH 1/2] Properly filtering null input in dl function when private_hosts is not set in config --- lib/install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/install.ps1 b/lib/install.ps1 index aed16beecd..5dba059391 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -402,7 +402,7 @@ function dl($url, $to, $cookies, $progress) { $wreq.Headers.Add('Cookie', (cookie_header $cookies)) } - get_config 'private_hosts' | Where-Object { $url -match $_.match } | ForEach-Object { + get_config 'private_hosts' | Where-Object { $_ -ne $null -and $url -match $_.match } | ForEach-Object { (ConvertFrom-StringData -StringData $_.Headers).GetEnumerator() | ForEach-Object { $wreq.Headers[$_.Key] = $_.Value } From a15c7de58a1b047ea8c3394579ba22526b1e942a Mon Sep 17 00:00:00 2001 From: Alex Stelmachonak Date: Mon, 21 Mar 2022 17:45:38 -0400 Subject: [PATCH 2/2] Rename checkver_token to gh_token and SCOOP_CHECKVER_TOKEN to SCOOP_GH_TOKEN --- CHANGELOG.md | 3 ++- README.md | 6 +++--- bin/checkver.ps1 | 2 +- lib/core.ps1 | 2 +- lib/install.ps1 | 2 +- libexec/scoop-config.ps1 | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9103d0944..517be17b95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ### Features -- **install:** Allow downloading from private repositories ([$4254](https://github.com/ScoopInstaller/Scoop/issues/4243)) +- **install:** Allow downloading from private repositories ([#4254](https://github.com/ScoopInstaller/Scoop/issues/4243)) +- **config:** Rename checkver_token to gh_token and SCOOP_CHECKVER_TOKEN to SCOOP_GH_TOKEN ([#4832](https://github.com/ScoopInstaller/Scoop/pull/4832)) ### Bug Fixes diff --git a/README.md b/README.md index 54f224f24b..5b29b5768a 100644 --- a/README.md +++ b/README.md @@ -103,11 +103,11 @@ $env:SCOOP_CACHE='F:\ScoopCache' # run the installer ``` -### Configure Scoop to use a GitHub API token during searching and checkver by setting `SCOOP_CHECKVER_TOKEN` +### Configure Scoop to use a GitHub API token during searching and checkver by setting `SCOOP_GH_TOKEN` ```powershell -$env:SCOOP_CHECKVER_TOKEN='' -[Environment]::SetEnvironmentVariable('SCOOP_CHECKVER_TOKEN', $env:SCOOP_CHECKVER_TOKEN, 'Machine') +$env:SCOOP_GH_TOKEN='' +[Environment]::SetEnvironmentVariable('SCOOP_GH_TOKEN', $env:SCOOP_GH_TOKEN, 'Machine') # search for an app ``` diff --git a/bin/checkver.ps1 b/bin/checkver.ps1 index 3d6d43dee8..bbee7af8f1 100644 --- a/bin/checkver.ps1 +++ b/bin/checkver.ps1 @@ -76,7 +76,7 @@ param( $Dir = Resolve-Path $Dir $Search = $App -$GitHubToken = $env:SCOOP_CHECKVER_TOKEN, (get_config 'checkver-token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1 +$GitHubToken = $env:SCOOP_GH_TOKEN, (get_config 'gh_token') | Where-Object -Property Length -Value 0 -GT | Select-Object -First 1 # don't use $Version with $App = '*' if ($App -eq '*' -and $Version -ne '') { diff --git a/lib/core.ps1 b/lib/core.ps1 index 094f93e9b7..a63ebd3054 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1032,7 +1032,7 @@ function handle_special_urls($url) } # Github.com - if ($url -match 'github.com/(?[^/]+)/(?[^/]+)/releases/download/(?[^/]+)/(?[^/#]+)(?.*)' -and ($token = get_config 'checkver_token')) { + if ($url -match 'github.com/(?[^/]+)/(?[^/]+)/releases/download/(?[^/]+)/(?[^/#]+)(?.*)' -and ($token = get_config 'gh_token')) { $headers = @{ "Authorization" = "token $token" } $privateUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)" $assetUrl = "https://api.github.com/repos/$($Matches.owner)/$($Matches.repo)/releases/tags/$($Matches.tag)" diff --git a/lib/install.ps1 b/lib/install.ps1 index 5dba059391..67f5249dfb 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -396,7 +396,7 @@ function dl($url, $to, $cookies, $progress) { } if ($url -match 'api\.github\.com/repos') { $wreq.Accept = 'application/octet-stream' - $wreq.Headers['Authorization'] = "token $(get_config 'checkver_token')" + $wreq.Headers['Authorization'] = "token $(get_config 'gh_token')" } if ($cookies) { $wreq.Headers.Add('Cookie', (cookie_header $cookies)) diff --git a/libexec/scoop-config.ps1 b/libexec/scoop-config.ps1 index 47405e5da4..e527653325 100644 --- a/libexec/scoop-config.ps1 +++ b/libexec/scoop-config.ps1 @@ -76,7 +76,7 @@ # cachePath: # For downloads, defaults to 'cache' folder under Scoop root directory. # -# checkver_token: +# gh_token: # GitHub API token used to make authenticated requests. # This is essential for checkver and similar functions to run without # incurring rate limits and download from private repositories.