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

Function main

storage/printFileAcl.js:25–57  ·  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', fileName = 'test.txt')

Source from the content-addressed store, hash-verified

23 */
24
25function main(bucketName = 'my-bucket', fileName = 'test.txt') {
26 // [START storage_print_file_acl]
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 ID of your GCS file
34 // const fileName = 'your-file-name';
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 printFileAcl() {
43 try {
44 // Gets the ACL for the file
45 const [acls] = await storage.bucket(bucketName).file(fileName).acl.get();
46
47 acls.forEach(acl => {
48 console.log(`${acl.role}: ${acl.entity}`);
49 });
50 } catch (error) {
51 console.error('Error executing print file ACL:', error.message || error);
52 }
53 }
54
55 printFileAcl();
56 // [END storage_print_file_acl]
57}
58main(...process.argv.slice(2));

Callers 1

printFileAcl.jsFile · 0.70

Calls 1

printFileAclFunction · 0.85

Tested by

no test coverage detected