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

Function main

secret-manager/editSecretAnnotations.js:17–58  ·  view source on GitHub ↗
(name, annotationKey, annotationValue)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(name, annotationKey, annotationValue) {
18 // [START secretmanager_edit_secret_annotations]
19 /**
20 * TODO(developer): Uncomment these variables before running the sample.
21 */
22 // const name = 'projects/my-project/secrets/my-secret';
23 // const annotationKey = 'updatedannotationkey';
24 // const annotationValue = 'updatedannotationvalue';
25
26 // Imports the Secret Manager library
27 const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
28
29 // Instantiates a client
30 const client = new SecretManagerServiceClient();
31
32 async function getSecret() {
33 const [secret] = await client.getSecret({
34 name: name,
35 });
36
37 return secret;
38 }
39
40 async function editSecretAnnotations() {
41 const oldSecret = await getSecret();
42 oldSecret.annotations[annotationKey] = annotationValue;
43 const [secret] = await client.updateSecret({
44 secret: {
45 name: name,
46 annotations: oldSecret.annotations,
47 },
48 updateMask: {
49 paths: ['annotations'],
50 },
51 });
52
53 console.info(`Updated secret ${secret.name}`);
54 }
55
56 editSecretAnnotations();
57 // [END secretmanager_edit_secret_annotations]
58}
59
60const args = process.argv.slice(2);
61main(...args).catch(console.error);

Callers 1

Calls 1

editSecretAnnotationsFunction · 0.85

Tested by

no test coverage detected