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

Function main

secret-manager/accessSecretVersion.js:17–46  ·  view source on GitHub ↗
(name = 'projects/my-project/secrets/my-secret/versions/1')

Source from the content-addressed store, hash-verified

15'use strict';
16
17async 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
48const args = process.argv.slice(2);
49main(...args).catch(console.error);

Callers 1

Calls 1

accessSecretVersionFunction · 0.70

Tested by

no test coverage detected