Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(secret-manager): add optional ttl field to createSecret function #3937

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all 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 = undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case, could you go ahead and set it to 900s instead of undefined?

) {
// [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).

// 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;
}

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

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