MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

storage/printBucketAclForUser.js:25–63  ·  view source on GitHub ↗

* This application demonstrates how to perform basic operations on bucket and * file Access Control Lists with the Google Cloud Storage API. * * For more information, see the README.md under /storage and the documentation * at https://cloud.google.com/storage/docs.

(bucketName = 'my-bucket', userEmail = 'jdobry@google.com')

Source from the content-addressed store, hash-verified

23 */
24
25function main(bucketName = 'my-bucket', userEmail = 'jdobry@google.com') {
26 // [START storage_print_bucket_acl_for_user]
27 /**
28 * TODO(developer): Uncomment the following lines before running the sample.
29 */
30 // The ID of your GCS bucket
31 // const bucketName = 'your-unique-bucket-name';
32
33 // The email address of the user to check
34 // const userEmail = 'user-email-to-check';
35
36 // Imports the Google Cloud client library
37 const {Storage} = require('@google-cloud/storage');
38
39 // Creates a client
40 const storage = new Storage();
41
42 async function printBucketAclForUser() {
43 try {
44 const options = {
45 // Specify the user
46 entity: `user-${userEmail}`,
47 };
48
49 // Gets the user's ACL for the bucket
50 const [aclObject] = await storage.bucket(bucketName).acl.get(options);
51
52 console.log(`${aclObject.role}: ${aclObject.entity}`);
53 } catch (error) {
54 console.error(
55 'Error executing print bucket ACL for user:',
56 error.message || error
57 );
58 }
59 }
60
61 printBucketAclForUser();
62 // [END storage_print_bucket_acl_for_user]
63}
64
65main(...process.argv.slice(2));

Callers 1

Calls 1

printBucketAclForUserFunction · 0.85

Tested by

no test coverage detected