Last active
January 2, 2023 21:16
-
-
Save dvu4/0ad73f1795d3110edeb2f02fa63422a0 to your computer and use it in GitHub Desktop.
this script will retrieve the keyvault name in Azure Storage Account by looking up the service principal name (display_name) in each entity in the table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from azure.data.tables import TableClient | |
| import get_storage_account_connection_string | |
| STORAGE_ACCOUNT_NAME = "storage_account_name" | |
| def read_keyvault_from_storage_table(display_name: str) -> Optional[str]: | |
| """ | |
| Parameters | |
| ---------- | |
| display_name : service principal name | |
| Returns : key vault name | |
| ------- | |
| """ | |
| connection_string = get_storage_account_connection_string() | |
| table_service_client = TableClient.from_connection_string(conn_str=connection_string, | |
| table_name=STORAGE_TABLE_NAME) | |
| params = {"display_name" : display_name} | |
| my_filter = "RowKey eq @display_name" | |
| entities = table_service_client.query_entities( | |
| query_filter=my_filter, | |
| select=["RowKey", "keyvault_name"], | |
| parameters=params) | |
| keyvault = [entity["keyvault_name"] for entity in entities] | |
| return keyvault[0] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment