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

Function main

storage/removeFileOwnerAcl.js:25–70  ·  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_remove_file_owner]
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 remove
41 // const userEmail = 'user-email-to-remove';
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 removeFileOwner() {
50 try {
51 // Removes the user from the access control list of the file. You can use
52 // deleteAllUsers(), deleteDomain(), deleteProject(), deleteGroup(), and
53 // deleteAllAuthenticatedUsers() to remove access for different types of entities.
54 await storage
55 .bucket(bucketName)
56 .file(fileName)
57 .acl.owners.deleteUser(userEmail);
58
59 console.log(`Removed user ${userEmail} from file ${fileName}.`);
60 } catch (error) {
61 console.error(
62 'Error executing remove file owner ACL:',
63 error.message || error
64 );
65 }
66 }
67
68 removeFileOwner();
69 // [END storage_remove_file_owner]
70}
71
72main(...process.argv.slice(2));

Callers 1

Calls 1

removeFileOwnerFunction · 0.85

Tested by

no test coverage detected