internal async Task <SharedAccessTablePolicies> GetPoliciesAsync(IStorageTableManagement localChannel, string tableName, string policyName)
        {
            CloudTable       table            = localChannel.GetTableReference(tableName);
            TablePermissions tablePermissions = await localChannel.GetTablePermissionsAsync(table, null, TableOperationContext).ConfigureAwait(false);

            return(tablePermissions.SharedAccessPolicies);
        }
Example #2
0
        /// <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 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, 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 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;
        }
Example #6
0
        /// <summary>
        /// list azure table clients by query
        /// </summary>
        /// <param name="localChannel"></param>
        /// <param name="query">table query string</param>
        /// <returns></returns>
        internal IEnumerable <AzureStorageTable> ListTablesByQueryV2(IStorageTableManagement localChannel, string query)
        {
            IEnumerable <TableItem> tableItems = localChannel.QueryTables(query, this.CmdletCancellationToken);

            foreach (TableItem tableItem in tableItems)
            {
                yield return(localChannel.GetAzureStorageTable(tableItem.Name));
            }
        }
Example #7
0
        /// <summary>
        /// list azure table clients by prefix using track2 sdk
        /// </summary>
        /// <param name="prefix">table prefix</param>
        /// <returns></returns>
        internal IEnumerable <AzureStorageTable> ListTablesByPrefixV2(IStorageTableManagement localChannel, string prefix)
        {
            if (!NameUtil.IsValidTablePrefix(prefix))
            {
                throw new ArgumentException(String.Format(Resources.InvalidTableName, prefix));
            }

            // append '{' as upper bound as it is the first ASCII char after the largest legal table name character
            string query = $"TableName ge '{prefix}' and TableName lt '{prefix}{{'";

            return(this.ListTablesByQueryV2(localChannel, query));
        }
Example #8
0
        /// <summary>
        /// create an azure table
        /// </summary>
        /// <param name="localChannel"></param>
        /// <param name="tableName"></param>
        internal AzureStorageTable CreateAzureTableV2(IStorageTableManagement localChannel, string tableName)
        {
            if (!NameUtil.IsValidTableName(tableName))
            {
                throw new ArgumentException(String.Format(Resources.InvalidTableName, tableName));
            }

            if (!localChannel.CreateTableIfNotExists(tableName, this.CmdletCancellationToken))
            {
                throw new ResourceAlreadyExistException(String.Format(Resources.TableAlreadyExists, tableName));
            }

            return(localChannel.GetAzureStorageTable(tableName));
        }
