【发布时间】:2021-12-18 22:29:03
【问题描述】:
我在 Google Cloud 上的 Node.JS 中有一个云功能,我需要向 Google 发出 GET 请求,它需要一个身份验证令牌。使用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
}
});
【问题讨论】:
-
您在执行此操作时是否遇到任何错误?如果是这样,你能在这里提供你的错误吗?
-
Error: Request failed with status code 401 -
第一个链接坏了。
-
试试这个:Link
标签: node.js google-app-engine google-cloud-functions authorization