我在Google Cloud上的Node.JS中有一个cloud函数,我需要向Google发出GET请求,它需要一个auth token。使用curl
可以使用$(gcloud auth application-default print-access-token)
生成一个。但是这在Cloud示例中不起作用,那么我如何生成一个?
部分功能:
exports.postTestResultsToSlack = functions.testLab
.testMatrix()
.onComplete(async testMatrix => {
if (testMatrix.clientInfo.details['testType'] != 'regression') {
// Not regression tests
return null;
}
const { testMatrixId, outcomeSummary, resultStorage } = testMatrix;
const projectID = "project-feat1"
const executionID = resultStorage.toolResultsExecutionId
const historyID = resultStorage.toolResultsHistoryId
const historyRequest = await axios.get(`https://toolresults.googleapis.com/toolresults/v1beta3/projects/${projectID}/histories/${historyID}/executions/${executionID}/environments`, {
headers: {
'Authorization': `Bearer $(gcloud auth application-default print-access-token)`,
'X-Goog-User-Project': projectID
}
});
字符串
3条答案
按热度按时间4smxwvx51#
经过无数个小时的花费,我偶然发现了答案滚动通过自动完成的建议.谷歌有关于身份验证的文档,但没有提到这是什么你需要云函数使API请求:
字符串
jgwigjjp2#
这是我为google auth编写的最后一段代码,与上面的代码类似,但是使用了一个base64的环境变量credentials。
字符串
我一辈子都无法理解谷歌如何期望人们使用任何一种自动部署软件来做不同的事情。
xtfmy6hx3#
我遇到了同样的问题,但调用谷歌翻译API,创建一个令牌,你需要添加范围,如果你使用的是服务帐户,授予服务使用消费者角色。
字符串