| | 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="AccountSasPermissions"/> contains the list of |
| | 12 | | /// permissions that can be set for a blob's access policy. Use |
| | 13 | | /// <see cref="AccountSasBuilder.SetPermissions(AccountSasPermissions)"/> |
| | 14 | | /// to set the permissions on the <see cref="AccountSasBuilder"/>. |
| | 15 | | /// </summary> |
| | 16 | | [Flags] |
| | 17 | | public enum AccountSasPermissions |
| | 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 Create is permitted. |
| | 46 | | /// </summary> |
| | 47 | | Create = 32, |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Indicates that Update is permitted. |
| | 51 | | /// </summary> |
| | 52 | | Update = 64, |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Indicates that Delete is permitted. |
| | 56 | | /// </summary> |
| | 57 | | Process = 128, |
| | 58 | |
|
| | 59 | | /// <summary> |
| | 60 | | /// Indicates that reading and writing Tags is permitted. |
| | 61 | | /// Blob service only. |
| | 62 | | /// </summary> |
| | 63 | | Tag = 256, |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// Indicates that filtering by tag is permitted. |
| | 67 | | /// Blob service only. |
| | 68 | | /// </summary> |
| | 69 | | Filter = 512, |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// Indicates that deleting a BlobVersion is permitted. |
| | 73 | | /// Blob Service only. |
| | 74 | | /// </summary> |
| | 75 | | DeleteVersion = 1024, |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Indicates that all permissions are set. |
| | 79 | | /// </summary> |
| | 80 | | All = ~0 |
| | 81 | | } |
| | 82 | | } |
| | 83 | |
|
| | 84 | | namespace Azure.Storage |
| | 85 | | { |
| | 86 | | /// <summary> |
| | 87 | | /// Blob enum extensions. |
| | 88 | | /// </summary> |
| | 89 | | internal static partial class AccountExtensions |
| | 90 | | { |
| | 91 | | /// <summary> |
| | 92 | | /// Create a permissions string to provide |
| | 93 | | /// <see cref="AccountSasBuilder.Permissions"/>. |
| | 94 | | /// </summary> |
| | 95 | | /// <returns>A permissions string.</returns> |
| | 96 | | internal static string ToPermissionsString(this AccountSasPermissions permissions) |
| | 97 | | { |
| 104 | 98 | | var sb = new StringBuilder(); |
| 104 | 99 | | if ((permissions & AccountSasPermissions.Read) == AccountSasPermissions.Read) |
| | 100 | | { |
| 88 | 101 | | sb.Append(Constants.Sas.Permissions.Read); |
| | 102 | | } |
| 104 | 103 | | if ((permissions & AccountSasPermissions.Write) == AccountSasPermissions.Write) |
| | 104 | | { |
| 82 | 105 | | sb.Append(Constants.Sas.Permissions.Write); |
| | 106 | | } |
| 104 | 107 | | if ((permissions & AccountSasPermissions.Delete) == AccountSasPermissions.Delete) |
| | 108 | | { |
| 86 | 109 | | sb.Append(Constants.Sas.Permissions.Delete); |
| | 110 | | } |
| 104 | 111 | | if ((permissions & AccountSasPermissions.DeleteVersion) == AccountSasPermissions.DeleteVersion) |
| | 112 | | { |
| 42 | 113 | | sb.Append(Constants.Sas.Permissions.DeleteBlobVersion); |
| | 114 | | } |
| 104 | 115 | | if ((permissions & AccountSasPermissions.List) == AccountSasPermissions.List) |
| | 116 | | { |
| 78 | 117 | | sb.Append(Constants.Sas.Permissions.List); |
| | 118 | | } |
| 104 | 119 | | if ((permissions & AccountSasPermissions.Add) == AccountSasPermissions.Add) |
| | 120 | | { |
| 78 | 121 | | sb.Append(Constants.Sas.Permissions.Add); |
| | 122 | | } |
| 104 | 123 | | if ((permissions & AccountSasPermissions.Create) == AccountSasPermissions.Create) |
| | 124 | | { |
| 78 | 125 | | sb.Append(Constants.Sas.Permissions.Create); |
| | 126 | | } |
| 104 | 127 | | if ((permissions & AccountSasPermissions.Update) == AccountSasPermissions.Update) |
| | 128 | | { |
| 50 | 129 | | sb.Append(Constants.Sas.Permissions.Update); |
| | 130 | | } |
| 104 | 131 | | if ((permissions & AccountSasPermissions.Process) == AccountSasPermissions.Process) |
| | 132 | | { |
| 50 | 133 | | sb.Append(Constants.Sas.Permissions.Process); |
| | 134 | | } |
| 104 | 135 | | if ((permissions & AccountSasPermissions.Tag) == AccountSasPermissions.Tag) |
| | 136 | | { |
| 46 | 137 | | sb.Append(Constants.Sas.Permissions.Tag); |
| | 138 | | } |
| 104 | 139 | | if ((permissions & AccountSasPermissions.Filter) == AccountSasPermissions.Filter) |
| | 140 | | { |
| 46 | 141 | | sb.Append(Constants.Sas.Permissions.FilterByTags); |
| | 142 | | } |
| 104 | 143 | | return sb.ToString(); |
| | 144 | | } |
| | 145 | | } |
| | 146 | | } |