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); }
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); }
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); }
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); }
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); }
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; 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 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); }
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); }
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); }