Search in sources :

Example 1 with DeleteSecretRequest

use of com.google.cloud.secretmanager.v1.DeleteSecretRequest in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplate method deleteSecret.

@Override
public void deleteSecret(String secretId, String projectId) {
    SecretName name = SecretName.of(projectId, secretId);
    DeleteSecretRequest request = DeleteSecretRequest.newBuilder().setName(name.toString()).build();
    this.secretManagerServiceClient.deleteSecret(request);
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) DeleteSecretRequest(com.google.cloud.secretmanager.v1.DeleteSecretRequest)

Example 2 with DeleteSecretRequest

use of com.google.cloud.secretmanager.v1.DeleteSecretRequest in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplateTests method verifyDeleteSecretRequest.

private void verifyDeleteSecretRequest(String secretId, String projectId) {
    SecretName name = SecretName.of(projectId, secretId);
    DeleteSecretRequest request = DeleteSecretRequest.newBuilder().setName(name.toString()).build();
    verify(this.client).deleteSecret(request);
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) DeleteSecretRequest(com.google.cloud.secretmanager.v1.DeleteSecretRequest)

Example 3 with DeleteSecretRequest

use of com.google.cloud.secretmanager.v1.DeleteSecretRequest in project java-docs-samples by GoogleCloudPlatform.

the class QuickstartIT method afterAll.

@AfterClass
public static void afterAll() throws Exception {
    Assert.assertFalse("missing GOOGLE_CLOUD_PROJECT", Strings.isNullOrEmpty(PROJECT_ID));
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Delete the secret created by quickstart
        SecretName name = SecretName.of(PROJECT_ID, SECRET_ID);
        DeleteSecretRequest deleteRequest = DeleteSecretRequest.newBuilder().setName(name.toString()).build();
        client.deleteSecret(deleteRequest);
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) DeleteSecretRequest(com.google.cloud.secretmanager.v1.DeleteSecretRequest) AfterClass(org.junit.AfterClass)

Example 4 with DeleteSecretRequest

use of com.google.cloud.secretmanager.v1.DeleteSecretRequest in project java-docs-samples by GoogleCloudPlatform.

the class DeleteSecretWithEtag method deleteSecret.

// Delete an existing secret with the given name and etag.
public static void deleteSecret(String projectId, String secretId, 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 secret name.
        SecretName secretName = SecretName.of(projectId, secretId);
        // Construct the request.
        DeleteSecretRequest request = DeleteSecretRequest.newBuilder().setName(secretName.toString()).setEtag(etag).build();
        // Delete the secret.
        client.deleteSecret(request);
        System.out.printf("Deleted secret %s\n", secretId);
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient) DeleteSecretRequest(com.google.cloud.secretmanager.v1.DeleteSecretRequest)

Example 5 with DeleteSecretRequest

use of com.google.cloud.secretmanager.v1.DeleteSecretRequest 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)

Aggregations

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