如何从命令行获取 GitLab 个人访问令牌 [英] How to obtain GitLab Personal Access Token from command line
问题描述
是否有可能通过命令行而不是 Web 界面获取 Gitlab
API 的个人访问令牌?我正在做一些集成测试,将 Gitlab
部署到干净的环境中是测试会话设置的一部分.部署后测试用户正在使用 Gitlab
API 做一些工作.为了访问API,测试用户需要提供个人访问令牌.
Is there any possibility to get Personal Access Token for Gitlab
API via command line rather than web interface? I'm working on some integration tests, and Gitlab
deployment into the clean environment is a part of test session setup. After deployment test user is doing some work with Gitlab
API. In order to access API, test user need to provide Personal Access Token.
我设法转储了流量,我看到在响应 POST
请求时,在呈现的 HTML 模板中提供了令牌:
I managed to dump traffic, and I see that token is provided within a rendered HTML template in response to POST
request:
00:06:40.616996 IP6 localhost.amanda > localhost.53808: Flags [P.], seq 1:580, ack 1054, win 497, options [nop,nop,TS val 3133641719 ecr 3133641673], length 579
`..U.c.@................................'`.0...y.eIz.....k.....
........HTTP/1.1 302 Found
Server: nginx
Date: Tue, 21 Nov 2017 21:06:40 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 119
Connection: keep-alive
Cache-Control: no-cache
Location: http://localhost:10080/profile/personal_access_tokens
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Request-Id: 88178813-95ad-419a-b56b-5a5ddb183885
X-Runtime: 0.044209
X-Ua-Compatible: IE=edge
X-Xss-Protection: 1; mode=block
X-Accel-Buffering: no
内心深处的回应:
<input type="text" name="created-personal-access-token" id="created-personal-access-token" value="j1WZujuaKVVEkh8h8Fej" readonly="readonly" class="form-control js-select-on-focus" aria-describedby="created-personal-access-token-help-block" />
但是,POST HTML 表单然后解析生成的 HTML 以获取令牌似乎太脏了.任何人都可以分享如何正确做的秘诀吗?
However, it seems too be dirty to POST HTML Form and then parse resulting HTML in order to get the token. Can anyone share the secret how to do it right?
推荐答案
基于 HTML 解析的解决方法:https:///github.com/vitalyisaev2/gitlab_token
Workaround based on HTML parsing: https://github.com/vitalyisaev2/gitlab_token
这篇关于如何从命令行获取 GitLab 个人访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!