Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountSasBuilder"/>
 /// class to create a Blob Container Service Sas.
 /// </summary>
 /// <param name="permissions">
 /// The time at which the shared access signature becomes invalid.
 /// This field must be omitted if it has been specified in an
 /// associated stored access policy.
 /// </param>
 /// <param name="expiresOn">
 /// The time at which the shared access signature becomes invalid.
 /// This field must be omitted if it has been specified in an
 /// associated stored access policy.
 /// </param>
 /// <param name="services">
 /// Specifies the services accessible from an account level shared access
 /// signature.
 /// </param>
 /// <param name="resourceTypes">
 /// Specifies the resource types accessible from an account level shared
 /// access signature.
 /// </param>
 public AccountSasBuilder(
     AccountSasPermissions permissions,
     DateTimeOffset expiresOn,
     AccountSasServices services,
     AccountSasResourceTypes resourceTypes)
 {
     ExpiresOn = expiresOn;
     SetPermissions(permissions);
     Services      = services;
     ResourceTypes = resourceTypes;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Parse a string representing which resource types are accessible
        /// from a shared access signature.
        /// </summary>
        /// <param name="s">
        /// A string representing which resource types are accessible.
        /// </param>
        /// <returns>
        /// An <see cref="AccountSasResourceTypes"/> instance.
        /// </returns>
        /// <remarks>
        /// The order here matches the order used by the portal when generating SAS signatures.
        /// </remarks>
        internal static AccountSasResourceTypes ParseResourceTypes(string s)
        {
            AccountSasResourceTypes types = default;

            foreach (var ch in s)
            {
                types |= ch switch
                {
                    Constants.Sas.AccountResources.Service => AccountSasResourceTypes.Service,
                    Constants.Sas.AccountResources.Container => AccountSasResourceTypes.Container,
                    Constants.Sas.AccountResources.Object => AccountSasResourceTypes.Object,
                    _ => throw Errors.InvalidResourceType(ch),
                };
            }
            return(types);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a string representing which resource types are allowed
        /// for <see cref="AccountSasBuilder.ResourceTypes"/>.
        /// </summary>
        /// <returns>
        /// A string representing which resource types are allowed.
        /// </returns>
        /// <remarks>
        /// The order here matches the order used by the portal when generating SAS signatures.
        /// </remarks>
        internal static string ToPermissionsString(this AccountSasResourceTypes resourceTypes)
        {
            var sb = new StringBuilder();

            if ((resourceTypes & AccountSasResourceTypes.Service) == AccountSasResourceTypes.Service)
            {
                sb.Append(Constants.Sas.AccountResources.Service);
            }
            if ((resourceTypes & AccountSasResourceTypes.Container) == AccountSasResourceTypes.Container)
            {
                sb.Append(Constants.Sas.AccountResources.Container);
            }
            if ((resourceTypes & AccountSasResourceTypes.Object) == AccountSasResourceTypes.Object)
            {
                sb.Append(Constants.Sas.AccountResources.Object);
            }
            return(sb.ToString());
        }