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

Function main

storage/printFileAclForUser.js:25–73  ·  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',
  userEmail = 'jdobry@google.com'
)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 1

printFileAclForUserFunction · 0.85

Tested by

no test coverage detected