Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions secret-manager/createSecret.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

'use strict';

async function main(parent = 'projects/my-project', secretId = 'my-secret') {
async function main(
parent = 'projects/my-project',
secretId = 'my-secret',
ttl = '900s'
Comment thread
hivanalejandro marked this conversation as resolved.
Outdated
) {
// [START secretmanager_create_secret]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const parent = 'projects/my-project';
// const secretId = 'my-secret';
// const ttl = '900s' // Optional: Specify TTL in seconds (e.g., '900s' for 15 minutes).
Comment thread
hivanalejandro marked this conversation as resolved.
Outdated

// Imports the Secret Manager library
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
Expand All @@ -29,14 +34,21 @@ async function main(parent = 'projects/my-project', secretId = 'my-secret') {
const client = new SecretManagerServiceClient();

async function createSecret() {
const secretConfig = {
replication: {
automatic: {},
},
};

// Add TTL to the secret configuration if provided
if (ttl) {
secretConfig.ttl = ttl;
Comment thread
briandorsey marked this conversation as resolved.
Outdated
}

const [secret] = await client.createSecret({
parent: parent,
secretId: secretId,
secret: {
replication: {
automatic: {},
},
},
secret: secretConfig,
});

console.log(`Created secret ${secret.name}`);
Expand Down