【问题标题】:How to download single raw file from private gitlab repo using username and password如何使用用户名和密码从私人 gitlab 存储库下载单个原始文件
【发布时间】:2021-11-09 04:16:09
【问题描述】:

我可以使用下面的命令克隆一个带有用户名和密码的私人仓库

git clone https://some-git-lab-token:someHash@git.xxx.com/foo/bar.git

我想知道是否可以使用相同的凭据 some-git-lab-token:someHashcurlwget 来自同一仓库的单个原始文件@

如下示例 gitlab 原始文件 url

https://gitlab.com/athos.oc/lodash-has-plugin/-/raw/master/.eslintrc.json

我尝试如下卷曲单个文件,但失败了

curl https://some-git-lab-token:someHash@git.xxx.com/foo/bar/-/raw/master/testing.js

我得到的结果如下

<html><body>You are being <a href="https://git.xxx.com/users/sign_in">redirected</a>.</body></html>

【问题讨论】:

  • 这可以在个人访问令牌的帮助下实现。你能利用它吗?

标签: curl gitlab wget


【解决方案1】:

要通过 curl 下载存储库文件,需要使用repository files API endpoint

使用您的示例https://gitlab.com/athos.oc/lodash-has-plugin/-/raw/master/.eslintrc.json,将变成:

https://gitlab.com/api/v4/projects/30349314/repository/files/%2Eeslintrc%2Ejson/raw?ref=master

但是,API authentication 不包括用户名和密码作为可用的身份验证方法,因此您需要使用令牌(或会话 cookie)。

【讨论】:

  • 感谢您的回答!为了将来参考,您仍然需要/raw 来获取内容,因为没有它您只能获取文件的元数据。所以链接应该是https://gitlab.com/api/v4/projects/30349314/repository/files/%2Eeslintrc%2Ejson/raw?ref=master
  • 哦,是的,对不起!我从文档中复制了错误的示例。我已经更新了链接和示例
猜你喜欢
  • 2013-08-10
  • 2022-11-11
  • 1970-01-01
  • 2014-08-19
  • 2016-10-29
  • 2015-05-06
  • 2022-01-12
  • 2020-04-17
  • 2018-12-16
相关资源
最近更新 更多