internal string CreateAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission)
        {
            if (!NameUtil.IsValidStoredAccessPolicyName(policyName))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName));
            }

            //Get existing permissions
            CloudTable       table            = localChannel.GetTableReference(tableName);
            TablePermissions tablePermissions = localChannel.GetTablePermissions(table, null, TableOperationContext);

            //Add new policy
            if (tablePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName));
            }

            SharedAccessTablePolicy policy = new SharedAccessTablePolicy();

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessTablePolicy>(policy, startTime, expiryTime, permission);
            tablePermissions.SharedAccessPolicies.Add(policyName, policy);

            //Set permissions back to table
            localChannel.SetTablePermissions(table, tablePermissions, null, TableOperationContext);
            return(policyName);
        }
예제 #2
0
        internal async Task GetAzureContainerStoredAccessPolicyAsync(long taskId, IStorageBlobManagement localChannel, string containerName, string policyName)
        {
            //Get container instance, Get existing permissions
            CloudBlobContainer                 container_Track1  = Channel.GetContainerReference(containerName);
            BlobContainerClient                container         = AzureStorageContainer.GetTrack2BlobContainerClient(container_Track1, Channel.StorageContext, ClientOptions);
            BlobContainerAccessPolicy          accessPolicy      = (await container.GetAccessPolicyAsync(BlobRequestConditions, cancellationToken: CmdletCancellationToken).ConfigureAwait(false)).Value;
            IEnumerable <BlobSignedIdentifier> signedIdentifiers = accessPolicy.SignedIdentifiers;

            if (!String.IsNullOrEmpty(policyName))
            {
                BlobSignedIdentifier signedIdentifier = null;
                foreach (BlobSignedIdentifier identifier in signedIdentifiers)
                {
                    if (identifier.Id == policyName)
                    {
                        signedIdentifier = identifier;
                    }
                }
                if (signedIdentifier == null)
                {
                    throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
                }
                else
                {
                    OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject <BlobSignedIdentifier>(signedIdentifier));
                }
            }
            else
            {
                foreach (BlobSignedIdentifier identifier in signedIdentifiers)
                {
                    OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject <BlobSignedIdentifier>(identifier));
                }
            }
        }
        internal string SetAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            DateTime?startTimeToSet  = startTime;
            DateTime?expiryTimetoSet = expiryTime;

            //Get existing permissions
            CloudTable       table            = localChannel.GetTableReference(Table);
            TablePermissions tablePermissions = localChannel.GetTablePermissions(table);

            //Set the policy with new value
            if (!tablePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            SharedAccessTablePolicy policy = tablePermissions.SharedAccessPolicies[policyName];

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessTablePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
            tablePermissions.SharedAccessPolicies[policyName] = policy;

            //Set permission back to table
            localChannel.SetTablePermissions(table, tablePermissions);
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessTablePolicy>(tablePermissions.SharedAccessPolicies, policyName));
            return(policyName);
        }
        public void SetupAccessPolicyTest()
        {
            DateTime?start = DateTime.Now;
            DateTime?end   = start.Value.AddHours(1.0);

            SharedAccessBlobPolicy blobAccessPolicy = new SharedAccessBlobPolicy();

            AccessPolicyHelper.SetupAccessPolicy(blobAccessPolicy, start, end, "a");
            Assert.AreEqual(blobAccessPolicy.SharedAccessStartTime.Value.UtcDateTime.ToString(), start.Value.ToUniversalTime().ToString());
            Assert.AreEqual(blobAccessPolicy.SharedAccessExpiryTime.Value.UtcDateTime.ToString(), end.Value.ToUniversalTime().ToString());
            Assert.AreEqual(blobAccessPolicy.Permissions, SharedAccessBlobPermissions.Add);

            SharedAccessTablePolicy tableAccessPolicy = new SharedAccessTablePolicy();

            AccessPolicyHelper.SetupAccessPolicy(tableAccessPolicy, null, end, "d", true);
            Assert.AreEqual(tableAccessPolicy.SharedAccessStartTime, null);
            Assert.AreEqual(tableAccessPolicy.SharedAccessExpiryTime.Value.UtcDateTime.ToString(), end.Value.ToUniversalTime().ToString());
            Assert.AreEqual(tableAccessPolicy.Permissions, SharedAccessTablePermissions.Delete);

            SharedAccessQueuePolicy queueAccessPolicy = new SharedAccessQueuePolicy();

            AccessPolicyHelper.SetupAccessPolicy(queueAccessPolicy, start, null, "", noExpiryTime: true);
            Assert.AreEqual(queueAccessPolicy.SharedAccessStartTime.Value.UtcDateTime.ToString(), start.Value.ToUniversalTime().ToString());
            Assert.AreEqual(queueAccessPolicy.SharedAccessExpiryTime, null);
            Assert.AreEqual(queueAccessPolicy.Permissions, SharedAccessQueuePermissions.None);

            SharedAccessFilePolicy fileAccessPolicy = new SharedAccessFilePolicy();

            AccessPolicyHelper.SetupAccessPolicy(fileAccessPolicy, null, null, "dl", true, true);
            Assert.AreEqual(fileAccessPolicy.SharedAccessStartTime, null);
            Assert.AreEqual(fileAccessPolicy.SharedAccessExpiryTime, null);
            Assert.AreEqual(fileAccessPolicy.Permissions, SharedAccessFilePermissions.List | SharedAccessFilePermissions.Delete);
        }
