我正在尝试使用Azure函数中的Azure资源图python SDK查询Azure订阅中的资源。使用Functions运行时的事实并不重要,代码也无法在本地运行。 查询本身很好地工作。但是,然后我想在后续步骤中使用结果,这就是我遇到的一个问题。
credentials, *_ = get_azure_cli_credentials()
subscription_client = SubscriptionClient(credentials)
subs = [sub.as_dict() for sub in subscription_client.subscriptions.list()]
subs_list = []
for sub in subs:
subs_list.append(sub.get('subscription_id'))
client = rg.ResourceGraphClient(credentials)
request = QueryRequest(subscriptions=subs_list, query="resources | where type == 'microsoft.storage/storageaccounts'| where properties.supportsHttpsTrafficOnly == 'false'")
response = client.resources(request)
logging.info(response)
我尝试了以下方法:
for resource in response:
logging.info(resource)
This fails with Exception: TypeError: 'QueryResponse' object is not iterable
.
For reference: https://docs.microsoft.com/en-us/python/api/azure-mgmt-resourcegraph/azure.mgmt.resourcegraph.models.queryresponse?view=azure-python
logging.info(response['data'])
This fails with Exception: TypeError: 'QueryResponse' object is not subscriptable
.
Anybody know how to use this response now?
Thanks!