Skip to content

Commit cfd36a0

Browse files
alarconesparzaiennaecode-review-assist[bot]
authored
feat(secretmanager): add optional ttl to create secret sample (GoogleCloudPlatform#9889)
* feat(secretmanager): add optional ttl to create secret sample * nit: Update secretmanager/src/main/java/secretmanager/CreateSecret.java Co-authored-by: code-review-assist[bot] <182814678+code-review-assist[bot]@users.noreply.github.com> * fix(secretmanager): fix comment indentation to resolve linting issues --------- Co-authored-by: Jennifer Davis <iennae@gmail.com> Co-authored-by: code-review-assist[bot] <182814678+code-review-assist[bot]@users.noreply.github.com>
1 parent 7afa0d2 commit cfd36a0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

secretmanager/src/main/java/secretmanager/CreateSecret.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.cloud.secretmanager.v1.Replication;
2222
import com.google.cloud.secretmanager.v1.Secret;
2323
import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;
24+
import com.google.protobuf.Duration;
2425
import java.io.IOException;
2526

2627
public class CreateSecret {
@@ -41,13 +42,20 @@ public static void createSecret(String projectId, String secretId) throws IOExce
4142
// Build the parent name from the project.
4243
ProjectName projectName = ProjectName.of(projectId);
4344

45+
// Optionally set a TTL for the secret. This demonstrates how to configure
46+
// a secret to be automatically deleted after a certain period. The TTL is
47+
// specified in seconds (e.g., 900 for 15 minutes). This can be useful
48+
// for managing sensitive data and reducing storage costs.
49+
Duration ttl = Duration.newBuilder().setSeconds(900).build();
50+
4451
// Build the secret to create.
4552
Secret secret =
4653
Secret.newBuilder()
4754
.setReplication(
4855
Replication.newBuilder()
4956
.setAutomatic(Replication.Automatic.newBuilder().build())
5057
.build())
58+
.setTtl(ttl)
5159
.build();
5260

5361
// Create the secret.

0 commit comments

Comments
 (0)