* 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')
| 23 | */ |
| 24 | |
| 25 | function 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 | } |
| 58 | main(...process.argv.slice(2)); |
no test coverage detected