bash cURL 调用 REST Api

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33542514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:52:10  来源:igfitidea点击:

cURL to call REST Api

bashcurlbamboo

提问by user3437721

So I want to call a REST API from Bamboo after a deployment has completed. This API needs a username and password but it can't be stored in Bamboo as it seems it can be viewed in the Bash History of the Build agent.

所以我想在部署完成后从 Bamboo 调用 REST API。这个 API 需要用户名和密码,但它不能存储在 Bamboo 中,因为它似乎可以在 Build 代理的 Bash History 中查看。

I intended to use a script task and execute something like

我打算使用脚本任务并执行类似

curl -f -v -k --user "${bamboo.user}":"${bamboo.password}" -X POST https://bamboo.url/builds/rest/api/latest/queue/project_name"/

This would make the REST call. But the username and password is a problem.

这将进行 REST 调用。但是用户名和密码有问题。

I do have the option, however of using a PEM file. It can be provided so does anyone know if this can be used in conjunction with the cURL?

我确实可以选择使用 PEM 文件。它可以提供,所以有人知道这是否可以与 cURL 结合使用吗?

--OR--

- 或者 -

One other thought- could I encrypt a password within a file in my source control, and somehow decrypt it on the build agent, and then have curl use the file instead of reading the password from the command line? How would this look in cURL?

另一个想法 - 我可以在源代码管理中的文件中加密密码,并以某种方式在构建代理上解密它,然后让 curl 使用该文件而不是从命令行读取密码吗?这在 cURL 中看起来如何?

Any ideas how this could be achieved?

任何想法如何实现?

采纳答案by cristi

Your command seems to have an extra quote at the end of your command

您的命令似乎在命令末尾有一个额外的引号

Using a pem file to authenticate with curl:

使用 pem 文件通过 curl 进行身份验证:

curl -E /path/to/user-cert.pem -X POST https://bamboo.url/builds/rest/api/latest/queue/project_name

The file should have both private key and public key inside.

该文件应该同时包含私钥和公钥。