Delete a Certificate template
Stay organized with collections
Save and categorize content based on your preferences.
Delete the specified certificate template from project.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code demonstrates how to delete a specified certificate template from a project using the Certificate Authority Service.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves setting up Application Default Credentials for authentication, as detailed in the linked documentation.\u003c/p\u003e\n"],["\u003cp\u003eBoth Java and Python code samples are provided, illustrating the steps to delete a certificate template by its ID, project, and location.\u003c/p\u003e\n"],["\u003cp\u003eThe code uses the \u003ccode\u003eCertificateAuthorityServiceClient\u003c/code\u003e to send a \u003ccode\u003eDeleteCertificateTemplateRequest\u003c/code\u003e, then retrieves and checks the result for errors.\u003c/p\u003e\n"]]],[],null,["Delete the specified certificate template from project.\n\nCode sample \n\nJava\n\n\nTo authenticate to CA Service, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.api.core.https://cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html;\n import com.google.cloud.security.privateca.v1.https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.html;\n import com.google.cloud.security.privateca.v1.https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.CertificateTemplateName.html;\n import com.google.cloud.security.privateca.v1.https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.DeleteCertificateTemplateRequest.html;\n import com.google.longrunning.https://cloud.google.com/java/docs/reference/proto-google-common-protos/latest/com.google.longrunning.Operation.html;\n import java.io.IOException;\n import java.util.concurrent.ExecutionException;\n import java.util.concurrent.TimeUnit;\n import java.util.concurrent.TimeoutException;\n\n public class DeleteCertificateTemplate {\n\n public static void main(String[] args)\n throws IOException, ExecutionException, InterruptedException, TimeoutException {\n /* TODO(developer): Replace these variables before running the sample.\n location: For a list of locations, see:\n https://cloud.google.com/certificate-authority-service/docs/locations\n certificateTemplateId: Id of the certificate template to delete. */\n String project = \"your-project-id\";\n String location = \"ca-location\";\n String certificateTemplateId = \"certificate-template-id\";\n\n deleteCertificateTemplate(project, location, certificateTemplateId);\n }\n\n // Deletes the certificate template present in the given project and location.\n public static void deleteCertificateTemplate(\n String project, String location, String certificateTemplateId)\n throws IOException, ExecutionException, InterruptedException, TimeoutException {\n /* Initialize client that will be used to send requests. This client only needs to be created\n once, and can be reused for multiple requests. After completing all of your requests, call\n the `certificateAuthorityServiceClient.close()` method on the client to safely\n clean up any remaining background resources. */\n try (https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.html certificateAuthorityServiceClient =\n https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.html.create()) {\n\n // Set the parent name of the certificate template to be deleted.\n https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.DeleteCertificateTemplateRequest.html request =\n https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.DeleteCertificateTemplateRequest.html.newBuilder()\n .setName(\n https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.CertificateTemplateName.html.of(project, location, certificateTemplateId).toString())\n .build();\n\n ApiFuture\u003cOperation\u003e futureCall =\n certificateAuthorityServiceClient.https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient.html#com_google_cloud_security_privateca_v1_CertificateAuthorityServiceClient_deleteCertificateTemplateCallable__().futureCall(request);\n\n https://cloud.google.com/java/docs/reference/proto-google-common-protos/latest/com.google.longrunning.Operation.html response = futureCall.get(60, TimeUnit.SECONDS);\n\n // Check for errors.\n if (response.https://cloud.google.com/java/docs/reference/proto-google-common-protos/latest/com.google.longrunning.Operation.html#com_google_longrunning_Operation_hasError__()) {\n System.out.println(\"Error deleting the certificate template ! \" + response.https://cloud.google.com/java/docs/reference/proto-google-common-protos/latest/com.google.longrunning.Operation.html#com_google_longrunning_Operation_getError__());\n return;\n }\n\n System.out.println(\"Successfully created certificate template ! \" + response.https://cloud.google.com/java/docs/reference/proto-google-common-protos/latest/com.google.longrunning.Operation.html#com_google_longrunning_Operation_getName__());\n }\n }\n }\n\nPython\n\n\nTo authenticate to CA Service, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import google.cloud.security.privateca_v1 as privateca_v1\n\n\n def delete_certificate_template(\n project_id: str,\n location: str,\n certificate_template_id: str,\n ) -\u003e None:\n \"\"\"\n Delete the certificate template present in the given project and location.\n\n Args:\n project_id: project ID or project number of the Cloud project you want to use.\n location: location you want to use. For a list of locations, see: https://cloud.google.com/certificate-authority-service/docs/locations.\n certificate_template_id: set a unique name for the certificate template.\n \"\"\"\n\n caServiceClient = privateca_v1.CertificateAuthorityServiceClient()\n\n # Request to delete a certificate template.\n request = privateca_v1.DeleteCertificateTemplateRequest(\n name=caServiceClient.certificate_template_path(\n project_id,\n location,\n certificate_template_id,\n )\n )\n operation = caServiceClient.delete_certificate_template(request=request)\n result = operation.result()\n\n print(\"Operation result\", result)\n print(\"Deleted certificate template:\", certificate_template_id)\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=privateca)."]]