/// <summary> /// Validate the table access policy /// </summary> /// <param name="policy">SharedAccessBlobPolicy object</param> /// <param name="policyIdentifier">The policy identifier which need to be checked.</param> internal static bool ValidateTableAccessPolicy(IStorageTableManagement channel, string tableName, SharedAccessTablePolicy policy, string policyIdentifier) { if (string.IsNullOrEmpty(policyIdentifier)) { return(true); } CloudTable table = channel.GetTableReference(tableName); TableRequestOptions options = null; OperationContext context = null; TablePermissions permission = channel.GetTablePermissions(table, options, context); SharedAccessTablePolicy sharedAccessPolicy = GetExistingPolicy <SharedAccessTablePolicy>(permission.SharedAccessPolicies, policyIdentifier); if (policy.Permissions != SharedAccessTablePermissions.None) { throw new ArgumentException(Resources.SignedPermissionsMustBeOmitted); } if (policy.SharedAccessExpiryTime.HasValue && sharedAccessPolicy.SharedAccessExpiryTime.HasValue) { throw new ArgumentException(Resources.SignedExpiryTimeMustBeOmitted); } return(!sharedAccessPolicy.SharedAccessExpiryTime.HasValue); }
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); }
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 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); //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); return policyName; }
internal bool RemoveAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName) { bool success = false; string result = string.Empty; //Get existing permissions CloudTable table = localChannel.GetTableReference(tableName); TablePermissions tablePermissions = localChannel.GetTablePermissions(table); //remove the specified policy if (!tablePermissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName)); } if (this.Force || ConfirmRemove(policyName)) { tablePermissions.SharedAccessPolicies.Remove(policyName); localChannel.SetTablePermissions(table, tablePermissions); success = true; } return(success); }
internal bool RemoveAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName) { bool success = false; string result = string.Empty; //Get existing permissions CloudTable table = localChannel.GetTableReference(tableName); TablePermissions tablePermissions = localChannel.GetTablePermissions(table); //remove the specified policy if (!tablePermissions.SharedAccessPolicies.Keys.Contains(policyName)) { throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName)); } if (this.Force || ConfirmRemove(policyName)) { tablePermissions.SharedAccessPolicies.Remove(policyName); localChannel.SetTablePermissions(table, tablePermissions); success = true; } return success; }
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; }