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

Function authCloudExplicit

auth/auth.js:50–77  ·  view source on GitHub ↗
({projectId, keyFilename})

Source from the content-addressed store, hash-verified

48};
49
50const authCloudExplicit = async ({projectId, keyFilename}) => {
51 // [START auth_cloud_explicit]
52 // Imports the Google Cloud client library.
53 const {Storage} = require('@google-cloud/storage');
54
55 // Instantiates a client. Explicitly use service account credentials by
56 // specifying the private key file. All clients in google-cloud-node have this
57 // helper, see https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/docs/authentication.md
58 // const projectId = 'project-id'
59 // const keyFilename = '/path/to/keyfile.json'
60 const storage = new Storage({projectId, keyFilename});
61
62 // Makes an authenticated API request.
63 async function listBuckets() {
64 try {
65 const [buckets] = await storage.getBuckets();
66
67 console.log('Buckets:');
68 buckets.forEach(bucket => {
69 console.log(bucket.name);
70 });
71 } catch (err) {
72 console.error('ERROR:', err);
73 }
74 }
75 listBuckets();
76 // [END auth_cloud_explicit]
77};
78
79const cli = require('yargs')
80 .demand(1)

Callers

nothing calls this directly

Calls 1

listBucketsFunction · 0.85

Tested by

no test coverage detected