* 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)
| 24 | * @param {string} secretId The ID of the secret to retrieve. |
| 25 | */ |
| 26 | async 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 | |
| 51 | async function main() { |