【发布时间】:2016-11-22 09:04:24
【问题描述】:
我需要使用带有 Chef 配方的 rest API 将 .json 文件发布到服务器,遵循 Chef's documentation 我想出了以下代码:
http_request '/tmp/bpp.json' do
url 'http://localhost:8080/api/v1/blueprints/bpp'
headers ({
'AUTHORIZATION' => "Basic #{Base64.encode64(user)}",
'CONTENT-TYPE' => 'aplication/json'
})
action :post
end
对于授权令牌,user 是一个包含'user:password' 的变量
当我运行这个厨师食谱时,我得到以下响应:
Error executing action `post` on resource 'http_request[POST /tmp/bpp.json]'
Net::HTTPServerException
------------------------
400 "Bad Request"
在此之前,我只是在执行 curl 调用,它工作正常,但我需要更改为 http_request 资源。这是旧的(工作)curl 请求:
curl --user user:password -H 'X-Requested-By:My-cookbook' --data @/tmp/bpp.json localhost:8080/api/v1/blueprints/bpp
我不太习惯使用 REST api,对我来说似乎是一个未知领域。
【问题讨论】:
标签: ruby rest curl chef-infra chef-recipe