|
18 | 18 |
|
19 | 19 | def _extract_storage_account_resource_id(subscription_id, resource_group_name, container_uri): |
20 | 20 | """Extract storage account resource ID from container URI. |
21 | | - Used for permission guidance messages |
| 21 | + Used for permission guidance messages |
22 | 22 | Expected format: https://<storage-account-name>.blob.core.windows.net/<container-name> |
23 | 23 | """ |
24 | 24 | try: |
25 | 25 | parsed = urlparse(container_uri) |
26 | 26 | storage_account_name = parsed.hostname.split('.')[0] |
27 | 27 | return f"/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Storage/storageAccounts/{storage_account_name}" |
28 | | - except Exception: |
| 28 | + except Exception: # pylint: disable=broad-exception-caught |
29 | 29 | return "<storage-account-resource-id>" |
30 | 30 |
|
31 | 31 |
|
32 | 32 | def _extract_keyvault_resource_id(subscription_id, resource_group_name, keyvault_secret_uri): |
33 | 33 | """Extract key vault resource ID from secret URI. |
34 | | - Used for permission guidance messages |
| 34 | + Used for permission guidance messages |
35 | 35 | Expected format: https://<keyvault-name>.vault.azure.net/secrets/<secret-name> |
36 | 36 | """ |
37 | 37 | try: |
38 | 38 | parsed = urlparse(keyvault_secret_uri) |
39 | 39 | keyvault_name = parsed.hostname.split('.')[0] |
40 | 40 | return f"/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.KeyVault/vaults/{keyvault_name}" |
41 | | - except Exception: |
| 41 | + except Exception: # pylint: disable=broad-exception-caught |
42 | 42 | return "<key-vault-resource-id>" |
43 | 43 |
|
44 | 44 |
|
45 | 45 | def _display_permission_guidance(storage_access_mode, principal_id, subscription_id, resource_group_name, container_uri, keyvault_secret_uri=None): |
46 | 46 | """Display permission guidance for the managed identity.""" |
47 | | - |
48 | | - |
49 | 47 | if storage_access_mode == 'ManagedIdentity': |
50 | 48 | storage_resource_id = _extract_storage_account_resource_id(subscription_id, resource_group_name, container_uri) |
51 | 49 | role = "Storage Blob Data Contributor" |
52 | 50 |
|
53 | 51 | logger.warning("") |
54 | | - logger.warning(f"Please ensure that the Managed Identity of the pipeline (Object ID: {principal_id}) has the necessary permissions to access the Storage Account Blob Container.") |
| 52 | + logger.warning("Please ensure that the Managed Identity of the pipeline (Object ID: %s) has the necessary permissions to access the Storage Account Blob Container.", principal_id) |
55 | 53 | logger.warning("Please run:") |
56 | | - logger.warning(f" az role assignment create --assignee \"{principal_id}\" --role \"{role}\" --scope \"{storage_resource_id}\"") |
| 54 | + logger.warning(" az role assignment create --assignee \"%s\" --role \"%s\" --scope \"%s\"", principal_id, role, storage_resource_id) |
57 | 55 | logger.warning("Note: If the Storage Account is in a different resource group, update the --scope parameter accordingly.") |
58 | 56 | logger.warning("") |
59 | 57 | elif storage_access_mode == 'SasToken' and keyvault_secret_uri: |
60 | 58 | keyvault_resource_id = _extract_keyvault_resource_id(subscription_id, resource_group_name, keyvault_secret_uri) |
61 | 59 | role = "Key Vault Secrets User" |
62 | 60 |
|
63 | 61 | logger.warning("") |
64 | | - logger.warning(f"Please ensure that the Managed Identity of the pipeline (Object ID: {principal_id}) has the necessary permissions to access the Key Vault Secret containing the Storage Account SAS Key.") |
| 62 | + logger.warning("Please ensure that the Managed Identity of the pipeline (Object ID: %s) has the necessary permissions to access the Key Vault Secret containing the Storage Account SAS Key.", principal_id) |
65 | 63 | logger.warning("Please run:") |
66 | | - logger.warning(f" az role assignment create --assignee \"{principal_id}\" --role \"{role}\" --scope \"{keyvault_resource_id}\"") |
| 64 | + logger.warning(" az role assignment create --assignee \"%s\" --role \"%s\" --scope \"%s\"", principal_id, role, keyvault_resource_id) |
67 | 65 | logger.warning("Note: If the Key Vault is in a different resource group, update the --scope parameter accordingly.") |
68 | 66 | logger.warning("") |
69 | 67 |
|
|
0 commit comments