123456789101112131415161718 |
- def get_azure_reader_role_id(AzureApiBearerToken, AzureSubscriptionId):
- """
- Gets the id of the reader role for this subscription.
- https://docs.microsoft.com/en-us/rest/api/authorization/roleassignments/list
- """
- api_url = "https://management.azure.com/subscriptions/" + AzureSubscriptionId + "/providers/Microsoft.Authorization/roleDefinitions?api-version=2015-07-01&$filter=roleName eq 'Reader'"
- authorization_value = "Bearer " + AzureApiBearerToken
- response = requests.get(api_url, headers={"Authorization": authorization_value})
- if "value" in response.json():
- value = (response.json()["value"])[0]
- if "id" in value:
- return value["id"]
- print("Failed to get the Azure Reader Role Id")
- return None
|