예제 #1
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, XTable.SharedAccessTablePolicy policy, string policyIdentifier)
        {
            if (string.IsNullOrEmpty(policyIdentifier))
            {
                return(true);
            }
            XTable.CloudTable          table      = channel.GetTableReference(tableName);
            XTable.TableRequestOptions options    = null;
            XTable.OperationContext    context    = null;
            XTable.TablePermissions    permission = channel.GetTablePermissions(table, options, context);

            XTable.SharedAccessTablePolicy sharedAccessPolicy =
                GetExistingPolicy <XTable.SharedAccessTablePolicy>(permission.SharedAccessPolicies, policyIdentifier);

            if (policy.Permissions != XTable.SharedAccessTablePermissions.None)
            {
                throw new ArgumentException(Resources.SignedPermissionsMustBeOmitted);
            }

            if (policy.SharedAccessExpiryTime.HasValue && sharedAccessPolicy.SharedAccessExpiryTime.HasValue)
            {
                throw new ArgumentException(Resources.SignedExpiryTimeMustBeOmitted);
            }

            return(!sharedAccessPolicy.SharedAccessExpiryTime.HasValue);
        }
예제 #2
0
        static void Main(string[] args)
        {
            /* Legacy Table SDK */
            var storageAccountLegacy = LEGACY_STORAGE.CloudStorageAccount.Parse(connectionTableSAS);
            var tableClientLegacy    = storageAccountLegacy.CreateCloudTableClient();

            Debug.Assert(tableClientLegacy.StorageUri.SecondaryUri != null); // demonstrate SecondaryUri initialised

            var tableRequestOptionsLegacy = new LEGACY_TABLE.TableRequestOptions()
            {
                LocationMode = LEGACY_RETRY.LocationMode.SecondaryOnly
            };

            tableClientLegacy.DefaultRequestOptions = tableRequestOptionsLegacy;

            var tableLegacy       = tableClientLegacy.GetTableReference("foo"); // don't need table to exist to show the issue
            var retrieveOperation = LEGACY_TABLE.TableOperation.Retrieve(string.Empty, string.Empty, new List <string>()
            {
                "bar"
            });

            var tableResult = tableLegacy.Execute(retrieveOperation);

            Console.WriteLine("Legacy PASS");


            /* Newset Table SDK */
            var storageAccountNewest = NEWEST_TABLE.CloudStorageAccount.Parse(connectionTableSAS);
            var tableClientNewest    = storageAccountNewest.CreateCloudTableClient(new TableClientConfiguration());

            Debug.Assert(tableClientNewest.StorageUri.SecondaryUri != null); // demonstrate SecondaryUri initialised

            var tableRequestOptionsNewest = new NEWEST_TABLE.TableRequestOptions()
            {
                LocationMode = NEWEST_TABLE.LocationMode.SecondaryOnly
            };

            tableClientNewest.DefaultRequestOptions = tableRequestOptionsNewest;

            var tableNewset             = tableClientNewest.GetTableReference("foo"); // don't need table to exist to show the issue
            var retrieveOperationNewset = NEWEST_TABLE.TableOperation.Retrieve(string.Empty, string.Empty, new List <string>()
            {
                "bar"
            });

            /* throws Microsoft.Azure.Cosmos.Table.StorageException
             * Exception thrown while initializing request: This operation can only be executed against the primary storage location
             */
            var tableResultNewset = tableNewset.Execute(retrieveOperationNewset);

            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
예제 #3
0
 /// <summary>
 /// Get the Table service properties
 /// </summary>
 /// <param name="account">Cloud storage account</param>
 /// <param name="options">Request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>The service properties of the specified service type</returns>
 public XTable.ServiceProperties GetStorageTableServiceProperties(XTable.TableRequestOptions options, XTable.OperationContext operationContext)
 {
     XTable.CloudStorageAccount account = StorageContext.TableStorageAccount;
     try
     {
         return(account.CreateCloudTableClient().GetServicePropertiesAsync(options, operationContext).Result);
     }
     catch (AggregateException e) when(e.InnerException is XTable.StorageException)
     {
         throw e.InnerException;
     }
 }
        /// <summary>
        /// Get a request options
        /// </summary>
        /// <param name="type">Service type</param>
        /// <returns>Request options</returns>
        public XTable.TableRequestOptions GetTableRequestOptions()
        {
            XTable.TableRequestOptions options = new XTable.TableRequestOptions();

            if (ServerTimeoutPerRequest.HasValue)
            {
                options.ServerTimeout = ConvertToTimeSpan(ServerTimeoutPerRequest.Value);
            }

            if (ClientTimeoutPerRequest.HasValue)
            {
                options.MaximumExecutionTime = ConvertToTimeSpan(ClientTimeoutPerRequest.Value);
            }

            return(options);
        }
예제 #5
0
 /// <summary>
 /// Set Table service properties
 /// </summary>
 /// <param name="account">Cloud storage account</param>
 /// <param name="properties">Service properties</param>
 /// <param name="options">Request options</param>
 /// <param name="operationContext">Operation context</param>
 public void SetStorageTableServiceProperties(XTable.ServiceProperties properties, XTable.TableRequestOptions options, XTable.OperationContext operationContext)
 {
     XTable.CloudStorageAccount account = StorageContext.TableStorageAccount;
     try
     {
         Task.Run(() => account.CreateCloudTableClient().SetServicePropertiesAsync(properties, options, operationContext)).Wait();
     }
     catch (AggregateException e) when(e.InnerException is XTable.StorageException)
     {
         throw e.InnerException;
     }
 }
 public void SetStorageTableServiceProperties(Azure.Cosmos.Table.ServiceProperties properties, XTable.TableRequestOptions options, XTable.OperationContext operationContext)
 {
     throw new NotImplementedException();
 }