/// <summary>
 /// Gets a <see cref="TableSasBuilder"/> instance scoped to the current account.
 /// </summary>
 /// <param name="permissions"><see cref="TableAccountSasPermissions"/> containing the allowed permissions.</param>
 /// <param name="resourceTypes"><see cref="TableAccountSasResourceTypes"/> containing the accessible resource types.</param>
 /// <param name="expiresOn">The time at which the shared access signature becomes invalid.</param>
 /// <returns>An instance of <see cref="TableAccountSasBuilder"/>.</returns>
 public virtual TableAccountSasBuilder GetSasBuilder(TableAccountSasPermissions permissions, TableAccountSasResourceTypes resourceTypes, DateTimeOffset expiresOn)
 {
     return(new TableAccountSasBuilder(permissions, resourceTypes, expiresOn)
     {
         Version = _version
     });
 }
Example #2
0
        /// <summary>
        /// Create a permissions string to provide
        /// <see cref="TableAccountSasBuilder.Permissions"/>.
        /// </summary>
        /// <returns>A permissions string.</returns>
        internal static string ToPermissionsString(this TableAccountSasPermissions permissions)
        {
            var sb = new StringBuilder();

            if ((permissions & TableAccountSasPermissions.Read) == TableAccountSasPermissions.Read)
            {
                sb.Append(TableConstants.Sas.Permissions.Read);
            }
            if ((permissions & TableAccountSasPermissions.Write) == TableAccountSasPermissions.Write)
            {
                sb.Append(TableConstants.Sas.Permissions.Write);
            }
            if ((permissions & TableAccountSasPermissions.Delete) == TableAccountSasPermissions.Delete)
            {
                sb.Append(TableConstants.Sas.Permissions.Delete);
            }
            if ((permissions & TableAccountSasPermissions.List) == TableAccountSasPermissions.List)
            {
                sb.Append(TableConstants.Sas.Permissions.List);
            }
            if ((permissions & TableAccountSasPermissions.Add) == TableAccountSasPermissions.Add)
            {
                sb.Append(TableConstants.Sas.Permissions.Add);
            }
            if ((permissions & TableAccountSasPermissions.Update) == TableAccountSasPermissions.Update)
            {
                sb.Append(TableConstants.Sas.Permissions.Update);
            }
            return(sb.ToString());
        }
        public void SetPermissions(string permissionsString, TableAccountSasPermissions permissions, TableAccountSasResourceTypes resourceTypes)
        {
            var TableAccountSasBuilder = new TableAccountSasBuilder(permissionsString, resourceTypes, DateTimeOffset.Now);

            Assert.That(TableAccountSasBuilder.Permissions, Is.EqualTo(permissionsString));

            TableAccountSasBuilder.SetPermissions(permissions);

            Assert.That(TableAccountSasBuilder.Permissions, Is.EqualTo(permissionsString));
        }
        public void GenerateSasUri(TableServiceClient client, TableSharedKeyCredential cred)
        {
            TableAccountSasPermissions   permissions   = TableAccountSasPermissions.Add;
            TableAccountSasResourceTypes resourceTypes = TableAccountSasResourceTypes.Container;
            var expires     = DateTime.Now.AddDays(1);
            var expectedSas = new TableAccountSasBuilder(permissions, resourceTypes, expires).Sign(cred);

            var actualSas = client.GenerateSasUri(permissions, resourceTypes, expires);

            Assert.AreEqual("?" + expectedSas, actualSas.Query);
        }
 /// <summary>
 /// Initializes an instance of a <see cref="TableAccountSasBuilder"/>.
 /// </summary>
 /// <param name="permissions">The permissions associated with the shared access signature.</param>
 /// <param name="resourceTypes"><see cref="TableAccountSasResourceTypes"/> containing the accessible resource types.</param>
 /// <param name="expiresOn">The time at which the shared access signature becomes invalid.</param>
 public TableAccountSasBuilder(TableAccountSasPermissions permissions, TableAccountSasResourceTypes resourceTypes, DateTimeOffset expiresOn)
 {
     ExpiresOn = expiresOn;
     SetPermissions(permissions);
     ResourceTypes = resourceTypes;
 }
 /// <summary>
 /// Sets the permissions for a table SAS.
 /// </summary>
 /// <param name="permissions">
 /// <see cref="TableAccountSasPermissions"/> containing the allowed permissions.
 /// </param>
 public void SetPermissions(TableAccountSasPermissions permissions)
 {
     Permissions = permissions.ToPermissionsString();
 }