Example #9
0
        /// <summary>
        /// list azure table clients by full name or simple regular expression
        /// </summary>
        /// <param name="tableName">table name or simple regular expression</param>
        /// <returns></returns>
        internal IEnumerable <AzureStorageTable> ListTablesByNameV2(IStorageTableManagement localChannel, string tableName)
        {
            if (String.IsNullOrEmpty(tableName) || WildcardPattern.ContainsWildcardCharacters(tableName))
            {
                WildcardPattern wildcard = null;
                if (!string.IsNullOrEmpty(tableName))
                {
                    wildcard = new WildcardPattern(tableName, WildcardOptions.IgnoreCase | WildcardOptions.Compiled);
                }

                foreach (AzureStorageTable table in this.ListTablesByQueryV2(localChannel, query: null))
                {
                    if (wildcard == null || wildcard.IsMatch(table.Name))
                    {
                        yield return(table);
                    }
                }
            }
            else
            {
                if (!NameUtil.IsValidTableName(tableName))
                {
                    throw new ArgumentException(String.Format(Resources.InvalidTableName, tableName));
                }

                string query = $"TableName eq '{tableName}'";
                List <AzureStorageTable> tables = this.ListTablesByQueryV2(localChannel, query).ToList();
                if (tables.Count == 0)
                {
                    throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, tableName));
                }

                foreach (AzureStorageTable table in tables)
                {
                    yield return(table);
                }
            }
        }
        internal async Task GetAzureTableStoredAccessPolicyAsync(long taskId, IStorageTableManagement localChannel, string tableName, string policyName)
        {
            SharedAccessTablePolicies shareAccessPolicies = await GetPoliciesAsync(localChannel, tableName, policyName).ConfigureAwait(false);

            if (!String.IsNullOrEmpty(policyName))
            {
                if (shareAccessPolicies.Keys.Contains(policyName))
                {
                    OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessTablePolicy>(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 <SharedAccessTablePolicy>(shareAccessPolicies, key));
                }
            }
        }
        internal async Task GetAzureTableStoredAccessPolicyAsync(long taskId, IStorageTableManagement localChannel, string tableName, string policyName)
        {
            SharedAccessTablePolicies shareAccessPolicies = await GetPoliciesAsync(localChannel, tableName, policyName);

            if (!String.IsNullOrEmpty(policyName))
            {
                if (shareAccessPolicies.Keys.Contains(policyName))
                {
                    OutputStream.WriteObject(taskId, AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessTablePolicy>(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<SharedAccessTablePolicy>(shareAccessPolicies, key));
                }
            }
        }
        /// <summary>
        /// remove azure table
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="tableName">table name</param>
        /// <returns>
        /// true if the table is removed, false if user has cancelled the operation,
        /// otherwise throw an exception</returns>
        internal bool RemoveAzureTableV2(IStorageTableManagement localChannel, string tableName)
        {
            if (!NameUtil.IsValidTableName(tableName))
            {
                throw new ArgumentException(String.Format(Resources.InvalidTableName, tableName));
            }

            // check whether table exists
            bool   exists = false;
            string query  = $"TableName eq '{tableName}'";
            IEnumerable <TableItem> tableItems = localChannel.QueryTables(query, this.CmdletCancellationToken);

            foreach (TableItem tableItem in tableItems)
            {
                exists = true;
                break;
            }

            if (!exists)
            {
                throw new ResourceNotFoundException(String.Format(Resources.TableNotFound, tableName));
            }

            // delete accordingly
            if (force ||
                this.IsTableEmpty(localChannel, tableName, this.CmdletCancellationToken) ||
                ShouldContinue(string.Format("Remove table and all content in it: {0}", tableName), ""))
            {
                localChannel.DeleteTable(tableName, this.CmdletCancellationToken);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        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;
        }
Example #16
0
 public FakeRemoveAzureTableCommand(IStorageTableManagement channel)
 {
     Channel = channel;
 }
 /// <summary>
 /// Initializes a new instance of the GetAzureStorageTableStoredAccessPolicyCommand class.
 /// </summary>
 /// <param name="channel">IStorageTableManagement channel</param>
 public GetAzureStorageTableStoredAccessPolicyCommand(IStorageTableManagement channel)
 {
     Channel = channel;
 }
 /// <summary>
 /// Initializes a new instance of the NewAzureStorageTableStoredAccessPolicyCommand class.
 /// </summary>
 /// <param name="channel">IStorageTableManagement channel</param>
 public NewAzureStorageTableStoredAccessPolicyCommand(IStorageTableManagement channel)
 {
     Channel           = channel;
     EnableMultiThread = false;
 }
 /// <summary>
 /// Initializes a new instance of the GetAzureStorageTableCommand class.
 /// </summary>
 /// <param name="channel">IStorageTableManagement channel</param>
 public GetAzureStorageTableCommand(IStorageTableManagement channel)
 {
     Channel = channel;
     EnableMultiThread = false;
 }
 /// <summary>
 /// Initializes a new instance of the NewAzureStorageTableSasCommand class.
 /// </summary>
 /// <param name="channel">IStorageBlobManagement channel</param>
 public NewAzureStorageTableSasTokenCommand(IStorageTableManagement channel)
 {
     Channel = channel;
 }
 public FakeRemoveAzureTableCommand(IStorageTableManagement channel)
 {
     Channel = channel;
 }
 /// <summary>
 /// Initializes a new instance of the GetAzureStorageTableCommand class.
 /// </summary>
 /// <param name="channel">IStorageTableManagement channel</param>
 public GetAzureStorageTableCommand(IStorageTableManagement channel)
 {
     Channel = channel;
 }
 internal async Task<SharedAccessTablePolicies> GetPoliciesAsync(IStorageTableManagement localChannel, string tableName, string policyName)
 {
     CloudTable table = localChannel.GetTableReference(tableName);
     TablePermissions tablePermissions = await localChannel.GetTablePermissionsAsync(table);
     return tablePermissions.SharedAccessPolicies;
 }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the NewAzureStorageTableSasCommand class.
 /// </summary>
 /// <param name="channel">IStorageBlobManagement channel</param>
 public NewAzureStorageTableSasTokenCommand(IStorageTableManagement channel)
 {
     Channel = channel;
 }
 /// <summary>
 /// Initializes a new instance of the NewAzureStorageTableSasCommand class.
 /// </summary>
 /// <param name="channel">IStorageBlobManagement channel</param>
 public NewAzureStorageTableSasTokenCommand(IStorageTableManagement channel)
 {
     Channel           = channel;
     EnableMultiThread = false;
 }
 /// <summary>
 /// Initializes a new instance of the GetAzureStorageTableStoredAccessPolicyCommand class.
 /// </summary>
 /// <param name="channel">IStorageTableManagement channel</param>
 public GetAzureStorageTableStoredAccessPolicyCommand(IStorageTableManagement channel)
 {
     Channel = channel;
 }
 /// <summary>
 /// Initializes a new instance of the NewAzureStorageTableSasCommand class.
 /// </summary>
 /// <param name="channel">IStorageBlobManagement channel</param>
 public NewAzureStorageTableSasTokenCommand(IStorageTableManagement channel)
 {
     Channel = channel;
     EnableMultiThread = false;
 }
 /// <summary>
 /// Initializes a new instance of the RemoveAzureStorageTableStoredAccessPolicyCommand class.
 /// </summary>
 /// <param name="channel">IStorageTableManagement channel</param>
 public RemoveAzureStorageTableStoredAccessPolicyCommand(IStorageTableManagement channel)
 {
     Channel = channel;
     EnableMultiThread = false;
 }
 /// <summary>
 /// Initializes a new instance of the GetAzureStorageTableCommand class.
 /// </summary>
 /// <param name="channel">IStorageTableManagement channel</param>
 public GetAzureStorageTableCommand(IStorageTableManagement channel)
 {
     Channel           = channel;
     EnableMultiThread = false;
 }
Example #30
0
 /// <summary>
 /// Initializes a new instance of the GetAzureStorageTableCommand class.
 /// </summary>
 /// <param name="channel">IStorageTableManagement channel</param>
 public GetAzureStorageTableCommand(IStorageTableManagement channel)
 {
     Channel = channel;
 }