(projectId = 'serviceAccountProjectId')
| 20 | // usage: node getServiceAccount.js <PROJECT_ID> |
| 21 | |
| 22 | function main(projectId = 'serviceAccountProjectId') { |
| 23 | // [START storage_get_service_account] |
| 24 | /** |
| 25 | * TODO(developer): Uncomment the following lines before running the sample. |
| 26 | */ |
| 27 | // The ID of your GCP project |
| 28 | // const projectId = 'your-project-id'; |
| 29 | |
| 30 | // Imports the Google Cloud client library |
| 31 | const {Storage} = require('@google-cloud/storage'); |
| 32 | |
| 33 | // Creates a client |
| 34 | const storage = new Storage({ |
| 35 | projectId, |
| 36 | }); |
| 37 | |
| 38 | async function getServiceAccount() { |
| 39 | try { |
| 40 | const [serviceAccount] = await storage.getServiceAccount(); |
| 41 | console.log( |
| 42 | `The GCS service account for project ${projectId} is: ${serviceAccount.emailAddress}` |
| 43 | ); |
| 44 | } catch (error) { |
| 45 | console.error( |
| 46 | 'Error executing get service account:', |
| 47 | error.message || error |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | getServiceAccount(); |
| 53 | // [END storage_get_service_account] |
| 54 | } |
| 55 | main(...process.argv.slice(2)); |
no test coverage detected