You can use the following code to list the services in v1beta1 using the gcloud python SDK for serviceusage.googleapis.com with the filter 'state:ENABLED' in PROJECT_ID:
from google.cloud import service_usage
from google.oauth2 import service_account
# Replace with your project id
project_id = 'YOUR_PROJECT_ID'
# Replace with your service account key file path
key_file_path = '/path/to/your/key_file.json'
# Define the filter to only include ENABLED services
filter = 'state:ENABLED'
# Create a service usage client using the credentials from the key file
credentials = service_account.Credentials.from_service_account_file(key_file_path)
service_usage_client = service_usage.ServiceUsageClient(credentials=credentials)
# List the services in the project with the specified filter
services = service_usage_client.list_services(parent=f"projects/{project_id}", filter_=filter)
# Print the names of the enabled services
for service in services:
print(service.name)
Note: You must replace YOUR_PROJECT_ID
and /path/to/your/key_file.json
with your actual project ID and service account key file path, respectively.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-12-05 11:00:00 +0000
Seen: 7 times
Last updated: Jan 19 '22
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?