예제 #5
0
        internal string CreateAzureQueueStoredAccessPolicy(IStorageQueueManagement localChannel, string queueName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission)
        {
            if (!NameUtil.IsValidStoredAccessPolicyName(policyName))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName));
            }

            //Get existing permissions
            CloudQueue       queue            = Channel.GetQueueReference(queueName);
            QueuePermissions queuePermissions = localChannel.GetPermissions(queue);

            //Add new policy
            if (queuePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName));
            }

            SharedAccessQueuePolicy policy = new SharedAccessQueuePolicy();

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessQueuePolicy>(policy, startTime, expiryTime, permission);
            queuePermissions.SharedAccessPolicies.Add(policyName, policy);

            //Set permissions back to queue
            localChannel.SetPermissions(queue, queuePermissions);
            return(policyName);
        }
        public override void ExecuteCmdlet()
        {
            if (String.IsNullOrEmpty(ShareName) || String.IsNullOrEmpty(Policy))
            {
                return;
            }

            NamingUtil.ValidateShareName(this.ShareName, false);

            if (!NameUtil.IsValidStoredAccessPolicyName(this.Policy))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, this.Policy));
            }

            //Get existing permissions
            CloudFileShare fileShare = this.Channel.GetShareReference(this.ShareName);

            FileSharePermissions fileSharePermissions = fileShare.GetPermissions();

            //Add new policy
            if (fileSharePermissions.SharedAccessPolicies.Keys.Contains(this.Policy))
            {
                throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, this.Policy));
            }

            SharedAccessFilePolicy policy = new SharedAccessFilePolicy();

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessFilePolicy>(policy, this.StartTime, this.ExpiryTime, this.Permission);
            fileSharePermissions.SharedAccessPolicies.Add(this.Policy, policy);

            //Set permissions back to container
            fileShare.SetPermissions(fileSharePermissions);
            WriteObject(Policy);
        }
예제 #7
0
        internal string CreateAzureContainerStoredAccessPolicy(IStorageBlobManagement localChannel, string containerName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission)
        {
            if (!NameUtil.IsValidStoredAccessPolicyName(policyName))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName));
            }

            //Get existing permissions
            CloudBlobContainer       container = localChannel.GetContainerReference(containerName);
            BlobContainerPermissions blobContainerPermissions = localChannel.GetContainerPermissions(container);

            //Add new policy
            if (blobContainerPermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName));
            }

            SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessBlobPolicy>(policy, startTime, expiryTime, permission);
            blobContainerPermissions.SharedAccessPolicies.Add(policyName, policy);

            //Set permissions back to container
            localChannel.SetContainerPermissions(container, blobContainerPermissions);
            return(policyName);
        }
