feat(install): Allow downloading from private repositories#4254
feat(install): Allow downloading from private repositories#4254rashil2000 merged 17 commits intoScoopInstaller:developfrom
Conversation
To do this, define a gh_api_token in the sccop config, if the repository is private it will use the apis to get and use the asset id
b23528b to
e7aa703
Compare
|
Waiting for this feature! |
|
Any update if this can be reviewed and included? |
|
Will be reviewed in the next release cycle. |
|
This is great feature - waiting for it to start using scoop as "homebrew for Windows" at my company! |
|
What scopes are required in the GH token used here? Is it a plain token? We already use a GH API token for making authenticated requests, we can use it here too: Scoop/libexec/scoop-config.ps1 Lines 79 to 82 in 7d5a47c |
|
@rashil2000 I think it is |
|
But it is fair to assume that users would already have repo scope if they plan to use private stuff. Renaming to |
|
@tmsmith can you update this PR with latest |
|
It looks like URL syntax |
|
I have a fix for that. If nobody objects, I will create a new PR with github private thing only (custom headers can be added later - I don't have setup to test them). |
|
Sure, go ahead! |
|
@tmsmith I have a validated fix for issue described above. How do you want me to share it? Should I make a PR to https://github.com/tmsmith/scoop/tree/private-github-support or just share a code snippet with you? Here it is, changes are in line with regex and line where # Github.com
if ($url -match "github.com\/(?<owner>[^\/]+)\/(?<repo>[^\/]+)\/releases\/download\/(?<tag>[^\/]+)\/(?<file>[^\/#]+)(?<filename>.*)" -and (get_config 'gh_api_token')) {
$headers = @{
"Authorization" = "token $(get_config 'gh_api_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'])"
$isPrivate = (Invoke-RestMethod -Uri $privateUrl -Headers $headers).private
if ($isPrivate) {
$url = ((Invoke-RestMethod -Uri $assetUrl -Headers $headers).assets | Where-Object { $_.name -eq $matches['file'] }).url + $($matches['filename'])
}
} |
|
PR is fine. |
|
@tmsmith please check my comment above and fix the issue with using |
|
I updated the fork with the code snippet you posted above. |
|
@tmsmith Thanks! I re-checked the current PR code and it works fine for me with @rashil2000 I think it is good to go now. There is definitely a need to combine/rework |
|
Actually, let's keep using @tmsmith Please inline the |
|
@tmsmith will you be able to update the PR as requested? I really want this feature to be in place before I start rolling out scoop as internal tool for the company... |
|
I have update the files as requested. I currently do not have a windows machine that functions so I was unable to fully test the changes. |
|
@tmsmith I can do the test. However can you please use |
|
@tmsmith I did some testing for current PR state and while github stuff works fine, the proposed solution of custom headers doesn't work. I spent some time fixing it and here is what I got: This is how hosts-related section of $hosts = get_config "hosts"
if ($hosts) {
$hosts | Where-Object { $url -match $_.match } | ForEach-Object {
(ConvertFrom-StringData -StringData $_.headers).GetEnumerator() | ForEach-Object {
$wreq.headers[$_.Key] = $_.Value
}
}
}And here is example of configuration file hosts section definition: "hosts": [
{
"match": ".*api.github.com/repos.*",
"headers": "Authorization=token SECRET_TOKEN\nCustomHeader=Custom Header Value"
}
]You can see: headers are defined using Hopefully with this change/testing done, we can finally get this merged! Thanks @tmsmith and @rashil2000! |
There was a problem hiding this comment.
Some static review, and please move Features to top of Unrelease in CHANGELOG.
Suggest using 'Allow downloading from private repositories` as CHANGELOG entry.
Since I'm not using private repo, please check if the review comments work.
PS: Also suggest using private_hosts in config file.
|
Thanks @niheaven - I checked you changes with both github and private host repo and they work fine! @tmsmith can you please incorporate proposed changes and rename |
|
I've done some tweaks and renamed config entry to If no bugs, it could be merged, and if there're some that introduced by my commits, please revert them or fixed. |
|
I will re-test this tomorrow. |
|
Just tested - everything works as expected from current branch. Let's merge it! |
|
Thanks @tmsmith @rashil2000 @niheaven |
|
@rashil2000 looks like your last commit broke it when Will need to open the PR to fix it |
Oh, sorry, my bad. I thought Where-Object and ForEach-Object functions would automatically take care of null input.
Are you opening it? |
Yes, shortly. |
Actually, they cannot, and that's why I rarely use them in pipeline. |
|
Is there documentation on this feature? |
|
Run |
Closes #4243.
Github Private repositories return a 404 when trying to use the releases download even with a provided API Token. To solve this I used the releases API which returns an asset URL that will allow for the download request. Also with this PR, a section can be defined in the config file to inject any custom headers needed for other buckets.