0
votes

I'm trying to use python 3 in order to set property in Azure : Allow Blob public access I didn't find any information on the net on how to implement this via python, I did find solution via Powershell: https://docs.microsoft.com/en-us/azure/storage/blobs/anonymous-read-access-configure?tabs=powershell

looking for solution for python3...

enter image description here

Thanks!

2

2 Answers

1
votes

Allow Blob public access feature is newly added in the latest python sdk azure-mgmt-storage 16.0.0.

When using this feature, you need to add this line in your code:

from azure.mgmt.storage.v2019_06_01.models import StorageAccountUpdateParameters

Here is an example, it can work at my side:

from azure.identity import ClientSecretCredential
from azure.mgmt.storage import StorageManagementClient
from azure.mgmt.storage.v2019_06_01.models import StorageAccountUpdateParameters

subscription_id = "xxxxxxxx"    

creds = ClientSecretCredential(
    tenant_id="xxxxxxxx",
    client_id="xxxxxxxx",
    client_secret="xxxxxxx"
)

resource_group_name="xxxxx"
storage_account_name="xxxx"

storage_client = StorageManagementClient(creds, subscription_id)

#set the allow_blob_public_access settings here
p1 = StorageAccountUpdateParameters(allow_blob_public_access=False)

#then use update method to update this feature
storage_client.storage_accounts.update(resource_group_name, storage_account_name, p1)
0
votes

I haven't tried this myself, but looking at the Python Storage Management SDK and the REST API this should be possible.

Look here for an example on how to create a new storage account using the Python SDK. As you can see, the request body seems to be pretty much exactly what gets passed on to the underlying REST API.

That API does support the optional parameter properties.allowBlobPublicAccess so you should be able to add that directly in python as well.