Skip to content

Commit

Permalink
feat(secretmanager): add optional ttl to create secret sample (#9889)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Dec 23, 2024
1 parent 7afa0d2 commit cfd36a0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions secretmanager/src/main/java/secretmanager/CreateSecret.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.cloud.secretmanager.v1.Replication;
import com.google.cloud.secretmanager.v1.Secret;
import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;
import com.google.protobuf.Duration;
import java.io.IOException;

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

// Optionally set a TTL for the secret. This demonstrates how to configure
// a secret to be automatically deleted after a certain period. The TTL is
// specified in seconds (e.g., 900 for 15 minutes). This can be useful
// for managing sensitive data and reducing storage costs.
Duration ttl = Duration.newBuilder().setSeconds(900).build();

// Build the secret to create.
Secret secret =
Secret.newBuilder()
.setReplication(
Replication.newBuilder()
.setAutomatic(Replication.Automatic.newBuilder().build())
.build())
.setTtl(ttl)
.build();

// Create the secret.
Expand Down

0 comments on commit cfd36a0

Please sign in to comment.