コード例 #1
0
        /// <summary>
        /// Parse Uri for SAS (Shared access signature) information.
        /// </summary>
        /// <param name="address">The complete Uri.</param>
        /// <param name="parsedCredentials">The credentials to use.</param>
        /// <param name="parsedSnapshot">The parsed snapshot.</param>
        /// <returns>The blob URI without credentials or snapshot info</returns>
        /// <exception cref="System.ArgumentException">address</exception>
        /// <remarks>
        /// Validate that no other query parameters are passed in.
        /// Any SAS information will be recorded as corresponding credentials instance.
        /// If credentials is passed in and it does not match the SAS information found, an
        /// exception will be thrown.
        /// Otherwise a new client is created based on SAS information or as anonymous credentials.
        /// </remarks>
        private static Uri ParseBlobQueryAndVerify(Uri address, out StorageCredentials parsedCredentials, out DateTimeOffset?parsedSnapshot)
        {
            parsedCredentials = null;
            parsedSnapshot    = null;
            if (address == null)
            {
                return(null);
            }

            if (!address.IsAbsoluteUri)
            {
                string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.RelativeAddressNotPermitted, address.ToString());
                throw new ArgumentException(errorMessage, "address");
            }

            IDictionary <string, string> queryParameters = HttpWebUtility.ParseQueryString(address.Query);

            string snapshot;

            if (queryParameters.TryGetValue(Constants.QueryConstants.Snapshot, out snapshot))
            {
                if (!string.IsNullOrEmpty(snapshot))
                {
                    parsedSnapshot = ParseSnapshotTime(snapshot);
                }
            }

            parsedCredentials = SharedAccessSignatureHelper.ParseQuery(queryParameters);

            // SAS credentials were passed in the Uri if parsedCredentials is non null.
            if (parsedCredentials != null)
            {
                string signedResource;
                queryParameters.TryGetValue(Constants.QueryConstants.SignedResource, out signedResource);

                if (string.IsNullOrEmpty(signedResource))
                {
                    string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.MissingMandatoryParametersForSAS);
                    throw new ArgumentException(errorMessage);
                }
            }

            return(new Uri(address.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped)));
        }
コード例 #2
0
        /// <summary>
        /// Parse Uri for SAS (Shared access signature) information.
        /// </summary>
        /// <param name="address">The complete Uri.</param>
        /// <param name="parsedCredentials">The credentials to use.</param>
        /// <remarks>
        /// Validate that no other query parameters are passed in.
        /// Any SAS information will be recorded as corresponding credentials instance.
        /// If credentials is passed in and it does not match the SAS information found, an
        /// exception will be thrown.
        /// Otherwise a new client is created based on SAS information or as anonymous credentials.
        /// </remarks>
        private static Uri ParseQueueTableQueryAndVerify(Uri address, out StorageCredentials parsedCredentials)
        {
            parsedCredentials = null;
            if (address == null)
            {
                return(null);
            }

            if (!address.IsAbsoluteUri)
            {
                string errorMessage = string.Format(CultureInfo.InvariantCulture, SR.RelativeAddressNotPermitted, address.ToString());
                throw new ArgumentException(errorMessage, "address");
            }

            IDictionary <string, string> queryParameters = HttpWebUtility.ParseQueryString(address.Query);

            parsedCredentials = SharedAccessSignatureHelper.ParseQuery(queryParameters);
            return(new Uri(address.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped)));
        }
コード例 #3
0
        public static string GetCanonicalizedResourceString(Uri uri, string accountName, bool isSharedKeyLiteOrTableService = false)
        {
            StringBuilder canonicalizedResource = new StringBuilder(ExpectedResourceStringLength);

            canonicalizedResource.Append('/');
            canonicalizedResource.Append(accountName);
            canonicalizedResource.Append(GetAbsolutePathWithoutSecondarySuffix(uri, accountName));

            IDictionary <string, string> queryParameters = HttpWebUtility.ParseQueryString(uri.Query);

            if (!isSharedKeyLiteOrTableService)
            {
                List <string> queryParameterNames = new List <string>(queryParameters.Keys);
                queryParameterNames.Sort(StringComparer.OrdinalIgnoreCase);

                foreach (string queryParameterName in queryParameterNames)
                {
                    canonicalizedResource.Append('\n');
                    canonicalizedResource.Append(queryParameterName.ToLowerInvariant());
                    canonicalizedResource.Append(':');
                    canonicalizedResource.Append(queryParameters[queryParameterName]);
                }
            }
            else
            {
                // Add only the comp parameter
                string compQueryParameterValue;
                if (queryParameters.TryGetValue("comp", out compQueryParameterValue))
                {
                    canonicalizedResource.Append("?comp=");
                    canonicalizedResource.Append(compQueryParameterValue);
                }
            }

            return(canonicalizedResource.ToString());
        }