BlobStorage.Advanced.CallSasSamples C# (CSharp) Method

CallSasSamples() private static method

Calls shared access signature samples for both containers and blobs.
private static CallSasSamples ( Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container ) : System.Threading.Tasks.Task
container Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer A CloudBlobContainer object.
return System.Threading.Tasks.Task
        private static async Task CallSasSamples(CloudBlobContainer container)
        {
            const string BlobName1 = "sasBlob1.txt";
            const string BlobContent1 = "Blob created with an ad-hoc SAS granting write permissions on the container.";

            const string BlobName2 = "sasBlob2.txt";
            const string BlobContent2 = "Blob created with a SAS based on a stored access policy granting write permissions on the container.";

            const string BlobName3 = "sasBlob3.txt";
            const string BlobContent3 = "Blob created with an ad-hoc SAS granting create/write permissions to the blob.";

            const string BlobName4 = "sasBlob4.txt";
            const string BlobContent4 = "Blob created with a SAS based on a stored access policy granting create/write permissions to the blob.";

            string sharedAccessPolicyName = "sample-policy-" + DateTime.Now.Ticks.ToString();

            // Create the container if it does not already exist.
            await container.CreateIfNotExistsAsync();

            // Create a new shared access policy on the container.
            // The access policy may be optionally used to provide constraints for
            // shared access signatures on the container and the blob.
            await CreateSharedAccessPolicyAsync(container, sharedAccessPolicyName);

            // Generate an ad-hoc SAS URI for the container with write and list permissions.
            string adHocContainerSAS = GetContainerSasUri(container);

            // Test the SAS. The write and list operations should succeed, and 
            // the read and delete operations should fail with error code 403 (Forbidden).
            await TestContainerSASAsync(adHocContainerSAS, BlobName1, BlobContent1);

            // Generate a SAS URI for the container, using the stored access policy to set constraints on the SAS.
            string sharedPolicyContainerSAS = GetContainerSasUri(container, sharedAccessPolicyName);

            // Test the SAS. The write, read, list, and delete operations should all succeed.
            await TestContainerSASAsync(sharedPolicyContainerSAS, BlobName2, BlobContent2);

            // Generate an ad-hoc SAS URI for a blob within the container. The ad-hoc SAS has create, write, and read permissions.
            string adHocBlobSAS = GetBlobSasUri(container, BlobName3, null);
            
            // Test the SAS. The create, write, and read operations should succeed, and 
            // the delete operation should fail with error code 403 (Forbidden).
            await TestBlobSASAsync(adHocBlobSAS, BlobContent3);

            // Generate a SAS URI for a blob within the container, using the stored access policy to set constraints on the SAS.
            string sharedPolicyBlobSAS = GetBlobSasUri(container, BlobName4, sharedAccessPolicyName);
            
            // Test the SAS. The create, write, read, and delete operations should all succeed.
            await TestBlobSASAsync(sharedPolicyBlobSAS, BlobContent4);
        }