Created
June 22, 2015 16:47
-
-
Save justinribeiro/66b4e19e462ace4f0fd9 to your computer and use it in GitHub Desktop.
setCors - simple command line program to set CORS header properties on Azure BLOB store.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.WindowsAzure.Storage; | |
using Microsoft.WindowsAzure.Storage.Auth; | |
using Microsoft.WindowsAzure.Storage.Shared.Protocol; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace setCors | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
StorageCredentials storageCredentials = new StorageCredentials(args[0], args[1]); | |
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); | |
var blobClient = storageAccount.CreateCloudBlobClient(); | |
// Define our basics for quick op | |
ServiceProperties blobServiceProperties = new ServiceProperties() | |
{ | |
HourMetrics = null, | |
MinuteMetrics = null, | |
Logging = null, | |
}; | |
// Define our CORS rules (wide open here) | |
CorsRule corsRule = new CorsRule() | |
{ | |
AllowedHeaders = new List<string>() { "*" }, | |
AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Post | CorsHttpMethods.Head | CorsHttpMethods.Put, | |
AllowedOrigins = new List<string>() { "*" }, | |
ExposedHeaders = new List<string>() { "*", "Accept-Ranges", "Content-Range"}, | |
MaxAgeInSeconds = 3600 // 30 minutes | |
}; | |
// Set our rule | |
blobServiceProperties.Cors.CorsRules.Add(corsRule); | |
try | |
{ | |
blobClient.SetServiceProperties(blobServiceProperties); | |
Console.Out.WriteLine("CORS is rollin' for " + args[0]); | |
} | |
catch (Exception e) | |
{ | |
Console.Out.WriteLine(e.ToString()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment