I cannot find any documentation on how to generate/renew the masterkey of CosmosDB for Read/Write or only for Read.
I can do it on Azure Portal, but I wish to do this with python or with a REST API.
For lot of ressource in Azure, we can use the Service Principal to generate a Token and then access other API. Like in Databricks.
curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' \
https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token \
-d 'client_id=${CLIENT_ID}' \
-d 'grant_type=client_credentials' \
-d 'scope=2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default' \
-d 'client_secret=${CLIENT_SECRET}'
With the scope=2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default
it will grant me access to Databricks API. https://vault.azure.net/.default
is for Azure KeyVault. But I can't find anything for cosmos-DB
Any Idea on how to manage cosmosdb from a Service Principal?
CodePudding user response:
Yes you can do this using the Python Azure Management Library for Cosmos DB.
Pip install these
azure-identity
azure-mgmt-resource==15.0.0
azure-mgmt-cosmosdb==6.4.0
azure-cosmos==4.2.0
Some samples that show you how to get started using this library here
The API article on how to regenerate a key is here