Google云端存储权限问题

问题描述 投票:0回答:1

从云功能执行任何Google云端存储操作时出错。我一直得到错误[project-id]@appspot.gserviceaccount.com does not have storage.buckets.get。我给了服务管理员不同的角色,包括editorstorage adminstorage object admin,但似乎没有用。

以下是测试功能。

exports.test = async (req, res) => {

  const {Storage} = require('@google-cloud/storage');

  // Creates a client
  const storage = new Storage();

  // Gets the ACL for the bucket
  const [acls] = await storage.bucket('sharedbox').acl.get();

  acls.forEach(acl => {
    console.log(`${acl.role}: ${acl.entity}`);
  });
};
google-cloud-storage google-cloud-functions google-cloud-iam
1个回答
0
投票

我稍微修改了您的代码并创建了一个Node.js 8 HTTP触发的Google云功能,该功能已正确执行并检索了存储桶的ACL。按照下面的步骤,它也应该适合你:

  1. 使用您选择的名称创建新的Google Cloud功能。
  2. 触发HTTP
  3. 运行时间Node.js 8
  4. package.json用以下内容替换所有内容:
{
  "name": "sample-http",
  "version": "0.0.1",
  "dependencies": {
     "@google-cloud/storage" : "^2.4.3" 
  }
}
  1. 在功能下执行添加getAClGoogleCloudStorage
  2. index.js里面用this code from GitHub替换所有代码。
  3. 点击CREATE

成功创建后,转到Cloud Function的详细信息页面,然后单击Trigger选项卡。单击为触发器提供的URL,您应该看到Execution finished!作为响应。

检查云功能的日志时,您会注意到列出的存储桶的OWNER ...,READER ... ACL。

我已经测试了上面的代码,但它没有给我任何访问权限问题。

© www.soinside.com 2019 - 2024. All rights reserved.