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

Function main

storage/addBucketOwnerAcl.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_add_bucket_owner]
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 add
34 // const userEmail = 'user-email-to-add';
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 addBucketOwner() {
43 try {
44 // Makes the user an owner of the bucket. You can use addAllUsers(),
45 // addDomain(), addProject(), addGroup(), and addAllAuthenticatedUsers()
46 // to grant access to different types of entities. You can also use "readers"
47 // and "writers" to grant different roles.
48 await storage.bucket(bucketName).acl.owners.addUser(userEmail);
49
50 console.log(
51 `Added user ${userEmail} as an owner on bucket ${bucketName}.`
52 );
53 } catch (error) {
54 console.error(
55 'Error executing add bucket owner ACL:',
56 error.message || error
57 );
58 }
59 }
60
61 addBucketOwner();
62 // [END storage_add_bucket_owner]
63}
64main(...process.argv.slice(2));

Callers 1

Calls 1

addBucketOwnerFunction · 0.85

Tested by

no test coverage detected