(name = 'projects/my-project/secrets/my-secret/versions/1')
| 15 | 'use strict'; |
| 16 | |
| 17 | async function main(name = 'projects/my-project/secrets/my-secret/versions/1') { |
| 18 | // [START secretmanager_access_secret_version] |
| 19 | /** |
| 20 | * TODO(developer): Uncomment these variables before running the sample. |
| 21 | */ |
| 22 | // const name = 'projects/my-project/secrets/my-secret/versions/5'; |
| 23 | // const name = 'projects/my-project/secrets/my-secret/versions/latest'; |
| 24 | |
| 25 | // Imports the Secret Manager library |
| 26 | const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); |
| 27 | |
| 28 | // Instantiates a client |
| 29 | const client = new SecretManagerServiceClient(); |
| 30 | |
| 31 | async function accessSecretVersion() { |
| 32 | const [version] = await client.accessSecretVersion({ |
| 33 | name: name, |
| 34 | }); |
| 35 | |
| 36 | // Extract the payload as a string. |
| 37 | const payload = version.payload.data.toString(); |
| 38 | |
| 39 | // WARNING: Do not print the secret in a production environment - this |
| 40 | // snippet is showing how to access the secret material. |
| 41 | console.info(`Payload: ${payload}`); |
| 42 | } |
| 43 | |
| 44 | accessSecretVersion(); |
| 45 | // [END secretmanager_access_secret_version] |
| 46 | } |
| 47 | |
| 48 | const args = process.argv.slice(2); |
| 49 | main(...args).catch(console.error); |
no test coverage detected