My company Kakadu uses Python + Django + Azure as the development environment.
I think that many companies use AWS as a cloud environment, but Azure also provides Python library as an SDK. I like it because it's easy to use.
The other day, I started using Azure storage, a function equivalent to S3 in AWS, and started serving static files from Azure storage, but I set Azure CORS (Cross Origin Resource Sharing) in Python. I didn't have any material on the net about how to do it, so I'll keep a record of how I responded.
from azure.storage.models import StorageServiceProperties
from azure.storage.blob import BlobService
from azure.storage.blob.models import WindowsAzureData
class Cors(WindowsAzureData):
pass
class CorsRule(WindowsAzureData):
pass
rule = CorsRule()
rule.allowed_origins = '*'
rule.allowed_methods = 'GET,PUT'
rule.max_age_in_seconds = 500
rule.exposed_headers = 'x-ms-meta-data*,x-ms-meta-customheader'
rule.allowed_headers = 'x-ms-meta-data*,x-ms-meta-customheader'
cors = Cors()
cors.corsrule = rule
prop = StorageServiceProperties()
prop.cors = cors
prop.default_service_version = '2013-08-15'
client = BlobService(
account_name='account name',
account_key='Key'
)
client.set_blob_service_properties(prop)
This is a workaround that I came up with while reading the SDK implementation, but if anyone knows how to make it easier, I would appreciate it if you could comment!
Recommended Posts