[英]Enable Google IAM API Python
is there anyway to enable IAM API through python.无论如何通过python启用IAM API。 However, I dont see any methods mentioned in Google documentaion.
但是,我没有看到 Google 文档中提到的任何方法。 I have gone through this link https://cloud.google.com/service-usage/docs/enable-disable#gcloud but it only describes enabling service API via, gcloud or curl.
我已经浏览了这个链接https://cloud.google.com/service-usage/docs/enable-disable#gcloud但它只描述了通过 gcloud 或 ZF6E57C9DE709E45FEB0D955351FZ 启用服务 API。
Is there anyway I can enable it via Python?无论如何我可以通过 Python 启用它吗?
The API you want to use is Service Usage您要使用的 API 是 Service Usage
Link to the REST API:链接到 REST API:
Link to the Python API:链接到 Python API:
Example code that I wrote to use the Python API to list services:我编写的使用 Python API 列出服务的示例代码:
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
# https://cloud.google.com/service-usage/docs/reference/rest/v1/services
# https://cloud.google.com/service-usage/docs/list-services
credentials = GoogleCredentials.get_application_default()
project = 'projects/development-xxxxxx'
service = discovery.build('serviceusage', 'v1', credentials=credentials)
next = None
totalCount = 0
while 1:
request = service.services().list(parent=project, pageToken=next)
response = ''
try:
response = request.execute()
except Exception as e:
print(e)
break
services = response.get('services')
for index in range(len(services)):
totalCount += 1
item = services[index]
name = item['config']['name']
state = item['state']
print("%-50s %s" % (name, state))
next = response.get('nextPageToken')
# print('NEXT:', next)
if next == None:
break;
print('')
print('Total number of services:', totalCount)
To enable a service call the enable method:要启用服务,请调用 enable 方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.