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

Function getSecret

secret-manager/getSecret.js:26–48  ·  view source on GitHub ↗

* Get metadata about a secret. * * @param {string} projectId The ID of the Google Cloud project. * @param {string} secretId The ID of the secret to retrieve.

(projectId, secretId)

Source from the content-addressed store, hash-verified

24 * @param {string} secretId The ID of the secret to retrieve.
25 */
26async function getSecret(projectId, secretId) {
27 const client = new SecretManagerServiceClient();
28 const name = `projects/${projectId}/secrets/${secretId}`;
29 try {
30 const [secret] = await client.getSecret({
31 name: name,
32 });
33
34 if (secret.replication && secret.replication.replication) {
35 const policy = secret.replication.replication;
36 console.info(
37 `Found secret ${secret.name} with replication policy ${policy}`
38 );
39 } else {
40 console.info(`Found secret ${secret.name} with no replication policy.`);
41 }
42 return secret;
43 } catch (err) {
44 console.error(`Failed to retrieve secret ${name}:`, err);
45 } finally {
46 await client.close();
47 }
48}
49// [END secretmanager_get_secret]
50
51async function main() {

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected