/// <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>
        internal static Uri ParseBlobQueryAndVerify(Uri address, out StorageCredentials parsedCredentials, out DateTimeOffset?parsedSnapshot)
        {
            CommonUtils.AssertNotNull("address", address);
            if (!address.IsAbsoluteUri)
            {
                string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.RelativeAddressNotPermitted, address.ToString());
                throw new ArgumentException(errorMessage, "address");
            }

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

            parsedSnapshot = null;
            string snapshot;

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

            parsedCredentials = SharedAccessSignatureHelper.ParseQuery(queryParameters);
            return(new Uri(address.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped)));
        }
Esempio n. 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>
        /// <returns>The file URI without credentials 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 ParseFileQueryAndVerify(Uri address, out StorageCredentials parsedCredentials)
        {
            parsedCredentials = 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);

            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)));
        }
Esempio n. 3
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>
        internal static Uri ParseQueueTableQueryAndVerify(Uri address, out StorageCredentials parsedCredentials)
        {
            CommonUtility.AssertNotNull("address", address);
            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);

            parsedCredentials = SharedAccessSignatureHelper.ParseQuery(queryParameters, false);
            return(new Uri(address.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped)));
        }
        /// <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="parsedShareSnapshot">The parsed share snapshot.</param>
        /// <returns>The file 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 ParseFileQueryAndVerify(Uri address, out StorageCredentials parsedCredentials, out DateTimeOffset?parsedShareSnapshot)
        {
            parsedCredentials   = null;
            parsedShareSnapshot = 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);

            parsedCredentials = SharedAccessSignatureHelper.ParseQuery(queryParameters);

            return(new Uri(address.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped)));
        }