| | 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.Data.Tables.Sas; |
| | 7 | |
|
| | 8 | | namespace Azure.Data.Tables.Sas |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Specifies the resource types accessible from an account level shared |
| | 12 | | /// access signature. |
| | 13 | | /// </summary> |
| | 14 | | [Flags] |
| | 15 | | public enum TableAccountSasResourceTypes |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// Indicates whether service-level APIs are accessible |
| | 19 | | /// from this shared access signature (e.g., Get/Set Service |
| | 20 | | /// Properties, Get Service Stats, List Containers/Queues/Tables/ |
| | 21 | | /// Shares). |
| | 22 | | /// </summary> |
| | 23 | | Service = 1, |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Indicates whether blob container-level APIs are accessible |
| | 27 | | /// from this shared access signature (e.g., Create/Delete Container, |
| | 28 | | /// Create/Delete Queue, Create/Delete Table, Create/Delete Share, List |
| | 29 | | /// Blobs/Files and Directories). |
| | 30 | | /// </summary> |
| | 31 | | Container = 2, |
| | 32 | |
|
| | 33 | | #pragma warning disable CA1720 // Identifier contains type name |
| | 34 | | /// <summary> |
| | 35 | | /// Indicates whether object-level APIs for blobs, queue |
| | 36 | | /// messages, and files are accessible from this shared access |
| | 37 | | /// signature (e.g. Put Blob, Query Entity, Get Messages, Create File, |
| | 38 | | /// etc.). |
| | 39 | | /// </summary> |
| | 40 | | Object = 4, |
| | 41 | | #pragma warning restore CA1720 // Identifier contains type name |
| | 42 | |
|
| | 43 | | /// <summary> |
| | 44 | | /// Indicates all service-level APIs are accessible from this shared |
| | 45 | | /// access signature. |
| | 46 | | /// </summary> |
| | 47 | | All = ~0 |
| | 48 | | } |
| | 49 | | } |
| | 50 | |
|
| | 51 | | namespace Azure.Data.Tables |
| | 52 | | { |
| | 53 | | internal static partial class TableExtensions |
| | 54 | | { |
| | 55 | | /// <summary> |
| | 56 | | /// Creates a string representing which resource types are allowed |
| | 57 | | /// for <see cref="TableAccountSasBuilder.ResourceTypes"/>. |
| | 58 | | /// </summary> |
| | 59 | | /// <returns> |
| | 60 | | /// A string representing which resource types are allowed. |
| | 61 | | /// </returns> |
| | 62 | | /// <remarks> |
| | 63 | | /// The order here matches the order used by the portal when generating SAS signatures. |
| | 64 | | /// </remarks> |
| | 65 | | internal static string ToPermissionsString(this TableAccountSasResourceTypes resourceTypes) |
| | 66 | | { |
| 64 | 67 | | var sb = new StringBuilder(); |
| 64 | 68 | | if ((resourceTypes & TableAccountSasResourceTypes.Service) == TableAccountSasResourceTypes.Service) |
| | 69 | | { |
| 64 | 70 | | sb.Append(TableConstants.Sas.TableAccountResources.Service); |
| | 71 | | } |
| 64 | 72 | | if ((resourceTypes & TableAccountSasResourceTypes.Container) == TableAccountSasResourceTypes.Container) |
| | 73 | | { |
| 48 | 74 | | sb.Append(TableConstants.Sas.TableAccountResources.Container); |
| | 75 | | } |
| 64 | 76 | | if ((resourceTypes & TableAccountSasResourceTypes.Object) == TableAccountSasResourceTypes.Object) |
| | 77 | | { |
| 32 | 78 | | sb.Append(TableConstants.Sas.TableAccountResources.Object); |
| | 79 | | } |
| 64 | 80 | | return sb.ToString(); |
| | 81 | | } |
| | 82 | | } |
| | 83 | | } |