예제 #8
0
        /// <summary>
        /// Update the access policy
        /// </summary>
        /// <param name="policy">Access policy object</param>
        /// <param name="shouldSetExpiryTime">Should set the default expiry time</param>
        private void SetupAccessPolicy(SharedAccessQueuePolicy policy, bool shouldSetExpiryTime)
        {
            DateTimeOffset?accessStartTime;
            DateTimeOffset?accessEndTime;

            SasTokenHelper.SetupAccessPolicyLifeTime(StartTime, ExpiryTime, out accessStartTime, out accessEndTime, shouldSetExpiryTime);
            policy.SharedAccessStartTime  = accessStartTime;
            policy.SharedAccessExpiryTime = accessEndTime;
            AccessPolicyHelper.SetupAccessPolicyPermission(policy, Permission);
        }
 /// <summary>
 /// Update the access policy
 /// </summary>
 /// <param name="policy">Access policy object</param>
 /// <param name="shouldSetExpiryTime">Should set the default expiry time</param>
 private void SetupAccessPolicy(SharedAccessBlobPolicy accessPolicy, bool shouldSetExpiryTime)
 {
     AccessPolicyHelper.SetupAccessPolicyPermission(accessPolicy, Permission);
     DateTimeOffset? accessStartTime;
     DateTimeOffset? accessEndTime;
     SasTokenHelper.SetupAccessPolicyLifeTime(StartTime, ExpiryTime,
         out accessStartTime, out accessEndTime, shouldSetExpiryTime);
     accessPolicy.SharedAccessStartTime = accessStartTime;
     accessPolicy.SharedAccessExpiryTime = accessEndTime;
 }
        public void SetupAccessPolicyLifeTimeTest()
        {
            DateTime?      start     = DateTime.Now;
            DateTime?      end       = start.Value.AddHours(1.0);
            DateTimeOffset?testStart = null;
            DateTimeOffset?testEnd   = null;

            AccessPolicyHelper.SetupAccessPolicyLifeTime(start, end, out testStart, out testEnd);
            Assert.AreEqual(testStart.Value.UtcDateTime.ToString(), start.Value.ToUniversalTime().ToString());
            Assert.AreEqual(testEnd.Value.UtcDateTime.ToString(), end.Value.ToUniversalTime().ToString());
            AssertThrows <ArgumentException>(() => SasTokenHelper.SetupAccessPolicyLifeTime(end, start, out testStart, out testEnd, true));
        }
        internal string SetAzureContainerStoredAccessPolicy(IStorageBlobManagement localChannel, string containerName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            //Get container instance, Get existing permissions
            CloudBlobContainer                 container_Track1  = Channel.GetContainerReference(containerName);
            BlobContainerClient                container         = AzureStorageContainer.GetTrack2BlobContainerClient(container_Track1, Channel.StorageContext, ClientOptions);
            BlobContainerAccessPolicy          accessPolicy      = container.GetAccessPolicy(cancellationToken: CmdletCancellationToken).Value;
            IEnumerable <BlobSignedIdentifier> signedIdentifiers = accessPolicy.SignedIdentifiers;

            //Set the policy with new value
            BlobSignedIdentifier signedIdentifier = null;

            foreach (BlobSignedIdentifier identifier in signedIdentifiers)
            {
                if (identifier.Id == policyName)
                {
                    signedIdentifier = identifier;
                }
            }

            if (signedIdentifier == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }
            if (noStartTime)
            {
                signedIdentifier.AccessPolicy.PolicyStartsOn = DateTimeOffset.MinValue;
            }

            else if (startTime != null)
            {
                signedIdentifier.AccessPolicy.PolicyStartsOn = StartTime.Value.ToUniversalTime();
            }
            if (noExpiryTime)
            {
                signedIdentifier.AccessPolicy.PolicyExpiresOn = DateTimeOffset.MinValue;
            }
            else if (ExpiryTime != null)
            {
                signedIdentifier.AccessPolicy.PolicyExpiresOn = ExpiryTime.Value.ToUniversalTime();
            }

            if (this.Permission != null)
            {
                signedIdentifier.AccessPolicy.Permissions = this.Permission;
                signedIdentifier.AccessPolicy.Permissions = AccessPolicyHelper.OrderBlobPermission(this.Permission);
            }

            //Set permissions back to container
            container.SetAccessPolicy(accessPolicy.BlobPublicAccess, signedIdentifiers, BlobRequestConditions, CmdletCancellationToken);
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject <BlobSignedIdentifier>(signedIdentifier));
            return(policyName);
        }
        public override void ExecuteCmdlet()
        {
            if (String.IsNullOrEmpty(ShareName) || String.IsNullOrEmpty(Policy))
            {
                return;
            }

            NamingUtil.ValidateShareName(this.ShareName, false);

            if (!NameUtil.IsValidStoredAccessPolicyName(this.Policy))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, this.Policy));
            }

            //Get existing permissions
            CloudFileShare fileShare = this.Channel.GetShareReference(this.ShareName);

            FileSharePermissions fileSharePermissions;

            try
            {
                fileSharePermissions = fileShare.GetPermissionsAsync().Result;
            }
            catch (AggregateException e) when(e.InnerException is StorageException)
            {
                throw e.InnerException;
            }

            //Add new policy
            if (fileSharePermissions.SharedAccessPolicies.Keys.Contains(this.Policy))
            {
                throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, this.Policy));
            }

            SharedAccessFilePolicy policy = new SharedAccessFilePolicy();

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessFilePolicy>(policy, this.StartTime, this.ExpiryTime, this.Permission);
            fileSharePermissions.SharedAccessPolicies.Add(this.Policy, policy);

            //Set permissions back to container
            try
            {
                Task.Run(() => fileShare.SetPermissionsAsync(fileSharePermissions, null, null, OperationContext)).Wait();
            }
            catch (AggregateException e) when(e.InnerException is StorageException)
            {
                throw e.InnerException;
            }

            WriteObject(Policy);
        }
        internal string CreateAzureContainerStoredAccessPolicy(IStorageBlobManagement localChannel, string containerName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission)
        {
            if (!NameUtil.IsValidStoredAccessPolicyName(policyName))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName));
            }

            //Get container instance, Get existing permissions
            CloudBlobContainer                 container_Track1  = Channel.GetContainerReference(containerName);
            BlobContainerClient                container         = AzureStorageContainer.GetTrack2BlobContainerClient(container_Track1, Channel.StorageContext, ClientOptions);
            BlobContainerAccessPolicy          accessPolicy      = container.GetAccessPolicy(cancellationToken: CmdletCancellationToken).Value;
            IEnumerable <BlobSignedIdentifier> signedIdentifiers = accessPolicy.SignedIdentifiers;

            //Add new policy
            foreach (BlobSignedIdentifier identifier in signedIdentifiers)
            {
                if (identifier.Id == policyName)
                {
                    throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName));
                }
            }
            BlobSignedIdentifier signedIdentifier = new BlobSignedIdentifier();

            signedIdentifier.Id           = policyName;
            signedIdentifier.AccessPolicy = new BlobAccessPolicy();
            if (StartTime != null)
            {
                signedIdentifier.AccessPolicy.PolicyStartsOn = StartTime.Value.ToUniversalTime();
            }
            if (ExpiryTime != null)
            {
                signedIdentifier.AccessPolicy.PolicyExpiresOn = ExpiryTime.Value.ToUniversalTime();
            }
            signedIdentifier.AccessPolicy.Permissions = AccessPolicyHelper.OrderBlobPermission(this.Permission);
            var newsignedIdentifiers = new List <BlobSignedIdentifier>(signedIdentifiers);

            newsignedIdentifiers.Add(signedIdentifier);

            //Set permissions back to container
            container.SetAccessPolicy(accessPolicy.BlobPublicAccess, newsignedIdentifiers, BlobRequestConditions, CmdletCancellationToken);
            return(policyName);
        }
        internal string SetAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            //Get existing permissions
            CloudFileShare       share       = localChannel.GetShareReference(shareName);
            FileSharePermissions permissions = localChannel.GetSharePermissions(share);

            //Set the policy with new value
            if (!permissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            SharedAccessFilePolicy policy = permissions.SharedAccessPolicies[policyName];

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessFilePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
            permissions.SharedAccessPolicies[policyName] = policy;

            //Set permission back to share
            localChannel.SetSharePermissions(share, permissions, null, null, OperationContext);
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessFilePolicy>(permissions.SharedAccessPolicies, policyName));
            return(policyName);
        }
        internal string SetAzureQueueStoredAccessPolicy(IStorageQueueManagement localChannel, string queueName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            //Get existing permissions
            CloudQueue       queue            = Channel.GetQueueReference(queueName);
            QueuePermissions queuePermissions = localChannel.GetPermissions(queue);

            //Set the policy with new value
            if (!queuePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            SharedAccessQueuePolicy policy = queuePermissions.SharedAccessPolicies[policyName];

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessQueuePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
            queuePermissions.SharedAccessPolicies[policyName] = policy;

            //Set permission back to queue
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessQueuePolicy>(queuePermissions.SharedAccessPolicies, policyName));
            localChannel.SetPermissions(queue, queuePermissions);
            return(policyName);
        }
