| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Text; |
| | 6 | | using Azure.Storage.Sas; |
| | 7 | |
|
| | 8 | | namespace Azure.Storage.Sas |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// <see cref="QueueAccountSasPermissions"/> contains the list of |
| | 12 | | /// permissions that can be set for a file's access policy. Use |
| | 13 | | /// <see cref="QueueSasBuilder.SetPermissions(QueueAccountSasPermissions)"/> |
| | 14 | | /// to set the permissions on the <see cref="QueueSasBuilder"/>. |
| | 15 | | /// </summary> |
| | 16 | | [Flags] |
| | 17 | | public enum QueueAccountSasPermissions |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Indicates that Read is permitted. |
| | 21 | | /// </summary> |
| | 22 | | Read = 1, |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Indicates that Write is permitted. |
| | 26 | | /// </summary> |
| | 27 | | Write = 2, |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Indicates that Delete is permitted. |
| | 31 | | /// </summary> |
| | 32 | | Delete = 4, |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Indicates that List is permitted. |
| | 36 | | /// </summary> |
| | 37 | | List = 8, |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// Indicates that Add is permitted. |
| | 41 | | /// </summary> |
| | 42 | | Add = 16, |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Indicates that Update is permitted. |
| | 46 | | /// </summary> |
| | 47 | | Update = 32, |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Indicates that Delete is permitted. |
| | 51 | | /// </summary> |
| | 52 | | Process = 64, |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Indicates that all permissions are set. |
| | 56 | | /// </summary> |
| | 57 | | All = ~0 |
| | 58 | | } |
| | 59 | | } |
| | 60 | |
|
| | 61 | | namespace Azure.Storage.Queues |
| | 62 | | { |
| | 63 | | /// <summary> |
| | 64 | | /// Queue enum extensions. |
| | 65 | | /// </summary> |
| | 66 | | internal static partial class QueueExtensions |
| | 67 | | { |
| | 68 | |
|
| | 69 | | /// <summary> |
| | 70 | | /// Create a permissions string to provide |
| | 71 | | /// <see cref="QueueSasBuilder.Permissions"/>. |
| | 72 | | /// </summary> |
| | 73 | | /// <returns>A permissions string.</returns> |
| | 74 | | internal static string ToPermissionsString(this QueueAccountSasPermissions permissions) |
| | 75 | | { |
| 4 | 76 | | var sb = new StringBuilder(); |
| 4 | 77 | | if ((permissions & QueueAccountSasPermissions.Read) == QueueAccountSasPermissions.Read) |
| | 78 | | { |
| 4 | 79 | | sb.Append(Constants.Sas.Permissions.Read); |
| | 80 | | } |
| 4 | 81 | | if ((permissions & QueueAccountSasPermissions.Write) == QueueAccountSasPermissions.Write) |
| | 82 | | { |
| 0 | 83 | | sb.Append(Constants.Sas.Permissions.Write); |
| | 84 | | } |
| 4 | 85 | | if ((permissions & QueueAccountSasPermissions.Delete) == QueueAccountSasPermissions.Delete) |
| | 86 | | { |
| 0 | 87 | | sb.Append(Constants.Sas.Permissions.Delete); |
| | 88 | | } |
| 4 | 89 | | if ((permissions & QueueAccountSasPermissions.List) == QueueAccountSasPermissions.List) |
| | 90 | | { |
| 0 | 91 | | sb.Append(Constants.Sas.Permissions.List); |
| | 92 | | } |
| 4 | 93 | | if ((permissions & QueueAccountSasPermissions.Add) == QueueAccountSasPermissions.Add) |
| | 94 | | { |
| 4 | 95 | | sb.Append(Constants.Sas.Permissions.Add); |
| | 96 | | } |
| 4 | 97 | | if ((permissions & QueueAccountSasPermissions.Update) == QueueAccountSasPermissions.Update) |
| | 98 | | { |
| 4 | 99 | | sb.Append(Constants.Sas.Permissions.Update); |
| | 100 | | } |
| 4 | 101 | | if ((permissions & QueueAccountSasPermissions.Process) == QueueAccountSasPermissions.Process) |
| | 102 | | { |
| 4 | 103 | | sb.Append(Constants.Sas.Permissions.Process); |
| | 104 | | } |
| 4 | 105 | | return sb.ToString(); |
| | 106 | | } |
| | 107 | | } |
| | 108 | | } |