Search in sources :

Example 1 with DestroySecretVersionRequest

use of com.google.cloud.secretmanager.v1beta1.DestroySecretVersionRequest in project java-secretmanager by googleapis.

the class ITSystemTest method tearDown.

@AfterClass
public static void tearDown() {
    /* destroy secret version */
    DestroySecretVersionRequest versionRequest = DestroySecretVersionRequest.newBuilder().setName(formattedSecretVersion).build();
    SecretVersion actualSecretVersion = client.destroySecretVersion(versionRequest);
    assertEquals(secretVersion.getCreateTime(), actualSecretVersion.getCreateTime());
    assertEquals(SecretVersion.State.DESTROYED, actualSecretVersion.getState());
    /* delete secret */
    DeleteSecretRequest secretRequest = DeleteSecretRequest.newBuilder().setName(formattedSecretName).build();
    client.deleteSecret(secretRequest);
    client.close();
}
Also used : SecretVersion(com.google.cloud.secretmanager.v1beta1.SecretVersion) DestroySecretVersionRequest(com.google.cloud.secretmanager.v1beta1.DestroySecretVersionRequest) DeleteSecretRequest(com.google.cloud.secretmanager.v1beta1.DeleteSecretRequest) AfterClass(org.junit.AfterClass)

Example 2 with DestroySecretVersionRequest

use of com.google.cloud.secretmanager.v1beta1.DestroySecretVersionRequest in project java-docs-samples by GoogleCloudPlatform.

the class DestroySecretVersionWithEtag method destroySecretVersion.

// Destroy an existing secret version.
public static void destroySecretVersion(String projectId, String secretId, String versionId, String etag) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the name from the version.
        SecretVersionName secretVersionName = SecretVersionName.of(projectId, secretId, versionId);
        // Build the request.
        DestroySecretVersionRequest request = DestroySecretVersionRequest.newBuilder().setName(secretVersionName.toString()).setEtag(etag).build();
        // Destroy the secret version.
        SecretVersion version = client.destroySecretVersion(request);
        System.out.printf("Destroyed secret version %s\n", version.getName());
    }
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) SecretVersion(com.google.cloud.secretmanager.v1.SecretVersion) DestroySecretVersionRequest(com.google.cloud.secretmanager.v1.DestroySecretVersionRequest) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Aggregations

DestroySecretVersionRequest (com.google.cloud.secretmanager.v1.DestroySecretVersionRequest)1 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)1 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)1 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)1 DeleteSecretRequest (com.google.cloud.secretmanager.v1beta1.DeleteSecretRequest)1 DestroySecretVersionRequest (com.google.cloud.secretmanager.v1beta1.DestroySecretVersionRequest)1 SecretVersion (com.google.cloud.secretmanager.v1beta1.SecretVersion)1 AfterClass (org.junit.AfterClass)1