【问题标题】:How to authenticate with Google App Engine Admin API from a Google Cloud Function context如何从 Google Cloud Function 上下文使用 Google App Engine Admin API 进行身份验证
【发布时间】:2019-08-18 21:35:07
【问题描述】:

我正在尝试使用 Google Cloud Function 在不使用时关闭 Google App Engine Flex 环境。我正在努力寻找使用 nodejs GoogleAPIs 客户端进行身份验证的最佳方法。

当然我不需要用户输入?

【问题讨论】:

    标签: google-app-engine google-cloud-platform google-cloud-functions


    【解决方案1】:

    如果您指定了所需的 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

    【讨论】:

    • 看看 Cloud Run。部署在 AppEngine Flex 和 Cloud Run 上的代码包非常接近(都是封装在容器中),安全策略与功能相同(您的工作可以重复使用)。无论如何,感谢您分享您的发现!
    猜你喜欢
    • 2019-05-14
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 2011-12-25
    • 2014-08-14
    • 1970-01-01
    • 2015-01-02
    • 2014-06-22
    相关资源
    最近更新 更多