我正在使用Microsoft Azure Security Center (ASC) Management Client Library获取订阅的安全分数。库中的所有操作状态为
You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
因此,我正在使用以下规范创建SecurityCenter客户端:
SecurityCenter(credentials, subscription_id, asc_location, base_url=None)
然而,在我看来,正确获取asc_location
信息的唯一方法是使用SecurityCenter客户端获取它The spec与上面的引文相同,You should not instantiate...
。因此,我无法创建客户端,因为我需要ASC位置来创建客户端,我需要创建客户端来获取ASC位置
文件中提到
The location where ASC stores the data of the subscription. can be retrieved from Get locations
在pythonsdk文档中搜索这个“getlocations”,除了restapi之外,我什么都没有得到。我错过什么了吗?我们是否应该从SDK存储库中硬编码位置,如this SO post或this GitHub issue
正如官方API参考list locations所示:
它不会更改,因此如果您已经知道订阅的
asc_location
的值,则可以硬编码此值但每个订阅可能具有不同的asc\U位置值(my 2 Azure订阅具有不同的asc\U位置值)。 因此,如果您有很多Azure订阅,您可以通过API查询
asc_location
(据我所知,这是我能找到的唯一方法),然后使用SDK获得安全分数,请尝试以下代码:结果:
我最近遇到了这个问题
根据我的观察,我可以使用订阅下的任何位置启动SecurityCenter客户端。然后稍后
client.locations.list()
正好给我一个ASC位置在我的例子中,不管我的输入是
eastasia
,它总是westcentralus
请注意,如果使用get而不是list,您将得到异常
所以我做的有点尴尬
相关问题 更多 >
编程相关推荐