List Certificate templates
Stay organized with collections
Save and categorize content based on your preferences.
List the Certificate templates in the specified project and location.
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 content provides code samples in Java and Python to list certificate templates within a specified project and location.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples utilize the Certificate Authority Service and require setting up Application Default Credentials for authentication.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating a request to list certificate templates and then iterating through the response to display the names of the found templates.\u003c/p\u003e\n"],["\u003cp\u003eThe content also provides information regarding the necessary imports for using the certificate authority service along with a link to view more Google cloud product samples.\u003c/p\u003e\n"]]],[],null,["# List Certificate templates\n\nList the Certificate templates in the specified project and location.\n\nCode sample\n-----------\n\n### Java\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.CertificateTemplate.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.ListCertificateTemplatesRequest.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.ListCertificateTemplatesResponse.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.LocationName.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 ListCertificateTemplates {\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 String project = \"your-project-id\";\n String location = \"ca-location\";\n\n listCertificateTemplates(project, location);\n }\n\n // Lists the certificate templates present in the given project and location.\n public static void listCertificateTemplates(String project, String location)\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 to list the certificate templates.\n https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.ListCertificateTemplatesRequest.html request =\n https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.ListCertificateTemplatesRequest.html.newBuilder()\n .setParent(https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.LocationName.html.of(project, location).toString())\n .build();\n\n ApiFuture\u003cListCertificateTemplatesResponse\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_listCertificateTemplatesCallable__().futureCall(request);\n\n // Get the response.\n https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.ListCertificateTemplatesResponse.html response = futureCall.get(60, TimeUnit.SECONDS);\n\n // List all templates.\n for (https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.CertificateTemplate.html template : response.https://cloud.google.com/java/docs/reference/google-cloud-security-private-ca/latest/com.google.cloud.security.privateca.v1.ListCertificateTemplatesResponse.html#com_google_cloud_security_privateca_v1_ListCertificateTemplatesResponse_getCertificateTemplatesList__()) {\n System.out.println(template.getName());\n }\n }\n }\n }\n\n### Python\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 list_certificate_templates(project_id: str, location: str) -\u003e None:\n \"\"\"\n List the certificate templates 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 \"\"\"\n\n caServiceClient = privateca_v1.CertificateAuthorityServiceClient()\n\n # List Templates Request.\n request = privateca_v1.ListCertificateTemplatesRequest(\n parent=caServiceClient.common_location_path(project_id, location),\n )\n\n print(\"Available certificate templates:\")\n for certificate_template in caServiceClient.list_certificate_templates(\n request=request\n ):\n print(certificate_template.name)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=privateca)."]]