( parent = 'projects/my-project', secretId = 'my-secret', ttl = undefined )
| 15 | 'use strict'; |
| 16 | |
| 17 | async function main( |
| 18 | parent = 'projects/my-project', |
| 19 | secretId = 'my-secret', |
| 20 | ttl = undefined |
| 21 | ) { |
| 22 | // [START secretmanager_create_secret] |
| 23 | /** |
| 24 | * TODO(developer): Uncomment these variables before running the sample. |
| 25 | */ |
| 26 | // const parent = 'projects/my-project'; |
| 27 | // const secretId = 'my-secret'; |
| 28 | // const ttl = undefined // Optional: Specify TTL in seconds (e.g., '900s' for 15 minutes). |
| 29 | |
| 30 | // Imports the Secret Manager library |
| 31 | const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); |
| 32 | |
| 33 | // Instantiates a client |
| 34 | const client = new SecretManagerServiceClient(); |
| 35 | |
| 36 | async function createSecret() { |
| 37 | const secretConfig = { |
| 38 | replication: { |
| 39 | automatic: {}, |
| 40 | }, |
| 41 | }; |
| 42 | |
| 43 | // Add TTL to the secret configuration if provided |
| 44 | if (ttl) { |
| 45 | secretConfig.ttl = { |
| 46 | seconds: parseInt(ttl.replace('s', ''), 10), |
| 47 | }; |
| 48 | console.log(`Secret TTL set to ${ttl}`); |
| 49 | } |
| 50 | |
| 51 | const [secret] = await client.createSecret({ |
| 52 | parent: parent, |
| 53 | secretId: secretId, |
| 54 | secret: secretConfig, |
| 55 | }); |
| 56 | |
| 57 | console.log(`Created secret ${secret.name}`); |
| 58 | } |
| 59 | |
| 60 | createSecret(); |
| 61 | // [END secretmanager_create_secret] |
| 62 | } |
| 63 | |
| 64 | const args = process.argv.slice(2); |
| 65 | main(...args).catch(console.error); |
no test coverage detected