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

Function main

compute/getUsageExportBucket.js:21–62  ·  view source on GitHub ↗

* Retrieve Compute Engine usage export bucket for the Cloud project. * Replaces the empty value returned by the API with the default value used to generate report file names. * * @param {string} projectId - ID or number of the project you want to use.

(projectId)

Source from the content-addressed store, hash-verified

19 * @param {string} projectId - ID or number of the project you want to use.
20 */
21function main(projectId) {
22 // [START compute_usage_report_get]
23 /**
24 * TODO(developer): Uncomment and replace these variables before running the sample.
25 */
26 // const projectId = 'YOUR_PROJECT_ID';
27
28 const compute = require('@google-cloud/compute');
29
30 async function getUsageExportBucket() {
31 // Get the usage export location for the project from the server.
32 const projectsClient = new compute.ProjectsClient();
33 const [project] = await projectsClient.get({
34 project: projectId,
35 });
36
37 const usageExportLocation = project.usageExportLocation;
38
39 if (!usageExportLocation || !usageExportLocation.bucketName) {
40 // The usage reports are disabled.
41 return;
42 }
43
44 if (!usageExportLocation.reportNamePrefix) {
45 // Although the server explicitly sent the empty string value,
46 // the next usage report generated with these settings still has the default prefix value `usage_gce`.
47 // (see https://cloud.google.com/compute/docs/reference/rest/v1/projects/get)
48 console.log(
49 'Report name prefix not set, replacing with default value of `usage_gce`.'
50 );
51 usageExportLocation.reportNamePrefix = 'usage_gce';
52 }
53
54 console.log(
55 'Returned reportNamePrefix:',
56 usageExportLocation.reportNamePrefix
57 );
58 }
59
60 getUsageExportBucket();
61 // [END compute_usage_report_get]
62}
63
64main(...process.argv.slice(2));

Callers 1

Calls 1

getUsageExportBucketFunction · 0.85

Tested by

no test coverage detected