Добавьте электронную почту в качестве участника Azure Blob с помощью Python SDK ⇐ Python

Программы на Python
Anonymous
Добавьте электронную почту в качестве участника Azure Blob с помощью Python SDK

Сообщение Anonymous »

У меня есть идентификатор электронной почты от пользователя, и я хотел бы предоставить ему роль участника контейнера BLOB-объектов Azure с помощью Python SDK. Я пробовал использовать этот метод, но, похоже, DefaultAzureCredientials не работает.
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient

# Set your Azure subscription ID, resource group name, storage account name, and container name
subscription_id = 'your_subscription_id'
resource_group_name = 'your_resource_group_name'
storage_account_name = 'your_storage_account_name'
container_name = 'your_container_name'
email_address = 'user@example.com' # The email address to which you want to grant access

# Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()

# Create clients
resource_client = ResourceManagementClient(credential, subscription_id)
storage_client = StorageManagementClient(credential, subscription_id)

# Get the storage account ID
storage_account = storage_client.storage_accounts.get_properties(resource_group_name, storage_account_name)
storage_account_id = storage_account.id

# Define the role assignment parameters
role_definition_id = "/subscriptions/{}/providers/Microsoft.Authorization/roleDefinitions/{}".format(
subscription_id,
"b2e1d0c4-5f1b-4b6b-a1c1-4a2d5f8f3e56" # Storage Blob Data Contributor role ID
)

# Create the role assignment
role_assignment_name = str(uuid.uuid4()) # Generate a unique GUID for the role assignment
role_assignment_parameters = {
'properties': {
'roleDefinitionId': role_definition_id,
'principalId': email_address # This should be the object ID of the user, not the email
}
}

# Assign the role
role_assignment = resource_client.role_assignments.create(
scope=storage_account_id,
role_assignment_name=role_assignment_name,
parameters=role_assignment_parameters
)

print(f"Role assignment created: {role_assignment.id}")`



Подробнее здесь: https://stackoverflow.com/questions/789 ... python-sdk

Вернуться в «Python»