kei*_*eiw 31 command-line github
GitHub指南解释了2种授权方式,但看起来没有使用Release文件.
后果:
curl -u 'username' -L -o a.tgz https://github.com/company/repository/releases/download/TAG-NAME/A.tgz
总有类似的东西
<!DOCTYPE html>
<!--
Hello future GitHubber! ...
ken*_*orb 37
下载从私人回购释放的文件,可以使用可以在生成个人访问令牌设置/令牌与私人仓库完全控制范围.
然后使用curl
命令下载资产(使用适当的值更改):
curl -vLJO -H 'Accept: application/octet-stream' 'https://api.github.com/repos/:owner/:repo/releases/assets/:id?access_token=:token'
Run Code Online (Sandbox Code Playgroud)
哪里:
:owner
是您的用户或组织用户名;:repo
是你的存储库名称;:id
是您的资产ID,可以在标记发布网址中找到,例如:
https://api.github.com/repos/:owner/:repo/releases/tags/:tag
Run Code Online (Sandbox Code Playgroud):token
是您的个人访问令牌(可以创建/settings/tokens
;
这是Bash脚本,可以下载给定文件名的资产文件:
#!/usr/bin/env bash
# Script to download asset file from tag release using GitHub API v3.
# See: http://stackoverflow.com/a/35688093/55075
CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
# Check dependencies.
set -e
type curl grep sed tr >&2
xargs=$(which gxargs || which xargs)
# Validate settings.
[ -f ~/.secrets ] && source ~/.secrets
[ "$GITHUB_API_TOKEN" ] || { echo "Error: Please define GITHUB_API_TOKEN variable." >&2; exit 1; }
[ $# -ne 4 ] && { echo "Usage: $0 [owner] [repo] [tag] [name]"; exit 1; }
[ "$TRACE" ] && set -x
read owner repo tag name <<<$@
# Define variables.
GH_API="https://api.github.com"
GH_REPO="$GH_API/repos/$owner/$repo"
GH_TAGS="$GH_REPO/releases/tags/$tag"
AUTH="Authorization: token $GITHUB_API_TOKEN"
WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie"
CURL_ARGS="-LJO#"
# Validate token.
curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; }
# Read asset tags.
response=$(curl -sH "$AUTH" $GH_TAGS)
# Get ID of the asset based on given name.
eval $(echo "$response" | grep -C3 "name.:.\+$name" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
#id=$(echo "$response" | jq --arg name "$name" '.assets[] | select(.name == $name).id') # If jq is installed, this can be used instead.
[ "$id" ] || { echo "Error: Failed to get asset id, response: $response" | awk 'length($0)<100' >&2; exit 1; }
GH_ASSET="$GH_REPO/releases/assets/$id"
# Download asset file.
echo "Downloading asset..." >&2
curl $CURL_ARGS -H 'Accept: application/octet-stream' "$GH_ASSET?access_token=$GITHUB_API_TOKEN"
echo "$0 done." >&2
Run Code Online (Sandbox Code Playgroud)
在运行之前,您需要GITHUB_API_TOKEN
使用GitHub令牌进行设置(参见:/settings/tokens
GH).这可以放在您的~/.secrets
文件中,如:
GITHUB_API_TOKEN=XXX
Run Code Online (Sandbox Code Playgroud)
示例脚本用法:
./get_gh_asset.sh :owner :repo :tag :name
Run Code Online (Sandbox Code Playgroud)
其中name是您的文件名(或部分名称).使用前缀脚本TRACE=1
进行调试.
如果你想知道为什么curl
有时失败(如其他答案所述):
只允许一种身份验证机制; 只应指定
X-Amz-Algorithm
查询参数,签名查询字符串参数或Authorization
标题.
当跑步时:
curl -vLJ -H 'Authorization: token <token>' -H 'Accept: application/octet-stream' https://api.github.com/repos/:owner/:repo/releases/assets/<id>
Run Code Online (Sandbox Code Playgroud)
这是因为您同时指定了多个机制,因此S3服务器不知道使用哪个机制,因此您只需选择一个,例如:
X-Amz-Algorithm
查询参数X-Amz-Signature
)Authorization: token <token>
)并且由于GitHub会从资产页面重定向您(在请求时application/octet-stream
),它会在查询字符串中自动填充凭据,因为curl
它会在请求标头(您已指定)中传递相同的凭据,因此它们是冲突的.因此,对于变通方法,您可以使用access_token
.
Dwa*_*yne 10
使用gh release download轻松编写脚本下载。首先gh auth登录进行授权。
因此,要下载示例 URL,https://github.com/company/repository/releases/download/TAG-NAME/A.tgz
请使用:
gh release download --repo company/repository TAG-NAME -p 'A.tgz'
似乎两种身份验证方法仅适用于API端点.有一个用于下载发布资产的API端点(文档):
GET /repos/:owner/:repo/releases/assets/:id
Run Code Online (Sandbox Code Playgroud)
但是人们需要知道资产的数字ID.我询问他们是否可以添加API端点以按名称下载发布资产(就像它们用于tarball一样).
更新:Github支持的回复:
我们不提供您建议的任何API.我们尝试避免在发布资产的标记或文件名发生更改时会发生变化的脆弱URL.我会将您的反馈意见带给团队进一步讨论.
我们必须经常从私有GitHub repos下载发布资产,因此我们创建了fetch,这是一个开源的跨平台工具,可以轻松下载源文件并从git标记,提交或公共分支中释放资产和私人GitHub回购.
例如,foo.exe
要从0.1.3
私有GitHub存储库的版本下载发布资产/tmp
,您将执行以下操作:
GITHUB_OAUTH_TOKEN="your token"
fetch --repo="https://github.com/foo/bar" --tag="0.1.3" --release-asset="foo.exe" /tmp
Run Code Online (Sandbox Code Playgroud)
这是curl
&jq
一个;)班轮:
CURL="curl -H 'Authorization: token <auth_token>' \
https://api.github.com/repos/<owner>/<repo>/releases"; \
ASSET_ID=$(eval "$CURL/tags/<tag>" | jq .assets[0].id); \
eval "$CURL/assets/$ASSET_ID -LJOH 'Accept: application/octet-stream'"
Run Code Online (Sandbox Code Playgroud)
更改<>
用您的数据包围的部分。要生成auth_token
去github.com/settings/tokens
如果你想用密码登录,请使用这个(注意它会要求输入两次密码):
CURL="curl -u <github_user> https://api.github.com/repos/<owner>/<repo>/releases"; \
ASSET_ID=$(eval "$CURL/tags/<tag>" | jq .assets[0].id); \
eval "$CURL/assets/$ASSET_ID -LJOH 'Accept: application/octet-stream'"
Run Code Online (Sandbox Code Playgroud)
我在这篇评论中找到了答案:https://github.com/request/request/pull/1058#issuecomment-55285276
curl
将请求中的身份验证标头转发到存储Github发布资产的AmazonS3存储桶.来自S3的错误响应:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidArgument</Code>
<Message>
Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified
</Message>
<ArgumentName>Authorization</ArgumentName>
<ArgumentValue>token <yourtoken> </ArgumentValue><RequestId>4BEDDBA630688865</RequestId> <HostId>SXLsRKgKM6tPa/K7g7tSOWmQEqowG/4kf6cwOmnpObXrSzUt4bzOFuihmzxK6+gx</HostId>
</Error>
Run Code Online (Sandbox Code Playgroud)
一线wget解决方案:
wget --auth-no-challenge --header='Accept:application/octet-stream' https://<token>:@api.github.com/repos/:owner/:repo/releases/assets/:id -O app.zip
Run Code Online (Sandbox Code Playgroud)
尝试:curl -i -H "Authorization: token <token>" -H "Accept:application/octet-stream" https://<token>:@api.github.com/repos/:owner/:repo/releases/assets/:id
,了解更多细节.单击添加-L
以查看S3错误消息.
归档时间: |
|
查看次数: |
24902 次 |
最近记录: |