问题描述
是否有可能通过命令行而不是通过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.
我设法转储了流量,并且看到在响应的呈现的HTML模板中提供了令牌到 POST
请求:
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" />
但是,似乎太脏了,无法发布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解析的解决方法:
Workaround based on HTML parsing: https://gist.github.com/vitalyisaev2/215f890e75252cd36794221c2debf365
这篇关于如何从命令行获取GitLab个人访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!