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

Function main

storage/getRequesterPaysStatus.js:25–68  ·  view source on GitHub ↗

* This application demonstrates how to perform basic operations on buckets 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.

(projectId, bucketName = 'my-bucket')

Source from the content-addressed store, hash-verified

23 */
24
25function main(projectId, bucketName = 'my-bucket') {
26 // [START storage_get_requester_pays_status]
27 /**
28 * TODO(developer): Uncomment the following lines before running the sample.
29 */
30 // The ID of your Google Cloud project
31 // const projectId = 'your-project-id';
32
33 // The ID of your GCS bucket
34 // const bucketName = 'your-unique-bucket-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 getRequesterPaysStatus() {
43 try {
44 // Gets the requester-pays status of a bucket
45 const [metadata] = await storage
46 .bucket(bucketName)
47 .getMetadata({userProject: projectId});
48
49 let status;
50 if (metadata && metadata.billing && metadata.billing.requesterPays) {
51 status = 'enabled';
52 } else {
53 status = 'disabled';
54 }
55 console.log(
56 `Requester-pays requests are ${status} for bucket ${bucketName}.`
57 );
58 } catch (error) {
59 console.error(
60 'Error executing get requester pays status:',
61 error.message || error
62 );
63 }
64 }
65
66 getRequesterPaysStatus();
67 // [END storage_get_requester_pays_status]
68}
69main(...process.argv.slice(2));

Callers 1

Calls 1

getRequesterPaysStatusFunction · 0.85

Tested by

no test coverage detected