Google Cloud Certificate Manager
The `google-cloud-certificate-manager` library is the official Python client for the Google Cloud Certificate Manager API. It allows developers to programmatically acquire and manage TLS (SSL) certificates for use with Cloud Load Balancing. Currently at version 1.13.0, it is part of the larger `google-cloud-python` monorepo, which undergoes frequent updates, ensuring ongoing feature development and maintenance.
Warnings
- breaking This library requires Python 3.9 or newer. Running on older Python versions (e.g., 3.8 or below) will result in installation failures or runtime errors.
- gotcha Authentication must be set up correctly for the client to interact with Google Cloud services. Without proper authentication (e.g., Application Default Credentials, service account key, or `GOOGLE_APPLICATION_CREDENTIALS` environment variable), `google.auth.exceptions.DefaultCredentialsError` or similar authentication errors will occur.
- gotcha The Certificate Manager API must be explicitly enabled in your Google Cloud project for the client library calls to succeed. If the API is not enabled, you will receive `PERMISSION_DENIED` errors.
- gotcha When using `CertificateManagerClient` as a context manager (`with certificate_manager_v1.CertificateManagerClient() as client:`), be aware that exiting the `with` block will close the underlying transport. This can cause issues if the transport object is shared with other client instances.
Install
-
pip install google-cloud-certificate-manager
Imports
- CertificateManagerClient
from google.cloud.certificate_manager import CertificateManagerClient
from google.cloud import certificate_manager_v1
Quickstart
import os
from google.cloud import certificate_manager_v1
# Set your Google Cloud Project ID
project_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id')
location = 'global' # Certificate Manager resources are often global
def list_certificates():
client = certificate_manager_v1.CertificateManagerClient()
parent = client.common_location_path(project_id, location)
print(f"Listing certificates in project {project_id} in location {location}:")
try:
for certificate in client.list_certificates(parent=parent):
print(f"- Certificate: {certificate.name} (DNS names: {', '.join(certificate.managed.dns_authorizations or ['N/A'])})")
except Exception as e:
print(f"Error listing certificates: {e}")
if __name__ == "__main__":
list_certificates()