我正在尝试使用ansible自动下载发行资产,但收到400“无效参数错误”:
<?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>Basic XXX</ArgumentValue>
<RequestId>XXXX</RequestId>
<HostId>XXXX</HostId>
</Error>
我在GitHub上找到了corresponding issue,但是如果不编写自定义脚本,就无法使用ansible实现解决方案。我目前的代码是:
- name: Download build asset
uri:
url: "{{ asset_url }}"
user: "{{ github_username }}"
password: "{{ github_token }}"
force_basic_auth: yes
headers:
Accept: application/octet-stream
我也尝试过不传递标题,并在网址中使用令牌
- name: Download build asset
uri:
url: "https://{{ TOKEN }}:@api.github.com/repos/<ORG>/<REPO>/releases/assets/{{ ASSET_ID }}"
headers:
Accept: application/octet-stream
但是随后我收到错误404“未找到”错误(大概是因为身份验证不起作用(将私有URL参数替换为):
fatal: [XXX]: FAILED! => changed=false
access_control_allow_origin: '*'
access_control_expose_headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
connection: close
content: '{"message":"Not Found","documentation_url":"https://docs.github.com/rest/reference/repos#get-a-release-asset"}'
content_length: '110'
content_security_policy: default-src 'none'
content_type: application/json; charset=utf-8
date: Wed, 18 Nov 2020 15:45:42 GMT
elapsed: 0
json:
documentation_url: https://docs.github.com/rest/reference/repos#get-a-release-asset
message: Not Found
msg: 'Status code was 404 and not [200]: HTTP Error 404: Not Found'
redirected: false
referrer_policy: origin-when-cross-origin, strict-origin-when-cross-origin
server: GitHub.com
status: 404
strict_transport_security: max-age=31536000; includeSubdomains; preload
url: https://<TOKEN>@api.github.com/repos/<ORG>/<REPO>/releases/assets/28089234
vary: Accept-Encoding, Accept, X-Requested-With
x_content_type_options: nosniff
x_frame_options: deny
x_github_media_type: unknown
x_github_request_id: CC26:2942:15E1154:1948AE9:5FB541A6
x_ratelimit_limit: '60'
x_ratelimit_remaining: '58'
x_ratelimit_reset: '1605717756'
x_ratelimit_used: '2'
x_xss_protection: 1; mode=block
这仅适用于发布资产,使用基本的auth方法,其他api调用也可以正常工作。它也可以使用curl或postman处理相同的请求。我使用的个人访问令牌的范围是:
就目前而言,使用curl可以发送请求,但是我更喜欢使用uri模块:
name: Download build asset
shell: >
curl -J -L -H "Accept: application/octet-stream"
"https://{{ TOKEN }}@api.github.com/repos/<ORG>/<REPO>/releases/assets/{{ ASSET_ID }}"
--output "/tmp/asset.tar.gz"