node.js - 为 ansible 塔生成 oath2 令牌的 Nodejs 脚本
问题描述
如何编写节点 js 脚本为 ansible 塔生成 oauth2 令牌。通过 cli :
curl -u username:password -k -X POST https://<tower-host>/api/v2/tokens/
解决方案
使用 axios ( npm i axios
) 脚本是:
var axios = require('axios');
var https = require('https');
const instance = axios.create({
httpsAgent: new https.Agent({ rejectUnauthorized: false })
});
(async () => {
var response = await instance({
method: 'post',
url: 'https://api/v2/token',
auth: { username: 'foo', password: 'bar' }
});
console.log('response is', response.data);
})();
推荐阅读
- javascript - 如何从不存在下载按钮的 pdfviewer 下载/保存为 pdf 演示文稿?
- azure-devops - azure devops 中的存储库级别通知设置
- meteor - 在 Meteor 服务器上使用 NodeJS EventEmitter
- python - 如何使用 attrs 从字符串反序列化为不可变对象?
- python-3.x - Tkinter Toplevel 窗口未出现
- vb.net - 如果在数据网格视图中满足某些条件,如何使按钮不可见和可见。?
- python - 当数据输入到另一个输入字段时,让输入字段实时更新
- vue.js - 基于复选框计数呈现按钮
- python - 使用 Python3 和 Matplotlib 创建动画
- node.js - 两次刷新同一页面时出错