从云功能执行任何Google云端存储操作时出错。我一直得到错误[project-id]@appspot.gserviceaccount.com does not have storage.buckets.get
。我给了服务管理员不同的角色,包括editor
,storage admin
和storage 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}`);
});
};
我稍微修改了您的代码并创建了一个Node.js 8 HTTP触发的Google云功能,该功能已正确执行并检索了存储桶的ACL。按照下面的步骤,它也应该适合你:
HTTP
。Node.js 8
。package.json
用以下内容替换所有内容:{
"name": "sample-http",
"version": "0.0.1",
"dependencies": {
"@google-cloud/storage" : "^2.4.3"
}
}
getAClGoogleCloudStorage
。index.js
里面用this code from GitHub替换所有代码。CREATE
。成功创建后,转到Cloud Function的详细信息页面,然后单击Trigger
选项卡。单击为触发器提供的URL,您应该看到Execution finished!
作为响应。
检查云功能的日志时,您会注意到列出的存储桶的OWNER ...,READER ... ACL。
我已经测试了上面的代码,但它没有给我任何访问权限问题。