File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed
Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change 1414
1515'use strict' ;
1616
17- async function main ( parent = 'projects/my-project' , secretId = 'my-secret' ) {
17+ async function main (
18+ parent = 'projects/my-project' ,
19+ secretId = 'my-secret' ,
20+ ttl = '900s'
21+ ) {
1822 // [START secretmanager_create_secret]
1923 /**
2024 * TODO(developer): Uncomment these variables before running the sample.
2125 */
2226 // const parent = 'projects/my-project';
2327 // const secretId = 'my-secret';
28+ // const ttl = '900s' // Optional: Specify TTL in seconds (e.g., '900s' for 15 minutes).
2429
2530 // Imports the Secret Manager library
26- const { SecretManagerServiceClient} = require ( '@google-cloud/secret-manager' ) ;
31+ const { SecretManagerServiceClient } = require ( '@google-cloud/secret-manager' ) ;
2732
2833 // Instantiates a client
2934 const client = new SecretManagerServiceClient ( ) ;
3035
3136 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 = ttl ;
46+ }
47+
3248 const [ secret ] = await client . createSecret ( {
3349 parent : parent ,
3450 secretId : secretId ,
35- secret : {
36- replication : {
37- automatic : { } ,
38- } ,
39- } ,
51+ secret : secretConfig ,
4052 } ) ;
4153
4254 console . log ( `Created secret ${ secret . name } ` ) ;
@@ -47,4 +59,4 @@ async function main(parent = 'projects/my-project', secretId = 'my-secret') {
4759}
4860
4961const args = process . argv . slice ( 2 ) ;
50- main ( ...args ) . catch ( console . error ) ;
62+ main ( ...args ) . catch ( console . error ) ;
You can’t perform that action at this time.
0 commit comments