Simple ScriptCS scripts to manage Azure storage account's CORS headers. Created in frustration as there are no readymade methods in the Azure SDK.
Many CORS headers that this script sets are hard coded; change setCors.csx to suit your needs.
Methods:
scriptcs dumpServiceProperties.csx -- [storageAccount] [storageAccountKey]
Verbs are fixed in this version, change them directly in the script.
scriptcs addCors.csx -- [storageAccount] [storageAccountKey] [origins]
An example
scriptcs addCors.csx -- myaccount mylongkey http://app.foo.bar,http://app.fu.bar
scriptcs addCors.csx -- myaccount mylongkey *
Note, that unfortunately CORS standard does not support star subdomains like http://*.foo.bar
scriptcs clearCors.csx -- [storageAccount] [storageAccountKey]
You can inspect CORS properties with curl:
curl -H "Origin: http://app.foo.bar" -H "Access-Control-Request-Method: GET" -H "Access-Control-Request-Headers: X-Requested-With" -X OPTIONS --verbose http://mystorageaccount.blob.core.windows.net/mycontainer/myblob.txt
Inspired by Bill Wilder's blogpost