简体   繁体   English

启用谷歌 IAM API Python

[英]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:

Service Usage API 服务使用 API

Link to the Python API:链接到 Python API:

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 方法:

API to enable a service API 启用服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS Python IAM API-如何以编程方式获取AWS IAM特权? - AWS Python IAM API - how to get AWS IAM privileges programmatically? 如何使用python API启用Google Compute Engine API - How to enable the Google Compute Engine API using python APIs 如何使用 Python 启用 Google Assistant API 的新“阅读”function? - How to enable new “read it” function of Google Assistant API with Python? 如何使用 Google API 计费获取 IAM 政策 - How to get IAM Policy using Google API billing 使用Python API启用VLAN跨越 - Enable VLAN Spanning with Python API 从 Python 访问具有 IAM 角色的 AWS API Gateway - Access AWS API Gateway with IAM roles from Python 无法在 Python API 中为新的 Google Cloud Platform 项目启用计费 - Can't enable billing for a fresh Google Cloud Platform project in Python API Google Cloud App Engine:是否有 API 或 SDK 调用来禁用/启用应用程序(python) - Google Cloud App Engine: Is there an API or SDK call to disable/enable an app (python) Python 启用 FastAPI API 密钥 header - Python enable FastAPI API Key header 使用 Python CDK 在 API 网关上启用 CORS - Enable CORS on API Gateway with Python CDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM