【发布时间】:2019-08-18 21:35:07
【问题描述】:
我正在尝试使用 Google Cloud Function 在不使用时关闭 Google App Engine Flex 环境。我正在努力寻找使用 nodejs GoogleAPIs 客户端进行身份验证的最佳方法。
当然我不需要用户输入?
【问题讨论】:
标签: google-app-engine google-cloud-platform google-cloud-functions
我正在尝试使用 Google Cloud Function 在不使用时关闭 Google App Engine Flex 环境。我正在努力寻找使用 nodejs GoogleAPIs 客户端进行身份验证的最佳方法。
当然我不需要用户输入?
【问题讨论】:
标签: google-app-engine google-cloud-platform google-cloud-functions
如果您指定了所需的 OAuth 范围,我们花了一些时间才发现捆绑的 GoogleAuth 库实际上获取了 Cloud Function 环境的权限。这种方法的好处是无需管理密钥!
const {google} = require('googleapis');
const gae = google.appengine('v1');
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/appengine.admin',
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/cloud-platform.read-only']
});
async function trigger(event, context) {
const authClient = await auth.getClient();
const versionsResponse = await gae.apps.services.versions.list({
auth: authClient,
appsId: "<APP_ID>",
servicesId: "<SERVICE_ID>",
fields: "versions(id,name,servingStatus)"
});
// Rest of code ...
}
我找到了代码here
【讨论】: