示例#1
0
 /// <summary>
 /// Returns a shared access signature for the table.
 /// </summary>
 /// <param name="policy">A <see cref="SharedAccessTablePolicy"/> object specifying the access policy for the shared access signature.</param>
 /// <param name="accessPolicyIdentifier">A string identifying a stored access policy.</param>
 /// <param name="startPartitionKey">A string specifying the start partition key, or <c>null</c>.</param>
 /// <param name="startRowKey">A string specifying the start row key, or <c>null</c>.</param>
 /// <param name="endPartitionKey">A string specifying the end partition key, or <c>null</c>.</param>
 /// <param name="endRowKey">A string specifying the end row key, or <c>null</c>.</param>
 /// <returns>A shared access signature, as a URI query string.</returns>
 /// <remarks>The query string returned includes the leading question mark.</remarks>
 /// <exception cref="InvalidOperationException">Thrown if the current credentials don't support creating a shared access signature.</exception>
 public string GetSharedAccessSignature(
     SharedAccessTablePolicy policy,
     string accessPolicyIdentifier,
     string startPartitionKey,
     string startRowKey,
     string endPartitionKey,
     string endRowKey)
 {
     return(this.GetSharedAccessSignature(policy, accessPolicyIdentifier, startPartitionKey, startRowKey, endPartitionKey, endRowKey, null, null));
 }
示例#2
0
 /// <summary>
 /// Returns a shared access signature for the table.
 /// </summary>
 /// <param name="policy">A <see cref="SharedAccessTablePolicy"/> object specifying the access policy for the shared access signature.</param>
 /// <param name="accessPolicyIdentifier">A string identifying a stored access policy.</param>
 /// <returns>A shared access signature, as a URI query string.</returns>
 /// <remarks>The query string returned includes the leading question mark.</remarks>
 /// <exception cref="InvalidOperationException">Thrown if the current credentials don't support creating a shared access signature.</exception>
 public string GetSharedAccessSignature(SharedAccessTablePolicy policy, string accessPolicyIdentifier)
 {
     return(this.GetSharedAccessSignature(
                policy,
                accessPolicyIdentifier,
                null /* startPartitionKey */,
                null /* startRowKey */,
                null /* endPartitionKey */,
                null /* endRowKey */));
 }
示例#3
0
        /// <summary>
        /// Returns a shared access signature for the table.
        /// </summary>
        /// <param name="policy">A <see cref="SharedAccessTablePolicy"/> object specifying the access policy for the shared access signature.</param>
        /// <param name="accessPolicyIdentifier">A string identifying a stored access policy.</param>
        /// <param name="startPartitionKey">A string specifying the start partition key, or <c>null</c>.</param>
        /// <param name="startRowKey">A string specifying the start row key, or <c>null</c>.</param>
        /// <param name="endPartitionKey">A string specifying the end partition key, or <c>null</c>.</param>
        /// <param name="endRowKey">A string specifying the end row key, or <c>null</c>.</param>
        /// <param name="protocols">The allowed protocols (https only, or http and https). Null if you don't want to restrict protocol.</param>
        /// <param name="ipAddressOrRange">The allowed IP address or IP address range. Null if you don't want to restrict based on IP address.</param>
        /// <returns>A shared access signature, as a URI query string.</returns>
        /// <remarks>The query string returned includes the leading question mark.</remarks>
        /// <exception cref="InvalidOperationException">Thrown if the current credentials don't support creating a shared access signature.</exception>
        public string GetSharedAccessSignature(
            SharedAccessTablePolicy policy,
            string accessPolicyIdentifier,
            string startPartitionKey,
            string startRowKey,
            string endPartitionKey,
            string endRowKey,
            SharedAccessProtocol?protocols,
            IPAddressOrRange ipAddressOrRange)
        {
            if (!this.ServiceClient.Credentials.IsSharedKey)
            {
                string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.CannotCreateSASWithoutAccountKey);
                throw new InvalidOperationException(errorMessage);
            }

            string            resourceName = this.GetCanonicalName();
            StorageAccountKey accountKey   = this.ServiceClient.Credentials.Key;

            string signature = SharedAccessSignatureHelper.GetHash(
                policy,
                accessPolicyIdentifier,
                startPartitionKey,
                startRowKey,
                endPartitionKey,
                endRowKey,
                resourceName,
                Constants.HeaderConstants.TargetStorageVersion,
                protocols,
                ipAddressOrRange,
                accountKey.KeyValue);

            UriQueryBuilder builder = SharedAccessSignatureHelper.GetSignature(
                policy,
                this.Name,
                accessPolicyIdentifier,
                startPartitionKey,
                startRowKey,
                endPartitionKey,
                endRowKey,
                signature,
                accountKey.KeyName,
                Constants.HeaderConstants.TargetStorageVersion,
                protocols,
                ipAddressOrRange);

            return(builder.ToString());
        }