예제 #16
0
        internal string SetAzureContainerStoredAccessPolicy(IStorageBlobManagement localChannel, string containerName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            //Get existing permissions
            CloudBlobContainer       container = localChannel.GetContainerReference(containerName);
            BlobContainerPermissions blobContainerPermissions = localChannel.GetContainerPermissions(container);

            //Set the policy with new value
            if (!blobContainerPermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            SharedAccessBlobPolicy policy = blobContainerPermissions.SharedAccessPolicies[policyName];

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessBlobPolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
            blobContainerPermissions.SharedAccessPolicies[policyName] = policy;

            //Set permission back to container
            localChannel.SetContainerPermissions(container, blobContainerPermissions);
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessBlobPolicy>(blobContainerPermissions.SharedAccessPolicies, policyName));
            return(policyName);
        }
        public void ValidateSetupAccessPolicyPermissionTest()
        {
            SharedAccessBlobPolicy blobAccessPolicy = new SharedAccessBlobPolicy();

            AccessPolicyHelper.SetupAccessPolicyPermission(blobAccessPolicy, null);
            Assert.AreEqual(blobAccessPolicy.Permissions, SharedAccessBlobPermissions.None);
            AccessPolicyHelper.SetupAccessPolicyPermission(blobAccessPolicy, "");
            Assert.AreEqual(blobAccessPolicy.Permissions, SharedAccessBlobPermissions.None);
            AccessPolicyHelper.SetupAccessPolicyPermission(blobAccessPolicy, "D");
            Assert.AreEqual(blobAccessPolicy.Permissions, SharedAccessBlobPermissions.Delete);

            SharedAccessTablePolicy tableAccessPolicy = new SharedAccessTablePolicy();

            AccessPolicyHelper.SetupAccessPolicyPermission(tableAccessPolicy, null);
            Assert.AreEqual(tableAccessPolicy.Permissions, SharedAccessTablePermissions.None);
            AccessPolicyHelper.SetupAccessPolicyPermission(tableAccessPolicy, "");
            Assert.AreEqual(tableAccessPolicy.Permissions, SharedAccessTablePermissions.None);
            AccessPolicyHelper.SetupAccessPolicyPermission(tableAccessPolicy, "ar");
            Assert.AreEqual(tableAccessPolicy.Permissions, SharedAccessTablePermissions.Add | SharedAccessTablePermissions.Query);

            SharedAccessQueuePolicy queueAccessPolicy = new SharedAccessQueuePolicy();

            AccessPolicyHelper.SetupAccessPolicyPermission(queueAccessPolicy, null);
            Assert.AreEqual(queueAccessPolicy.Permissions, SharedAccessQueuePermissions.None);
            AccessPolicyHelper.SetupAccessPolicyPermission(queueAccessPolicy, "");
            Assert.AreEqual(queueAccessPolicy.Permissions, SharedAccessQueuePermissions.None);
            AccessPolicyHelper.SetupAccessPolicyPermission(queueAccessPolicy, "p");
            Assert.AreEqual(queueAccessPolicy.Permissions, SharedAccessQueuePermissions.ProcessMessages);

            SharedAccessFilePolicy fileAccessPolicy = new SharedAccessFilePolicy();

            AccessPolicyHelper.SetupAccessPolicyPermission(fileAccessPolicy, null);
            Assert.AreEqual(fileAccessPolicy.Permissions, SharedAccessFilePermissions.None);
            AccessPolicyHelper.SetupAccessPolicyPermission(fileAccessPolicy, "");
            Assert.AreEqual(fileAccessPolicy.Permissions, SharedAccessFilePermissions.None);
            AccessPolicyHelper.SetupAccessPolicyPermission(fileAccessPolicy, "lwc");
            Assert.AreEqual(fileAccessPolicy.Permissions, SharedAccessFilePermissions.List | SharedAccessFilePermissions.Write | SharedAccessFilePermissions.Create);
        }
        internal async Task GetAzureContainerStoredAccessPolicyAsync(long taskId, IStorageBlobManagement localChannel, string containerName, string policyName)
        {
            SharedAccessBlobPolicies shareAccessPolicies = await GetPoliciesAsync(localChannel, containerName, policyName).ConfigureAwait(false);

            if (!String.IsNullOrEmpty(policyName))
            {
                if (shareAccessPolicies.Keys.Contains(policyName))
                {
                    OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessBlobPolicy>(shareAccessPolicies, policyName));
                }
                else
                {
                    throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
                }
            }
            else
            {
                foreach (string key in shareAccessPolicies.Keys)
                {
                    OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessBlobPolicy>(shareAccessPolicies, key));
                }
            }
        }