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

Function main

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

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(name, annotationKey) {
18 // [START secretmanager_delete_secret_annotation]
19 /**
20 * TODO(developer): Uncomment these variables before running the sample.
21 */
22 // const name = 'projects/my-project/secrets/my-secret';
23 // const annotationKey = 'secretmanager';
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 getSecret() {
32 const [secret] = await client.getSecret({
33 name: name,
34 });
35
36 return secret;
37 }
38
39 async function deleteSecretAnnotation() {
40 const oldSecret = await getSecret();
41 if (!oldSecret.annotations) {
42 console.info(
43 `Secret ${oldSecret.name} has no annotations, skipping update.`
44 );
45 return;
46 }
47 delete oldSecret.annotations[annotationKey];
48 const [secret] = await client.updateSecret({
49 secret: {
50 name: name,
51 annotations: oldSecret.annotations,
52 },
53 updateMask: {
54 paths: ['annotations'],
55 },
56 });
57
58 console.info(`Updated secret ${secret.name}`);
59 }
60
61 deleteSecretAnnotation();
62 // [END secretmanager_delete_secret_annotation]
63}
64
65const args = process.argv.slice(2);
66main(...args).catch(console.error);

Callers 1

Calls 1

deleteSecretAnnotationFunction · 0.85

Tested by

no test coverage detected